GUI: new pattern cursor logic, part 1 - READ

this new pattern cursor logic will finally allow you to click on any
cell of the previous/next pattern and take you there
on top of that you'll be able to make selections that go beyond the
boundaries of a pattern

operations are not supported yet, so don't try it out!
it won't work properly until I adapt the code.
This commit is contained in:
tildearrow 2025-06-27 20:37:23 -05:00
parent eac8c03158
commit b9604c5729
5 changed files with 97 additions and 46 deletions

View file

@ -21,22 +21,24 @@
#include "../ta-log.h"
#include "actionUtil.h"
void FurnaceGUI::startSelection(int xCoarse, int xFine, int y, bool fullRow) {
void FurnaceGUI::startSelection(int xCoarse, int xFine, int y, int ord, bool fullRow) {
DETERMINE_FIRST_LAST;
if (xCoarse!=selStart.xCoarse || xFine!=selStart.xFine || y!=selStart.y) {
if (xCoarse!=selStart.xCoarse || xFine!=selStart.xFine || y!=selStart.y || ord!=selStart.order) {
curNibble=false;
}
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && !fullRow && settings.doubleClickColumn) {
if (cursor.xCoarse==xCoarse && cursor.xFine==xFine && cursor.y==y) {
if (cursor.xCoarse==xCoarse && cursor.xFine==xFine && cursor.y==y && cursor.order==ord) {
// select entire channel
selStart.xCoarse=xCoarse;
selStart.xFine=0;
selStart.y=0;
selStart.order=ord;
selEnd.xCoarse=xCoarse;
selEnd.xFine=2+e->curPat[selEnd.xCoarse].effectCols*2;
selEnd.y=e->curSubSong->patLen-1;
selEnd.order=ord;
finishSelection();
return;
@ -44,17 +46,19 @@ void FurnaceGUI::startSelection(int xCoarse, int xFine, int y, bool fullRow) {
}
if (((settings.dragMovesSelection==1 || settings.dragMovesSelection==3 || settings.dragMovesSelection==5) || ((settings.dragMovesSelection==2 || settings.dragMovesSelection==4) && (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl)))) && !fullRow) {
if (xCoarse>=selStart.xCoarse && (xFine>=selStart.xFine || xCoarse>selStart.xCoarse) && y>=selStart.y &&
xCoarse<=selEnd.xCoarse && (xFine<=selEnd.xFine || xCoarse<selEnd.xCoarse) && y<=selEnd.y) {
if (xCoarse>=selStart.xCoarse && (xFine>=selStart.xFine || xCoarse>selStart.xCoarse) && (ord>selStart.order || y>=selStart.y) &&
xCoarse<=selEnd.xCoarse && (xFine<=selEnd.xFine || xCoarse<selEnd.xCoarse) && (ord<selEnd.order || y<=selEnd.y)) {
dragging=true;
selecting=true;
selectingFull=false;
dragSourceX=xCoarse;
dragSourceXFine=xFine;
dragSourceY=y;
dragSourceOrder=ord;
dragDestinationX=xCoarse;
dragDestinationXFine=xFine;
dragDestinationY=y;
dragDestinationOrder=ord;
dragStart=selStart;
dragEnd=selEnd;
return;
@ -68,34 +72,41 @@ void FurnaceGUI::startSelection(int xCoarse, int xFine, int y, bool fullRow) {
selEnd.xFine=2+e->curPat[selEnd.xCoarse].effectCols*2;
selStart.y=y;
selEnd.y=y;
selStart.order=ord;
selEnd.order=ord;
} else {
if (xCoarse!=cursor.xCoarse || y!=cursor.y) {
if (xCoarse!=cursor.xCoarse || y!=cursor.y || ord!=cursor.order) {
makeCursorUndo();
}
cursor.xCoarse=xCoarse;
cursor.xFine=xFine;
cursor.y=y;
cursor.order=ord;
selStart.xCoarse=xCoarse;
selStart.xFine=xFine;
selStart.y=y;
selStart.order=ord;
selEnd.xCoarse=xCoarse;
selEnd.xFine=xFine;
selEnd.y=y;
selEnd.order=ord;
}
selecting=true;
selectingFull=fullRow;
e->setMidiBaseChan(cursor.xCoarse);
}
void FurnaceGUI::updateSelection(int xCoarse, int xFine, int y, bool fullRow) {
void FurnaceGUI::updateSelection(int xCoarse, int xFine, int y, int ord, bool fullRow) {
if (!selecting) return;
if (dragging) {
dragDestinationX=xCoarse;
if (dragStart.xFine>=3 && dragStart.xCoarse==dragEnd.xCoarse) dragDestinationXFine=(dragSourceXFine&1)?((xFine-1)|1):((xFine+1)&(~1));
dragDestinationY=y;
dragDestinationOrder=ord;
cursorDrag.xCoarse=xCoarse;
cursorDrag.xFine=xFine;
cursorDrag.y=y;
cursorDrag.order=ord;
int len=dragEnd.xCoarse-dragStart.xCoarse+1;
if (len<0) len=0;
@ -119,6 +130,7 @@ void FurnaceGUI::updateSelection(int xCoarse, int xFine, int y, bool fullRow) {
}
}
// TODO: new cursor logic
if (dragStart.y+(dragDestinationY-dragSourceY)<0) {
dragDestinationY=dragSourceY-dragStart.y;
}
@ -139,17 +151,26 @@ void FurnaceGUI::updateSelection(int xCoarse, int xFine, int y, bool fullRow) {
selEnd.xCoarse=lastChannel-1;
selEnd.xFine=2+e->curPat[selEnd.xCoarse].effectCols*2;
selEnd.y=y;
selEnd.order=ord;
} else {
selEnd.xCoarse=xCoarse;
selEnd.xFine=xFine;
selEnd.y=y;
selEnd.order=ord;
}
}
}
void FurnaceGUI::finishSelection() {
// swap points if needed
if (selEnd.y<selStart.y) {
if (selEnd.order<selStart.order) {
selEnd.order^=selStart.order;
selStart.order^=selEnd.order;
selEnd.order^=selStart.order;
selEnd.y^=selStart.y;
selStart.y^=selEnd.y;
selEnd.y^=selStart.y;
} else if (selEnd.order==selStart.order && selEnd.y<selStart.y) {
selEnd.y^=selStart.y;
selStart.y^=selEnd.y;
selEnd.y^=selStart.y;
@ -172,7 +193,7 @@ void FurnaceGUI::finishSelection() {
mobilePatSel=false;
if (dragging) {
if (dragSourceX==dragDestinationX && dragSourceY==dragDestinationY && dragSourceXFine==dragDestinationXFine) {
if (dragSourceX==dragDestinationX && dragSourceY==dragDestinationY && dragSourceXFine==dragDestinationXFine && dragSourceOrder==dragDestinationOrder) {
cursor=cursorDrag;
selStart=cursorDrag;
selEnd=cursorDrag;
@ -190,14 +211,20 @@ void FurnaceGUI::finishSelection() {
if (selStart.xCoarse>=chanCount) selStart.xCoarse=chanCount-1;
if (selStart.y<0) selStart.y=0;
if (selStart.y>=e->curSubSong->patLen) selStart.y=e->curSubSong->patLen-1;
if (selStart.order<0) selStart.order=0;
if (selStart.order>=e->curSubSong->ordersLen) selStart.order=e->curSubSong->ordersLen-1;
if (selEnd.xCoarse<0) selEnd.xCoarse=0;
if (selEnd.xCoarse>=chanCount) selEnd.xCoarse=chanCount-1;
if (selEnd.y<0) selEnd.y=0;
if (selEnd.y>=e->curSubSong->patLen) selEnd.y=e->curSubSong->patLen-1;
if (selEnd.order<0) selEnd.order=0;
if (selEnd.order>=e->curSubSong->ordersLen) selEnd.order=e->curSubSong->ordersLen-1;
if (cursor.xCoarse<0) cursor.xCoarse=0;
if (cursor.xCoarse>=chanCount) cursor.xCoarse=chanCount-1;
if (cursor.y<0) cursor.y=0;
if (cursor.y>=e->curSubSong->patLen) cursor.y=e->curSubSong->patLen-1;
if (cursor.order<0) cursor.order=0;
if (cursor.order>=e->curSubSong->ordersLen) cursor.order=e->curSubSong->ordersLen-1;
if (e->curSubSong->chanCollapse[selStart.xCoarse]==3) {
selStart.xFine=0;
@ -218,7 +245,13 @@ void FurnaceGUI::finishSelection() {
selEnd.xFine=2+e->curPat[selEnd.xCoarse].effectCols*2;
}
logV(_("finish selection: %d.%d,%d - %d.%d,%d"),selStart.xCoarse,selStart.xFine,selStart.y,selEnd.xCoarse,selEnd.xFine,selEnd.y);
// change order if necessary
if (curOrder!=cursor.order) {
setOrder(cursor.order);
updateScroll(cursor.y);
}
logV(_("finish selection: %d.%d,%d.%d - %d.%d,%d.%d"),selStart.xCoarse,selStart.xFine,selStart.order,selStart.y,selEnd.xCoarse,selEnd.xFine,selEnd.order,selEnd.y);
e->setMidiBaseChan(cursor.xCoarse);
}

View file

@ -645,7 +645,8 @@ void FurnaceGUI::doAction(int what) {
selEndPat.xCoarse=e->getTotalChannelCount()-1;
selEndPat.xFine=2+e->curPat[selEndPat.xCoarse].effectCols*2;
selEndPat.y=e->curSubSong->patLen-1;
doCollapse(collapseAmount,SelectionPoint(0,0,0),selEndPat);
selEndPat.order=curOrder;
doCollapse(collapseAmount,SelectionPoint(0,0,0,curOrder),selEndPat);
break;
}
case GUI_ACTION_PAT_EXPAND_PAT: {
@ -653,7 +654,8 @@ void FurnaceGUI::doAction(int what) {
selEndPat.xCoarse=e->getTotalChannelCount()-1;
selEndPat.xFine=2+e->curPat[selEndPat.xCoarse].effectCols*2;
selEndPat.y=e->curSubSong->patLen-1;
doExpand(collapseAmount,SelectionPoint(0,0,0),selEndPat);
selEndPat.order=curOrder;
doExpand(collapseAmount,SelectionPoint(0,0,0,curOrder),selEndPat);
break;
}
case GUI_ACTION_PAT_COLLAPSE_SONG:

View file

@ -8609,9 +8609,13 @@ FurnaceGUI::FurnaceGUI():
wheelX(0),
wheelY(0),
dragSourceX(0),
dragSourceXFine(0),
dragSourceY(0),
dragSourceOrder(0),
dragDestinationX(0),
dragDestinationXFine(0),
dragDestinationY(0),
dragDestinationOrder(0),
oldBeat(-1),
oldBar(-1),
curGroove(-1),

View file

@ -1006,11 +1006,11 @@ enum NoteCtrl {
struct SelectionPoint {
int xCoarse, xFine;
int y;
SelectionPoint(int xc, int xf, int yp):
xCoarse(xc), xFine(xf), y(yp) {}
int y, order;
SelectionPoint(int xc, int xf, int yp, int o):
xCoarse(xc), xFine(xf), y(yp), order(o) {}
SelectionPoint():
xCoarse(0), xFine(0), y(0) {}
xCoarse(0), xFine(0), y(0), order(0) {}
};
struct UndoRegion {
@ -2343,7 +2343,7 @@ class FurnaceGUI {
int curIns, curWave, curSample, curOctave, curOrder, playOrder, prevIns, oldRow, editStep, editStepCoarse, soloChan, orderEditMode, orderCursor;
int loopOrder, loopRow, loopEnd, isClipping, newSongCategory, latchTarget;
int wheelX, wheelY, dragSourceX, dragSourceXFine, dragSourceY, dragDestinationX, dragDestinationXFine, dragDestinationY, oldBeat, oldBar;
int wheelX, wheelY, dragSourceX, dragSourceXFine, dragSourceY, dragSourceOrder, dragDestinationX, dragDestinationXFine, dragDestinationY, dragDestinationOrder, oldBeat, oldBar;
int curGroove, exitDisabledTimer;
int curPaletteChoice, curPaletteType;
float soloTimeout;
@ -2983,8 +2983,8 @@ class FurnaceGUI {
void processDrags(int dragX, int dragY);
void processPoint(SDL_Event& ev);
void startSelection(int xCoarse, int xFine, int y, bool fullRow=false);
void updateSelection(int xCoarse, int xFine, int y, bool fullRow=false);
void startSelection(int xCoarse, int xFine, int y, int ord, bool fullRow=false);
void updateSelection(int xCoarse, int xFine, int y, int ord, bool fullRow=false);
void finishSelection();
void finishDrag();

View file

@ -71,7 +71,11 @@ void FurnaceGUI::popPartBlend() {
// draw a pattern row
inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord, const DivPattern** patCache, bool inhibitSel) {
static char id[64];
bool selectedRow=(i>=sel1.y && i<=sel2.y && !inhibitSel);
bool selectedRow=(
!inhibitSel &&
(ord>sel1.order || (ord==sel1.order && i>=sel1.y)) &&
(ord<sel2.order || (ord==sel2.order && i<=sel2.y))
);
ImGui::TableNextRow(0,lineHeight);
ImGui::TableNextColumn();
float cursorPosY=ImGui::GetCursorPos().y-ImGui::GetScrollY();
@ -105,7 +109,7 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
}
// check overflow highlight
if (settings.overflowHighlight) {
if (edit && cursor.y==i && curWindowLast==GUI_WINDOW_PATTERN) {
if (edit && cursor.y==i && cursor.order==ord && curWindowLast==GUI_WINDOW_PATTERN) {
if (editClone && !isPatUnique && secondTimer<0.5) {
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING_CLONE]));
} else {
@ -120,7 +124,7 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
}
} else {
isPushing=true;
if (edit && cursor.y==i && curWindowLast==GUI_WINDOW_PATTERN) {
if (edit && cursor.y==i && cursor.order==ord && curWindowLast==GUI_WINDOW_PATTERN) {
if (editClone && !isPatUnique && secondTimer<0.5) {
ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING_CLONE]));
} else {
@ -146,10 +150,10 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
}
ImGui::Selectable(id,false,ImGuiSelectableFlags_NoPadWithHalfSpacing,fourChars);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(0,0,i,true);
updateSelection(0,0,i,ord,true);
}
if (ImGui::IsItemClicked()) {
startSelection(0,0,i,true);
startSelection(0,0,i,ord,true);
}
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
ImGui::InhibitInertialScroll();
@ -182,9 +186,9 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
bool selectedNote=selectedRow && (j32>=sel1XSum && j32<=sel2XSum);
bool selectedIns=selectedRow && (j32+1>=sel1XSum && j32+1<=sel2XSum);
bool selectedVol=selectedRow && (j32+2>=sel1XSum && j32+2<=sel2XSum);
bool cursorNote=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==0 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorIns=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==1 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorVol=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==2 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorNote=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==0 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorIns=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==1 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorVol=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==2 && curWindowLast==GUI_WINDOW_PATTERN);
// note
snprintf(id,63,"%.31s###PN_%d_%d",noteName(pat->data[i][0],pat->data[i][1]),i,j);
@ -205,10 +209,10 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
if (selectedNote) ImGui::PopStyleColor();
}
if (ImGui::IsItemClicked()) {
startSelection(j,0,i);
startSelection(j,0,i,ord);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,0,i);
updateSelection(j,0,i,ord);
}
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
ImGui::InhibitInertialScroll();
@ -249,10 +253,10 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
if (selectedIns) ImGui::PopStyleColor();
}
if (ImGui::IsItemClicked()) {
startSelection(j,1,i);
startSelection(j,1,i,ord);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,1,i);
updateSelection(j,1,i,ord);
}
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
ImGui::InhibitInertialScroll();
@ -287,10 +291,10 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
if (selectedVol) ImGui::PopStyleColor();
}
if (ImGui::IsItemClicked()) {
startSelection(j,2,i);
startSelection(j,2,i,ord);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,2,i);
updateSelection(j,2,i,ord);
}
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
ImGui::InhibitInertialScroll();
@ -306,8 +310,8 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
int index=4+(k<<1);
bool selectedEffect=selectedRow && (j32+index-1>=sel1XSum && j32+index-1<=sel2XSum);
bool selectedEffectVal=selectedRow && (j32+index>=sel1XSum && j32+index<=sel2XSum);
bool cursorEffect=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==index-1 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorEffectVal=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==index && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorEffect=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==index-1 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorEffectVal=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==index && curWindowLast==GUI_WINDOW_PATTERN);
// effect
if (pat->data[i][index]==-1) {
@ -340,10 +344,10 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
if (selectedEffect) ImGui::PopStyleColor();
}
if (ImGui::IsItemClicked()) {
startSelection(j,index-1,i);
startSelection(j,index-1,i,ord);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,index-1,i);
updateSelection(j,index-1,i,ord);
}
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
ImGui::InhibitInertialScroll();
@ -370,10 +374,10 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
if (selectedEffectVal) ImGui::PopStyleColor();
}
if (ImGui::IsItemClicked()) {
startSelection(j,index,i);
startSelection(j,index,i,ord);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,index,i);
updateSelection(j,index,i,ord);
}
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
ImGui::InhibitInertialScroll();
@ -408,6 +412,7 @@ void FurnaceGUI::drawPattern() {
if (oldRowChanged || !e->isStepping()) {
if (e->isStepping()) pendingStepUpdate=1;
cursor.y=oldRow;
cursor.order=curOrder;
if (selStart.xCoarse==selEnd.xCoarse && selStart.xFine==selEnd.xFine && selStart.y==selEnd.y && !selecting) {
selStart=cursor;
selEnd=cursor;
@ -416,7 +421,14 @@ void FurnaceGUI::drawPattern() {
}
sel1=selStart;
sel2=selEnd;
if (sel2.y<sel1.y) {
if (sel2.order<sel1.order) {
sel2.order^=sel1.order;
sel1.order^=sel2.order;
sel2.order^=sel1.order;
sel2.y^=sel1.y;
sel1.y^=sel2.y;
sel2.y^=sel1.y;
} else if (sel2.order==sel1.order && sel2.y<sel1.y) {
sel2.y^=sel1.y;
sel1.y^=sel2.y;
sel2.y^=sel1.y;
@ -1165,22 +1177,22 @@ void FurnaceGUI::drawPattern() {
// オップナー2608 i owe you one more for this horrible code
// previous pattern
ImGui::BeginDisabled();
ImGui::PushStyleVar(ImGuiStyleVar_FrameShading,0.0f);
if (settings.viewPrevPattern) {
if ((ord-1)>=0) for (int i=0; i<chans; i++) {
patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord-1],true);
patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord-1],false);
}
ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*ImGui::GetStyle().DisabledAlpha);
for (int i=0; i<dummyRows-1; i++) {
patternRow(e->curSubSong->patLen+i-dummyRows+1,e->isPlaying(),lineHeight,chans,ord-1,patCache,true);
}
ImGui::PopStyleVar();
} else {
for (int i=0; i<dummyRows-1; i++) {
ImGui::TableNextRow(0,lineHeight);
ImGui::TableNextColumn();
}
}
ImGui::EndDisabled();
// active area
for (int i=0; i<chans; i++) {
patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord],true);
@ -1189,14 +1201,15 @@ void FurnaceGUI::drawPattern() {
patternRow(i,e->isPlaying(),lineHeight,chans,ord,patCache,false);
}
// next pattern
ImGui::BeginDisabled();
if (settings.viewPrevPattern) {
if ((ord+1)<e->curSubSong->ordersLen) for (int i=0; i<chans; i++) {
patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord+1],true);
}
ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*ImGui::GetStyle().DisabledAlpha);
for (int i=0; i<=dummyRows; i++) {
patternRow(i,e->isPlaying(),lineHeight,chans,ord+1,patCache,true);
patternRow(i,e->isPlaying(),lineHeight,chans,ord+1,patCache,false);
}
ImGui::PopStyleVar();
} else {
for (int i=0; i<=dummyRows; i++) {
ImGui::TableNextRow(0,lineHeight);
@ -1204,7 +1217,6 @@ void FurnaceGUI::drawPattern() {
}
}
ImGui::EndDisabled();
ImGui::PopStyleVar();
if (demandScrollX) {
float finalX=-fourChars.x;