From 2f0e97f6d95a24ca718174cd826f69c769655941 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 10 Sep 2022 23:20:22 -0500 Subject: [PATCH] GUI: FM operator swapping --- src/gui/gui.cpp | 1 + src/gui/gui.h | 2 +- src/gui/insEdit.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 66b562b6d..329c3e8e0 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -5217,6 +5217,7 @@ FurnaceGUI::FurnaceGUI(): chanToMove(-1), sysToMove(-1), sysToDelete(-1), + opToMove(-1), transposeAmount(0), randomizeMin(0), randomizeMax(255), diff --git a/src/gui/gui.h b/src/gui/gui.h index 2fb566d5c..f91c4beec 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1471,7 +1471,7 @@ class FurnaceGUI { int renderTimeBegin, renderTimeEnd, renderTimeDelta; int eventTimeBegin, eventTimeEnd, eventTimeDelta; - int chanToMove, sysToMove, sysToDelete; + int chanToMove, sysToMove, sysToDelete, opToMove; ImVec2 patWindowPos, patWindowSize; diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index ec9ba32ba..c2c7a2600 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -1557,6 +1557,35 @@ void FurnaceGUI::drawMacros(std::vector& macros) { #define CENTER_TEXT_20(text) \ ImGui::SetCursorPosX(ImGui::GetCursorPosX()+0.5*(20.0f*dpiScale-ImGui::CalcTextSize(text).x)); +#define OP_DRAG_POINT \ + if (ImGui::Button(ICON_FA_ARROWS)) { \ + } \ + if (ImGui::BeginDragDropSource()) { \ + opToMove=i; \ + ImGui::SetDragDropPayload("FUR_OP",NULL,0,ImGuiCond_Once); \ + ImGui::Button(ICON_FA_ARROWS "##SysDrag"); \ + ImGui::EndDragDropSource(); \ + } else if (ImGui::IsItemHovered()) { \ + ImGui::SetTooltip("(drag to swap operators)"); \ + } \ + if (ImGui::BeginDragDropTarget()) { \ + const ImGuiPayload* dragItem=ImGui::AcceptDragDropPayload("FUR_OP"); \ + if (dragItem!=NULL) { \ + if (dragItem->IsDataType("FUR_OP")) { \ + if (opToMove!=i && opToMove>=0) { \ + e->lockEngine([this,ins,i]() { \ + DivInstrumentFM::Operator origOp=ins->fm.op[orderedOps[opToMove]]; \ + ins->fm.op[orderedOps[opToMove]]=ins->fm.op[orderedOps[i]]; \ + ins->fm.op[orderedOps[i]]=origOp; \ + }); \ + PARAMETER; \ + } \ + opToMove=-1; \ + } \ + } \ + ImGui::EndDragDropTarget(); \ + } + void FurnaceGUI::drawInsEdit() { if (nextWindow==GUI_WINDOW_INS_EDIT) { insEditOpen=true; @@ -2073,6 +2102,9 @@ void FurnaceGUI::drawInsEdit() { } else { ImGui::Text("OP%d",i+1); } + + // drag point + OP_DRAG_POINT; int maxTl=127; if (ins->type==DIV_INS_OPLL) { @@ -2356,7 +2388,10 @@ void FurnaceGUI::drawInsEdit() { } else { snprintf(tempID,1024,"Operator %d",i+1); } - CENTER_TEXT(tempID); + float nextCursorPosX=ImGui::GetCursorPosX()+0.5*(ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize(tempID).x); + OP_DRAG_POINT; + ImGui::SameLine(); + ImGui::SetCursorPosX(nextCursorPosX); ImGui::TextUnformatted(tempID); float sliderHeight=200.0f*dpiScale; @@ -2789,6 +2824,8 @@ void FurnaceGUI::drawInsEdit() { } ImGui::Dummy(ImVec2(dpiScale,dpiScale)); + OP_DRAG_POINT; + ImGui::SameLine(); if (ins->type==DIV_INS_OPL_DRUMS) { ImGui::Text("%s",oplDrumNames[i]); } else if (ins->type==DIV_INS_OPL && ins->fm.opllPreset==16) {