Skip to content

Commit 465328c

Browse files
committed
GUI: set order to free pattern on middle-click
1 parent 5b145b7 commit 465328c

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/engine/pattern.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ void DivChannelData::wipePatterns() {
8484
}
8585
}
8686

87+
bool DivPattern::isEmpty() {
88+
for (int i=0; i<DIV_MAX_ROWS; i++) {
89+
for (int j=0; j<DIV_MAX_COLS; j++) {
90+
if (newData[i][j]!=-1) return false;
91+
}
92+
}
93+
return true;
94+
}
95+
8796
void DivPattern::copyOn(DivPattern* dest) {
8897
dest->name=name;
8998
memcpy(dest->newData,newData,sizeof(newData));

src/engine/pattern.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ struct DivPattern {
3939
*/
4040
short newData[DIV_MAX_ROWS][DIV_MAX_COLS];
4141

42+
/**
43+
* check whether this pattern is empty.
44+
* @return whether it is.
45+
*/
46+
bool isEmpty();
47+
4248
/**
4349
* clear the pattern.
4450
*/

src/gui/orders.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,43 @@ void FurnaceGUI::drawOrders() {
407407
if (!pat->name.empty() && ImGui::IsItemHovered()) {
408408
ImGui::SetTooltip("%s",pat->name.c_str());
409409
}
410+
bool findFreePat=ImGui::IsItemClicked(ImGuiMouseButton_Middle);
411+
if (ImGui::IsItemHovered() && CHECK_LONG_HOLD) {
412+
NOTIFY_LONG_HOLD;
413+
findFreePat=true;
414+
}
415+
if (findFreePat) {
416+
// find free pattern and assign it
417+
prepareUndo(GUI_UNDO_CHANGE_ORDER);
418+
e->lockSave([this,i,j]() {
419+
bool foundOne=false;
420+
bool available[DIV_MAX_PATTERNS];
421+
memset(available,1,DIV_MAX_PATTERNS*sizeof(bool));
422+
for (int k=0; k<e->curSubSong->ordersLen; k++) {
423+
available[e->curOrders->ord[j][k]]=false;
424+
}
425+
for (int k=0; k<DIV_MAX_PATTERNS; k++) {
426+
// don't accept a used pattern
427+
if (!available[k]) continue;
428+
// accept an unallocated pattern (guaranteed to be empty)
429+
if (e->curPat[j].data[k]==NULL) {
430+
e->curOrders->ord[j][i]=k;
431+
foundOne=true;
432+
break;
433+
} else {
434+
// check whether this pattern is empty and accept it if so
435+
DivPattern* p=e->curPat[j].getPattern(k,false);
436+
if (p->isEmpty()) {
437+
e->curOrders->ord[j][i]=k;
438+
foundOne=true;
439+
break;
440+
}
441+
}
442+
}
443+
if (!foundOne) showError(_("no free patterns available on this channel!"));
444+
});
445+
makeUndo(GUI_UNDO_CHANGE_ORDER);
446+
}
410447
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
411448
if (curOrder==i) {
412449
if (orderEditMode==0) {

0 commit comments

Comments
 (0)