From 6f5450f0eccd4765fa6965fb1491318571256c97 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 20 May 2024 19:20:29 -0500 Subject: [PATCH] GUI: improve cursor focus now it's no longer fucking annoying --- src/gui/gui.h | 2 +- src/gui/pattern.cpp | 46 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/gui/gui.h b/src/gui/gui.h index 7ec0a4f6b..3c23ff83e 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2441,7 +2441,7 @@ class FurnaceGUI { ImVec2 fourChars, threeChars, twoChars; ImVec2 noteCellSize, insCellSize, volCellSize, effectCellSize, effectValCellSize; SelectionPoint sel1, sel2; - int dummyRows, demandX; + int dummyRows; int transposeAmount, randomizeMin, randomizeMax, fadeMin, fadeMax, collapseAmount; float scaleMax; bool fadeMode, randomMode, haveHitBounds; diff --git a/src/gui/pattern.cpp b/src/gui/pattern.cpp index f675f8e29..a1fc3a87c 100644 --- a/src/gui/pattern.cpp +++ b/src/gui/pattern.cpp @@ -191,7 +191,6 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]); ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]); ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,noteCellSize); - demandX=ImGui::GetCursorPosX(); ImGui::PopStyleColor(3); } else { if (selectedNote) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]); @@ -235,7 +234,6 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]); ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]); ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,insCellSize); - demandX=ImGui::GetCursorPosX(); ImGui::PopStyleColor(3); } else { if (selectedIns) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]); @@ -273,7 +271,6 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]); ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]); ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,volCellSize); - demandX=ImGui::GetCursorPosX(); ImGui::PopStyleColor(3); } else { if (selectedVol) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]); @@ -326,7 +323,6 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]); ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]); ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectCellSize); - demandX=ImGui::GetCursorPosX(); ImGui::PopStyleColor(3); } else { if (selectedEffect) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]); @@ -356,7 +352,6 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]); ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]); ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectValCellSize); - demandX=ImGui::GetCursorPosX(); ImGui::PopStyleColor(3); } else { if (selectedEffectVal) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]); @@ -407,7 +402,6 @@ void FurnaceGUI::drawPattern() { } } } - demandX=0; sel1=selStart; sel2=selEnd; if (sel2.y(ImGui::GetWindowWidth()-200*dpiScale)) { - ImGui::SetScrollX(demandX+200*dpiScale); + float finalX=-fourChars.x; + // manually calculate X scroll + for (int i=0; i<=cursor.xCoarse; i++) { + int fine=(i==cursor.xCoarse)?cursor.xFine:9999; + if (!e->curSubSong->chanShow[i]) continue; + + finalX+=noteCellSize.x; + // ins + if (fine==0) break; + if (e->curSubSong->chanCollapse[i]<3) { + finalX+=insCellSize.x; + } + // vol + if (fine==1) break; + if (e->curSubSong->chanCollapse[i]<2) { + finalX+=volCellSize.x; + } + // effects + if (fine==2) break; + if (e->curSubSong->chanCollapse[i]<1) { + for (int j=0; jcurPat[i].effectCols*2); j++) { + if (j&1) { + finalX+=effectValCellSize.x; + } else { + finalX+=effectCellSize.x; + } + } + } + } + float totalDemand=finalX-ImGui::GetScrollX(); + float availWidth=ImGui::GetWindowWidth(); + if (totalDemand<(availWidth*0.25f)) { + ImGui::SetScrollX(finalX-availWidth*0.25f); + } else if (totalDemand>(availWidth*0.7f)) { + ImGui::SetScrollX(finalX-availWidth*0.7f); } demandScrollX=false; }