From 18b05767808f0ad965dc62f04cec9905fda41c3d Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Sat, 22 Oct 2022 10:46:49 -0700 Subject: [PATCH 1/3] Cleanup: Rename Del -> Btn This button can be for adding or removing, so rename to Btn to be less confusing. --- ImSequencer.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ImSequencer.cpp b/ImSequencer.cpp index d4c6cf4b..dc0e98ea 100644 --- a/ImSequencer.cpp +++ b/ImSequencer.cpp @@ -38,16 +38,16 @@ namespace ImSequencer static bool SequencerAddDelButton(ImDrawList* draw_list, ImVec2 pos, bool add = true) { ImGuiIO& io = ImGui::GetIO(); - ImRect delRect(pos, ImVec2(pos.x + 16, pos.y + 16)); - bool overDel = delRect.Contains(io.MousePos); - int delColor = overDel ? 0xFFAAAAAA : 0x77A3B2AA; + ImRect btnRect(pos, ImVec2(pos.x + 16, pos.y + 16)); + bool overBtn = btnRect.Contains(io.MousePos); + int btnColor = overBtn ? 0xFFAAAAAA : 0x77A3B2AA; float midy = pos.y + 16 / 2 - 0.5f; float midx = pos.x + 16 / 2 - 0.5f; - draw_list->AddRect(delRect.Min, delRect.Max, delColor, 4); - draw_list->AddLine(ImVec2(delRect.Min.x + 3, midy), ImVec2(delRect.Max.x - 3, midy), delColor, 2); + draw_list->AddRect(btnRect.Min, btnRect.Max, btnColor, 4); + draw_list->AddLine(ImVec2(btnRect.Min.x + 3, midy), ImVec2(btnRect.Max.x - 3, midy), btnColor, 2); if (add) - draw_list->AddLine(ImVec2(midx, delRect.Min.y + 3), ImVec2(midx, delRect.Max.y - 3), delColor, 2); - return overDel; + draw_list->AddLine(ImVec2(midx, btnRect.Min.y + 3), ImVec2(midx, btnRect.Max.y - 3), btnColor, 2); + return overBtn; } bool Sequencer(SequenceInterface* sequence, int* currentFrame, bool* expanded, int* selectedEntry, int* firstFrame, int sequenceOptions) From 4cda4b7c2b0a24a44a3e43df0abc3ebecbab17b1 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Sat, 22 Oct 2022 10:52:09 -0700 Subject: [PATCH 2/3] Sequencer: Require click to start inside button Fix dragging a ImSequencer track start over the remove button and releasing deletes the track. Fix clicking on ImSequencer duplicate and dragging off to cancel removes the track if you released over the remove button. Now SequencerAddDelButton behaves like ImGui:Button: requires the click to start inside the button and end inside the button. Test Build imguizmo test app. * Click drag track start and end. * Click expand, add, duplicate, and remove buttons. * Click drag off remove button. * Click drag track start over remove button. --- ImSequencer.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ImSequencer.cpp b/ImSequencer.cpp index dc0e98ea..3c7e4bf8 100644 --- a/ImSequencer.cpp +++ b/ImSequencer.cpp @@ -40,14 +40,17 @@ namespace ImSequencer ImGuiIO& io = ImGui::GetIO(); ImRect btnRect(pos, ImVec2(pos.x + 16, pos.y + 16)); bool overBtn = btnRect.Contains(io.MousePos); - int btnColor = overBtn ? 0xFFAAAAAA : 0x77A3B2AA; + bool containedClick = overBtn && btnRect.Contains(io.MouseClickedPos[0]); + bool clickedBtn = containedClick && io.MouseReleased[0]; + int btnColor = overBtn ? 0xAAEAFFAA : 0x77A3B2AA; + float midy = pos.y + 16 / 2 - 0.5f; float midx = pos.x + 16 / 2 - 0.5f; draw_list->AddRect(btnRect.Min, btnRect.Max, btnColor, 4); draw_list->AddLine(ImVec2(btnRect.Min.x + 3, midy), ImVec2(btnRect.Max.x - 3, midy), btnColor, 2); if (add) draw_list->AddLine(ImVec2(midx, btnRect.Min.y + 3), ImVec2(midx, btnRect.Max.y - 3), btnColor, 2); - return overBtn; + return clickedBtn; } bool Sequencer(SequenceInterface* sequence, int* currentFrame, bool* expanded, int* selectedEntry, int* firstFrame, int sequenceOptions) @@ -193,7 +196,7 @@ namespace ImSequencer draw_list->AddRectFilled(canvas_pos, ImVec2(canvas_size.x + canvas_pos.x, canvas_pos.y + ItemHeight), 0xFF3D3837, 0); if (sequenceOptions & SEQUENCER_ADD) { - if (SequencerAddDelButton(draw_list, ImVec2(canvas_pos.x + legendWidth - ItemHeight, canvas_pos.y + 2), true) && io.MouseReleased[0]) + if (SequencerAddDelButton(draw_list, ImVec2(canvas_pos.x + legendWidth - ItemHeight, canvas_pos.y + 2), true)) ImGui::OpenPopup("addEntry"); if (ImGui::BeginPopup("addEntry")) @@ -280,12 +283,10 @@ namespace ImSequencer if (sequenceOptions & SEQUENCER_DEL) { - bool overDel = SequencerAddDelButton(draw_list, ImVec2(contentMin.x + legendWidth - ItemHeight + 2 - 10, tpos.y + 2), false); - if (overDel && io.MouseReleased[0]) + if (SequencerAddDelButton(draw_list, ImVec2(contentMin.x + legendWidth - ItemHeight + 2 - 10, tpos.y + 2), false)) delEntry = i; - bool overDup = SequencerAddDelButton(draw_list, ImVec2(contentMin.x + legendWidth - ItemHeight - ItemHeight + 2 - 10, tpos.y + 2), true); - if (overDup && io.MouseReleased[0]) + if (SequencerAddDelButton(draw_list, ImVec2(contentMin.x + legendWidth - ItemHeight - ItemHeight + 2 - 10, tpos.y + 2), true)) dupEntry = i; } customHeight += sequence->GetCustomHeight(i); @@ -675,8 +676,7 @@ namespace ImSequencer if (expanded) { - bool overExpanded = SequencerAddDelButton(draw_list, ImVec2(canvas_pos.x + 2, canvas_pos.y + 2), !*expanded); - if (overExpanded && io.MouseReleased[0]) + if (SequencerAddDelButton(draw_list, ImVec2(canvas_pos.x + 2, canvas_pos.y + 2), !*expanded)) *expanded = !*expanded; } From 43d8af4e0cf366da1d243a6eeb0197ee312e93ae Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Sat, 22 Oct 2022 11:01:57 -0700 Subject: [PATCH 3/3] Sequencer: Animate buttons on press When you click a button, expand its size to give feedback that it's pressed. Expanding looks better than shifting it down. Native imgui buttons use a different colour on press, but there's so little color to the AddDel button that you can't see it. --- ImSequencer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ImSequencer.cpp b/ImSequencer.cpp index 3c7e4bf8..b1d9ba91 100644 --- a/ImSequencer.cpp +++ b/ImSequencer.cpp @@ -43,6 +43,8 @@ namespace ImSequencer bool containedClick = overBtn && btnRect.Contains(io.MouseClickedPos[0]); bool clickedBtn = containedClick && io.MouseReleased[0]; int btnColor = overBtn ? 0xAAEAFFAA : 0x77A3B2AA; + if (containedClick && io.MouseDownDuration[0] > 0) + btnRect.Expand(2.0f); float midy = pos.y + 16 / 2 - 0.5f; float midx = pos.x + 16 / 2 - 0.5f;