proper checkbox disable; basic themeing

pull/1/head
Clyne 3 years ago
parent 79032a73d5
commit 4306970fd3

@ -17,6 +17,7 @@
#include "stmdsp.hpp" #include "stmdsp.hpp"
#include "imgui.h" #include "imgui.h"
#include "imgui_internal.h"
#include "ImGuiFileDialog.h" #include "ImGuiFileDialog.h"
#include "wav.hpp" #include "wav.hpp"
@ -106,7 +107,7 @@ static void drawSamplesTask(std::shared_ptr<stmdsp::device> device)
std::vector<stmdsp::dacsample_t> chunk; std::vector<stmdsp::dacsample_t> chunk;
if (lockDevice.try_lock_until(next)) { if (lockDevice.try_lock_until(next)) {
chunk = m_device->continuous_read(); chunk = m_device->continuous_read();
int tries = -1; int tries = -1;
while (chunk.empty() && m_device->is_running()) { while (chunk.empty() && m_device->is_running()) {
@ -115,16 +116,16 @@ static void drawSamplesTask(std::shared_ptr<stmdsp::device> device)
std::this_thread::sleep_for(std::chrono::microseconds(20)); std::this_thread::sleep_for(std::chrono::microseconds(20));
chunk = m_device->continuous_read(); chunk = m_device->continuous_read();
} }
lockDevice.unlock(); lockDevice.unlock();
} else { } else {
// Cooldown. // Cooldown.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
} }
if (drawSamplesInput && popupRequestDraw) { if (drawSamplesInput && popupRequestDraw) {
std::vector<stmdsp::dacsample_t> chunk2; std::vector<stmdsp::dacsample_t> chunk2;
if (lockDevice.try_lock_for(std::chrono::milliseconds(1))) { if (lockDevice.try_lock_for(std::chrono::milliseconds(1))) {
chunk2 = m_device->continuous_read_input(); chunk2 = m_device->continuous_read_input();
int tries = -1; int tries = -1;
while (chunk2.empty() && m_device->is_running()) { while (chunk2.empty() && m_device->is_running()) {
@ -133,28 +134,28 @@ static void drawSamplesTask(std::shared_ptr<stmdsp::device> device)
std::this_thread::sleep_for(std::chrono::microseconds(20)); std::this_thread::sleep_for(std::chrono::microseconds(20));
chunk2 = m_device->continuous_read_input(); chunk2 = m_device->continuous_read_input();
} }
lockDevice.unlock(); lockDevice.unlock();
} }
lockDraw.lock(); lockDraw.lock();
auto i = chunk2.cbegin(); auto i = chunk2.cbegin();
for (const auto& s : chunk) { for (const auto& s : chunk) {
drawSamplesQueue.push_back(s); drawSamplesQueue.push_back(s);
drawSamplesInputQueue.push_back(*i++); drawSamplesInputQueue.push_back(*i++);
} }
lockDraw.unlock(); lockDraw.unlock();
} else if (!doLogger) { } else if (!doLogger) {
lockDraw.lock(); lockDraw.lock();
for (const auto& s : chunk) for (const auto& s : chunk)
drawSamplesQueue.push_back(s); drawSamplesQueue.push_back(s);
lockDraw.unlock(); lockDraw.unlock();
} else { } else {
lockDraw.lock(); lockDraw.lock();
for (const auto& s : chunk) { for (const auto& s : chunk) {
drawSamplesQueue.push_back(s); drawSamplesQueue.push_back(s);
logSamplesFile << s << '\n'; logSamplesFile << s << '\n';
} }
lockDraw.unlock(); lockDraw.unlock();
} }
std::this_thread::sleep_until(next); std::this_thread::sleep_until(next);
@ -193,7 +194,7 @@ static void feedSigGenTask(std::shared_ptr<stmdsp::device> device)
if (lockDevice.try_lock_until(next)) { if (lockDevice.try_lock_until(next)) {
m_device->siggen_upload(wavBuf.data(), wavBuf.size()); m_device->siggen_upload(wavBuf.data(), wavBuf.size());
lockDevice.unlock(); lockDevice.unlock();
std::this_thread::sleep_until(next); std::this_thread::sleep_until(next);
} }
} }
@ -485,29 +486,24 @@ void deviceRenderMenu()
deviceAlgorithmUpload(); deviceAlgorithmUpload();
if (ImGui::MenuItem("Unload algorithm", nullptr, false, isConnected && !isRunning)) if (ImGui::MenuItem("Unload algorithm", nullptr, false, isConnected && !isRunning))
deviceAlgorithmUnload(); deviceAlgorithmUnload();
ImGui::Separator(); ImGui::Separator();
if (ImGui::Checkbox("Measure Code Time", &measureCodeTime)) { if (!isConnected || isRunning)
if (!isConnected) ImGui::PushDisabled();
measureCodeTime = false; ImGui::Checkbox("Measure Code Time", &measureCodeTime);
}
if (ImGui::Checkbox("Draw samples", &drawSamples)) { if (ImGui::Checkbox("Draw samples", &drawSamples)) {
if (isConnected) { if (drawSamples)
if (drawSamples) popupRequestDraw = true;
popupRequestDraw = true;
} else {
drawSamples = false;
}
} }
if (ImGui::Checkbox("Log results...", &logResults)) { if (ImGui::Checkbox("Log results...", &logResults)) {
if (isConnected) { if (logResults)
if (logResults) popupRequestLog = true;
popupRequestLog = true; else if (logSamplesFile.is_open())
else if (logSamplesFile.is_open()) logSamplesFile.close();
logSamplesFile.close();
} else {
logResults = false;
}
} }
if (!isConnected || isRunning)
ImGui::PopDisabled();
if (ImGui::MenuItem("Set buffer size...", nullptr, false, isConnected && !isRunning)) { if (ImGui::MenuItem("Set buffer size...", nullptr, false, isConnected && !isRunning)) {
popupRequestBuffer = true; popupRequestBuffer = true;
} }
@ -575,7 +571,7 @@ void deviceConnect()
m_device.reset(new stmdsp::device(devices.front())); m_device.reset(new stmdsp::device(devices.front()));
} catch (...) { } catch (...) {
log("Failed to connect (check permissions?)."); log("Failed to connect (check permissions?).");
m_device.reset(); m_device.reset();
} }
if (m_device) { if (m_device) {

@ -10,6 +10,7 @@
*/ */
#include "imgui.h" #include "imgui.h"
#include "imgui_internal.h"
#include "backends/imgui_impl_sdl.h" #include "backends/imgui_impl_sdl.h"
#include "backends/imgui_impl_opengl2.h" #include "backends/imgui_impl_opengl2.h"
@ -49,19 +50,52 @@ bool guiInitialize()
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
io = &ImGui::GetIO(); io = &ImGui::GetIO();
io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; //io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
fontSans = io->Fonts->AddFontFromFileTTF("fonts/Roboto-Regular.ttf", 20); fontSans = io->Fonts->AddFontFromFileTTF("fonts/Roboto-Regular.ttf", 20);
fontMono = io->Fonts->AddFontFromFileTTF("fonts/RobotoMono-Regular.ttf", 20); fontMono = io->Fonts->AddFontFromFileTTF("fonts/RobotoMono-Regular.ttf", 20);
ImGui::StyleColorsLight();
ImGui_ImplSDL2_InitForOpenGL(window, gl_context); ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
ImGui_ImplOpenGL2_Init(); ImGui_ImplOpenGL2_Init();
ImGui::StyleColorsLight();
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 5; style.WindowRounding = 5;
style.FrameRounding = 3; style.FrameRounding = 3;
style.ScrollbarRounding = 1; style.ScrollbarRounding = 1;
//#define ACCENT1 0.26f, 0.59f, 0.98f
#define ACCENT1 0.6f, 0.6f, 0.6f
#define ACCENT2 0.4f, 0.4f, 0.4f
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(ACCENT1, 0.40f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(ACCENT1, 0.67f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(ACCENT1, 1.00f);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(ACCENT1, 0.78f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.46f, 0.54f, 0.80f, 0.60f);
style.Colors[ImGuiCol_Button] = ImVec4(ACCENT1, 0.40f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(ACCENT1, 1.00f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(ACCENT2, 1.00f);
style.Colors[ImGuiCol_Header] = ImVec4(ACCENT1, 0.31f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(ACCENT1, 0.80f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(ACCENT1, 1.00f);
style.Colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 0.62f);
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.14f, 0.44f, 0.80f, 0.78f);
style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.14f, 0.44f, 0.80f, 1.00f);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(ACCENT1, 0.67f);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(ACCENT1, 0.95f);
style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.78f, 0.87f, 0.98f, 1.00f);
style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.57f, 0.57f, 0.64f, 1.00f);
style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.68f, 0.68f, 0.74f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(ACCENT1, 0.35f);
style.Colors[ImGuiCol_DragDropTarget] = ImVec4(ACCENT1, 0.95f);
style.Colors[ImGuiCol_Tab] = ImLerp(style.Colors[ImGuiCol_Header], style.Colors[ImGuiCol_TitleBgActive], 0.90f);
style.Colors[ImGuiCol_TabHovered] = style.Colors[ImGuiCol_HeaderHovered];
style.Colors[ImGuiCol_TabActive] = ImLerp(style.Colors[ImGuiCol_HeaderActive], style.Colors[ImGuiCol_TitleBgActive], 0.60f);
style.Colors[ImGuiCol_TabUnfocused] = ImLerp(style.Colors[ImGuiCol_Tab], style.Colors[ImGuiCol_TitleBg], 0.80f);
style.Colors[ImGuiCol_TabUnfocusedActive] = ImLerp(style.Colors[ImGuiCol_TabActive], style.Colors[ImGuiCol_TitleBg], 0.40f);
style.Colors[ImGuiCol_NavHighlight] = style.Colors[ImGuiCol_HeaderHovered];
return true; return true;
} }

Loading…
Cancel
Save