From 4b008f4b41c884461fe514f2c3020b42a7a3f985 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 7 Oct 2023 20:35:25 -0500 Subject: [PATCH] GUI: channel pair hints, part 1 very ugly --- src/engine/engine.cpp | 7 +++ src/engine/engine.h | 5 +++ src/gui/pattern.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 435cb54dd9..353ba71edc 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1418,6 +1418,11 @@ void* DivEngine::getDispatchChanState(int ch) { return disCont[dispatchOfChan[ch]].dispatch->getChanState(dispatchChanOfChan[ch]); } +DivChannelPair DivEngine::getChanPaired(int ch) { + if (ch<0 || ch>=chans) return DivChannelPair(); + return disCont[dispatchOfChan[ch]].dispatch->getPaired(dispatchChanOfChan[ch]); +} + unsigned char* DivEngine::getRegisterPool(int sys, int& size, int& depth) { if (sys<0 || sys>=song.systemLen) return NULL; if (disCont[sys].dispatch==NULL) return NULL; @@ -1912,11 +1917,13 @@ void DivEngine::recalcChans() { memset(isInsTypePossible,0,DIV_INS_MAX*sizeof(bool)); for (int i=0; igetTotalChannelCount(); int displayChans=0; + float chanHeadBottom=0.0f; const DivPattern* patCache[DIV_MAX_CHANS]; for (int i=0; icurSubSong->chanShow[i]) displayChans++; @@ -998,6 +999,7 @@ void FurnaceGUI::drawPattern() { } } } + chanHeadBottom=ImGui::GetCursorScreenPos().y; } ImGui::TableNextColumn(); lastPatternWidth=ImGui::GetCursorPosX()-lpwStart+ImGui::GetStyle().ScrollbarSize; @@ -1135,6 +1137,105 @@ void FurnaceGUI::drawPattern() { ImGui::EndTable(); } + if (patChannelPairs && e->isRunning()) { // pair hints + ImDrawList* dl=ImGui::GetWindowDrawList(); + float pos=0.0f; + float posCenter=0.0f; + float posMin=FLT_MAX; + float posMax=-FLT_MAX; + float posY=chanHeadBottom; + ImVec2 textSize; + + for (int i=0; icurSubSong->chanShow[i]) { + continue; + } + + DivChannelPair pairs=e->getChanPaired(i); + for (int j=0; j<8; j++) { + if (pairs.pairs[j]==-1) continue; + int pairCh=e->dispatchFirstChan[i]+pairs.pairs[j]; + if (!e->curSubSong->chanShow[pairCh]) { + continue; + } + isPaired=true; + break; + } + + if (!isPaired) continue; + + pos=(patChanX[i+1]+patChanX[i])*0.5; + posCenter=pos; + posMin=pos; + posMax=pos; + numPairs++; + + if (pairs.label==NULL) { + textSize=ImGui::CalcTextSize("???"); + } else { + textSize=ImGui::CalcTextSize(pairs.label); + } + dl->AddLine( + ImVec2(pos,posY), + ImVec2(pos,posY+textSize.y), + 0xffffffff, + dpiScale + ); + + for (int j=0; j<8; j++) { + if (pairs.pairs[j]==-1) continue; + int pairCh=e->dispatchFirstChan[i]+pairs.pairs[j]; + if (!e->curSubSong->chanShow[pairCh]) { + continue; + } + + pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5; + posCenter+=pos; + numPairs++; + if (posposMax) posMax=pos; + dl->AddLine( + ImVec2(pos,posY), + ImVec2(pos,posY+textSize.y), + 0xffffffff, + dpiScale + ); + } + + posCenter/=numPairs; + + if (pairs.label==NULL) { + dl->AddLine( + ImVec2(posMin,posY+textSize.y), + ImVec2(posMax,posY+textSize.y), + 0xffffffff, + dpiScale + ); + } else { + dl->AddLine( + ImVec2(posMin,posY+textSize.y), + ImVec2(posCenter-textSize.x*0.5,posY+textSize.y), + 0xffffffff, + dpiScale + ); + dl->AddLine( + ImVec2(posCenter+textSize.x*0.5,posY+textSize.y), + ImVec2(posMax,posY+textSize.y), + 0xffffffff, + dpiScale + ); + + dl->AddText( + ImVec2(posCenter-textSize.x*0.5,posY+textSize.y*0.5), + 0xffffffff, + pairs.label + ); + } + } + } + if (fancyPattern) { // visualizer e->getCommandStream(cmdStream); ImDrawList* dl=ImGui::GetWindowDrawList();