Handle double-click-to-reset on Scope sliders; Cleanup

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-05-18 18:18:14 +01:00
parent 2d42ef5249
commit 8d68d6e10c
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
2 changed files with 75 additions and 13 deletions

View file

@ -141,6 +141,17 @@ static ScopeData* getFakeScopeInstance()
struct SassyScopeWidget : ImGuiWidget {
SassyScopeModule* module = nullptr;
int lastClickedSliderBox = -1;
Rect sliderBoxes[8];
SassyScopeWidget()
{
for (int i=0; i<8; ++i)
{
sliderBoxes[i].pos = Vec(8 + (i % 4) * 27, 32 + (i / 4) * 153);
sliderBoxes[i].size = Vec(19, 150);
}
}
void drawImGui() override
{
@ -172,10 +183,54 @@ struct SassyScopeWidget : ImGuiWidget {
// center scope
if (e.pos.x >= 110 && e.pos.x <= 452 && e.pos.y >= 0 && e.pos.y <= 350)
return;
// consume for double-click if event belongs to a slider
lastClickedSliderBox = -1;
for (int i=0; i<8; ++i)
{
if (sliderBoxes[i].contains(e.pos))
{
lastClickedSliderBox = i;
e.consume(this);
break;
}
}
}
ImGuiWidget::onButton(e);
}
void onDoubleClick(const DoubleClickEvent& e) override
{
// handle double-click for slider param reset
if (lastClickedSliderBox != -1)
{
const int i = lastClickedSliderBox;
lastClickedSliderBox = -1;
// fake a mouse release
ButtonEvent e2 = {};
e2.button = GLFW_MOUSE_BUTTON_LEFT;
e2.action = GLFW_RELEASE;
ImGuiWidget::onButton(e2);
// do the reset
if (i < 4)
{
module->scope.mCh[i].mScaleSlider = 0;
module->scope.mCh[i].mScale = 1.0f / 5.0f;
}
else
{
module->scope.mCh[i-4].mOffset = 0;
}
e.consume(this);
return;
}
ImGuiWidget::onDoubleClick(e);
}
};
struct SassyScopeModuleWidget : ModuleWidget {

View file

@ -610,15 +610,7 @@ void do_show_scope_window(ScopeData* gScope, const float uiScale)
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[0]); ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[0]);
if (ImGui::VSliderInt("###0a", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[0].mScaleSlider, -4, 4, ""))
{
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
gScope->mCh[0].mScaleSlider = 0;
gScope->mCh[0].mScale = scalesteps[4];
}
else
{
gScope->mCh[0].mScale = scalesteps[gScope->mCh[0].mScaleSlider + 4];
}
gScope->mCh[0].mScale = scalesteps[gScope->mCh[0].mScaleSlider + 4];
}
if (ImGui::IsItemHovered())
{
@ -664,28 +656,43 @@ void do_show_scope_window(ScopeData* gScope, const float uiScale)
}
ImGui::PopStyleColor(2);
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[0]); ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[0]); ImGui::VSliderFloat("###0b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[0].mOffset, -2, 2, ""); ImGui::PopStyleColor(2); ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[0]);
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[0]);
ImGui::VSliderFloat("###0b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[0].mOffset, -2, 2, "");
ImGui::PopStyleColor(2);
ImGui::SameLine();
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%3.3f", gScope->mCh[0].mOffset);
ImGui::EndTooltip();
}
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[1]); ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[1]); ImGui::VSliderFloat("###1b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[1].mOffset, -2, 2, ""); ImGui::PopStyleColor(2); ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[1]);
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[1]);
ImGui::VSliderFloat("###1b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[1].mOffset, -2, 2, "");
ImGui::PopStyleColor(2);
ImGui::SameLine();
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%3.3f", gScope->mCh[1].mOffset);
ImGui::EndTooltip();
}
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[2]); ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[2]); ImGui::VSliderFloat("###2b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[2].mOffset, -2, 2, ""); ImGui::PopStyleColor(2); ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[2]);
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[2]);
ImGui::VSliderFloat("###2b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[2].mOffset, -2, 2, "");
ImGui::PopStyleColor(2);
ImGui::SameLine();
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%3.3f", gScope->mCh[2].mOffset);
ImGui::EndTooltip();
}
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[3]); ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[3]); ImGui::VSliderFloat("###3b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[3].mOffset, -2, 2, ""); ImGui::PopStyleColor(2);
ImGui::PushStyleColor(ImGuiCol_SliderGrab, gScope->colors[3]);
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, gScope->colors[3]);
ImGui::VSliderFloat("###3b", ImVec2(19 * uiScale, 150 * uiScale), &gScope->mCh[3].mOffset, -2, 2, "");
ImGui::PopStyleColor(2);
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();