channel drag copy: initial impl

This commit is contained in:
yohannd1 2025-09-28 12:43:47 -03:00 committed by tildearrow
parent e6c98506d1
commit 1099c79ec8
3 changed files with 44 additions and 4 deletions

View file

@ -603,10 +603,33 @@ void DivEngine::createNewFromDefaults() {
BUSY_END;
}
void DivEngine::copyChannel(int src, int dest) {
logV("copying channel %d to %d",src,dest);
if (src==dest) {
logV("not copying because it's the same channel!");
return;
}
for (int i=0; i<DIV_MAX_PATTERNS; i++) {
curOrders->ord[dest][i]=curOrders->ord[src][i];
if (curPat[src].data[i]!=NULL && curPat[dest].data[i]!=NULL) {
curPat[src].data[i]->copyOn(curPat[dest].data[i]);
}
}
curPat[dest].effectCols=curPat[src].effectCols;
curSubSong->chanName[dest]=curSubSong->chanName[src];
curSubSong->chanShortName[dest]=curSubSong->chanShortName[src];
curSubSong->chanShow[dest]=curSubSong->chanShow[src];
curSubSong->chanShowChanOsc[dest]=curSubSong->chanShowChanOsc[src];
curSubSong->chanCollapse[dest]=curSubSong->chanCollapse[src];
}
void DivEngine::swapChannels(int src, int dest) {
logV("swapping channel %d with %d",src,dest);
if (src==dest) {
logV("not swapping channels because it's the same channel!",src,dest);
logV("not swapping channels because it's the same channel!");
return;
}
@ -746,6 +769,16 @@ void DivEngine::checkAssetDir(std::vector<DivAssetDir>& dir, size_t entries) {
delete[] inAssetDir;
}
void DivEngine::copyChannelP(int src, int dest) {
if (src<0 || src>=chans) return;
if (dest<0 || dest>=chans) return;
BUSY_BEGIN;
saveLock.lock();
copyChannel(src,dest);
saveLock.unlock();
BUSY_END;
}
void DivEngine::swapChannelsP(int src, int dest) {
if (src<0 || src>=chans) return;
if (dest<0 || dest>=chans) return;

View file

@ -649,6 +649,7 @@ class DivEngine {
void exchangeWave(int one, int two);
void exchangeSample(int one, int two);
void copyChannel(int src, int dest);
void swapChannels(int src, int dest);
void stompChannel(int ch);
@ -1262,6 +1263,9 @@ class DivEngine {
// >=0: render specific sample
void renderSamplesP(int whichSample=-1);
// public copy channel
void copyChannelP(int src, int dest);
// public swap channels
void swapChannelsP(int src, int dest);

View file

@ -50,7 +50,7 @@ void FurnaceGUI::drawChannels() {
ImGui::TableNextColumn();
ImGui::Text(_("Osc"));
ImGui::TableNextColumn();
ImGui::Text(_("Swap"));
ImGui::Text(_("Drg"));
ImGui::TableNextColumn();
ImGui::Text(_("Name"));
for (int i=0; i<e->getTotalChannelCount(); i++) {
@ -79,14 +79,17 @@ void FurnaceGUI::drawChannels() {
ImGui::Button(ICON_FA_ARROWS "##ChanDrag");
ImGui::EndDragDropSource();
} else if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(_("%s #%d\n(drag to swap channels)"),e->getSystemName(e->sysOfChan[i]),e->dispatchChanOfChan[i]);
ImGui::SetTooltip(_("%s #%d\n(drag to swap channels)\n(shift+drag to copy channel contents)"),e->getSystemName(e->sysOfChan[i]),e->dispatchChanOfChan[i]);
}
if (ImGui::BeginDragDropTarget()) {
const ImGuiPayload* dragItem=ImGui::AcceptDragDropPayload("FUR_CHAN");
if (dragItem!=NULL) {
if (dragItem->IsDataType("FUR_CHAN")) {
if (chanToMove!=i && chanToMove>=0) {
e->swapChannelsP(chanToMove,i);
if (ImGui::IsKeyDown(ImGuiKey_LeftShift))
e->copyChannelP(chanToMove,i);
else
e->swapChannelsP(chanToMove,i);
MARK_MODIFIED;
}
chanToMove=-1;