Debian Codegraph @

src/gui/grooves.cpp

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "gui.h"
21 #include "imgui.h"
22 #include "misc/cpp/imgui_stdlib.h"
23 #include "IconsFontAwesome4.h"
24 #include <fmt/printf.h>
25 #include "intConst.h"
26
27 void FurnaceGUI::drawGrooves() {
28 if (nextWindow==GUI_WINDOW_GROOVES) {
29 groovesOpen=true;
30 ImGui::SetNextWindowFocus();
31 nextWindow=GUI_WINDOW_NOTHING;
32 }
33 if (!groovesOpen) return;
34 ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(canvasW,canvasH));
35 if (ImGui::Begin("Grooves",&groovesOpen,globalWinFlags,_("Grooves"))) {
36 int delGroove=-1;
37
38 ImGui::Text(_("use effect 09xx to select a groove pattern."));
39 if (!e->song.grooves.empty()) if (ImGui::BeginTable("GrooveList",3,ImGuiTableFlags_Borders)) {
40 ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
41 ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch);
42 ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthFixed);
43
44 ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
45 ImGui::TableNextColumn();
46 ImGui::Text("#");
47 ImGui::TableNextColumn();
48 ImGui::Text(_("pattern"));
49 ImGui::TableNextColumn();
50 // ImGui::Text("remove"); removed because the text clips from the fixed width
51
52 int index=0;
53 for (DivGroovePattern& i: e->song.grooves) {
54 ImGui::TableNextRow();
55 ImGui::TableNextColumn();
56 ImGui::PushFont(patFont);
57 ImGui::AlignTextToFramePadding();
58 ImGui::Text("%.2X",index);
59 ImGui::PopFont();
60
61 ImGui::TableNextColumn();
62
63 String grooveStr;
64
65 if (curGroove==index) {
66 int intVersion[256];
67 unsigned char intVersionLen=i.len;
68 unsigned char ignoredLoop=0;
69 unsigned char ignoredRel=0;
70 memset(intVersion,0,sizeof(int));
71 for (int j=0; j<16; j++) {
72 intVersion[j]=i.val[j];
73 }
74 if (intVersionLen>16) intVersionLen=16;
75 grooveStr=fmt::sprintf("##_GRI%d",index);
76 bool wantedFocus=wantGrooveListFocus;
77 if (wantGrooveListFocus) {
78 wantGrooveListFocus=false;
79 ImGui::SetItemDefaultFocus();
80 ImGui::SetKeyboardFocusHere();
81 }
82 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
83 ImGui::AlignTextToFramePadding();
84 if (ImGui::InputText(grooveStr.c_str(),&grooveListString)) {
85 decodeMMLStr(grooveListString,intVersion,intVersionLen,ignoredLoop,1,255,ignoredRel);
86 if (intVersionLen<1) {
87 intVersionLen=1;
88 intVersion[0]=6;
89 }
90 if (intVersionLen>16) intVersionLen=16;
91 e->lockEngine([&i,intVersion,intVersionLen]() {
92 i.len=intVersionLen;
93 for (int j=0; j<16; j++) {
94 i.val[j]=intVersion[j];
95 }
96 });
97 MARK_MODIFIED;
98 }
99 if (!ImGui::IsItemActive() && !wantedFocus) {
100 curGroove=-1;
101 //encodeMMLStr(grooveListString,intVersion,intVersionLen,-1,-1,false);
102 }
103 } else {
104 String grooveStr;
105
106 for (int j=0; j<i.len; j++) {
107 if (j>0) {
108 grooveStr+=' ';
109 }
110 grooveStr+=fmt::sprintf("%d",(int)i.val[j]);
111 }
112
113 size_t groovePrevLen=grooveStr.size();
114
115 grooveStr+=fmt::sprintf("##_GR%d",index);
116
117 if (ImGui::Selectable(grooveStr.c_str(),false)) {
118 curGroove=index;
119 grooveListString=grooveStr.substr(0,groovePrevLen);
120 wantGrooveListFocus=true;
121 }
122 }
123
124 ImGui::TableNextColumn();
125 pushDestColor();
126 String grooveID=fmt::sprintf(ICON_FA_TIMES "##GRR%d",index);
127 if (ImGui::Button(grooveID.c_str())) {
128 delGroove=index;
129 }
130 popDestColor();
131 if (ImGui::IsItemHovered()) {
132 ImGui::SetTooltip(_("remove"));
133 }
134
135 index++;
136 }
137
138 ImGui::EndTable();
139 }
140
141 if (delGroove>=0) {
142 e->lockEngine([this,delGroove]() {
143 e->song.grooves.erase(e->song.grooves.begin()+delGroove);
144 });
145 MARK_MODIFIED;
146 }
147
148 if (ImGui::Button(ICON_FA_PLUS "##AddGroove")) {
149 e->lockEngine([this]() {
150 e->song.grooves.push_back(DivGroovePattern());
151 });
152 MARK_MODIFIED;
153 }
154 }
155 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) {
156 curWindow=GUI_WINDOW_GROOVES;
157 } else {
158 curGroove=-1;
159 }
160 ImGui::End();
161 }