Debian Codegraph @

src/gui/sysManager.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 "misc/cpp/imgui_stdlib.h"
22 #include "IconsFontAwesome4.h"
23 #include <fmt/printf.h>
24 #include <imgui.h>
25
26 void FurnaceGUI::drawSysManager() {
27 if (nextWindow==GUI_WINDOW_SYS_MANAGER) {
28 sysManagerOpen=true;
29 ImGui::SetNextWindowFocus();
30 nextWindow=GUI_WINDOW_NOTHING;
31 }
32 if (!sysManagerOpen) return;
33 if (mobileUI) {
34 patWindowPos=(portrait?ImVec2(0.0f,(mobileMenuPos*-0.65*canvasH)):ImVec2((0.16*canvasH)+0.5*canvasW*mobileMenuPos,0.0f));
35 patWindowSize=(portrait?ImVec2(canvasW,canvasH-(0.16*canvasW)):ImVec2(canvasW-(0.16*canvasH),canvasH));
36 ImGui::SetNextWindowPos(patWindowPos);
37 ImGui::SetNextWindowSize(patWindowSize);
38 } else {
39 //ImGui::SetNextWindowSizeConstraints(ImVec2(440.0f*dpiScale,400.0f*dpiScale),ImVec2(canvasW,canvasH));
40 }
41 if (ImGui::Begin("Chip Manager",&sysManagerOpen,globalWinFlags,_("Chip Manager"))) {
42 ImGui::Checkbox(_("Preserve channel order"),&preserveChanPos);
43 ImGui::SameLine();
44 ImGui::Checkbox(_("Clone channel data"),&sysDupCloneChannels);
45 ImGui::SameLine();
46 ImGui::Checkbox(_("Clone at end"),&sysDupEnd);
47 if (ImGui::BeginTable("SystemList",3)) {
48 ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed);
49 ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch);
50 ImGui::TableSetupColumn("c3",ImGuiTableColumnFlags_WidthFixed);
51 ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
52 ImGui::TableNextColumn();
53 ImGui::TableNextColumn();
54 ImGui::Text(_("Name"));
55 ImGui::TableNextColumn();
56 ImGui::Text(_("Actions"));
57 for (unsigned char i=0; i<e->song.systemLen; i++) {
58 ImGui::PushID(i);
59 ImGui::TableNextRow();
60 ImGui::TableNextColumn();
61 if (ImGui::Button(ICON_FA_ARROWS)) {
62 }
63 if (ImGui::BeginDragDropSource()) {
64 sysToMove=i;
65 ImGui::SetDragDropPayload("FUR_SYS",NULL,0,ImGuiCond_Once);
66 ImGui::Button(ICON_FA_ARROWS "##SysDrag");
67 ImGui::EndDragDropSource();
68 } else if (ImGui::IsItemHovered()) {
69 ImGui::SetTooltip(_("(drag to swap chips)"));
70 }
71 if (ImGui::BeginDragDropTarget()) {
72 const ImGuiPayload* dragItem=ImGui::AcceptDragDropPayload("FUR_SYS");
73 if (dragItem!=NULL) {
74 if (dragItem->IsDataType("FUR_SYS")) {
75 if (sysToMove!=i && sysToMove>=0) {
76 e->swapSystem(sysToMove,i,preserveChanPos);
77 MARK_MODIFIED;
78 }
79 sysToMove=-1;
80 }
81 }
82 ImGui::EndDragDropTarget();
83 }
84 ImGui::TableNextColumn();
85 bool isNotCollapsed=true;
86 if (ImGui::TreeNode(fmt::sprintf("%d. %s##_SYSM%d",i+1,getSystemName(e->song.system[i]),i).c_str())) {
87 drawSysConf(i,i,e->song.system[i],e->song.systemFlags[i],true);
88 isNotCollapsed=false;
89 ImGui::TreePop();
90 }
91 if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary) && isNotCollapsed) {
92 if (e->song.system[i]!=DIV_SYSTEM_NULL) {
93 const DivSysDef* sysDef=e->getSystemDef(e->song.system[i]);
94 if (ImGui::BeginTooltip()) {
95 ImGui::Dummy(ImVec2(MIN(scrW*dpiScale,400.0f*dpiScale),0.0f));
96 ImGui::PushTextWrapPos(MIN(scrW*dpiScale,400.0f*dpiScale)); // arbitrary constant
97 ImGui::TextWrapped("%s",sysDef->description);
98 ImGui::Separator();
99 drawSystemChannelInfoText(sysDef);
100 drawSystemChannelInfo(sysDef);
101 ImGui::PopTextWrapPos();
102 ImGui::EndTooltip();
103 }
104 }
105 }
106 ImGui::TableNextColumn();
107 if (ImGui::Button(_("Clone##SysDup"))) {
108 if (!e->duplicateSystem(i,sysDupCloneChannels,sysDupEnd)) {
109 showError(fmt::sprintf(_("cannot clone chip! (%s)"),e->getLastError()));
110 } else {
111 if (e->song.autoSystem) {
112 autoDetectSystem();
113 updateWindowTitle();
114 }
115 updateROMExportAvail();
116 MARK_MODIFIED;
117 }
118 }
119 ImGui::SameLine();
120 ImGui::Button(_("Change##SysChange"));
121 if (ImGui::BeginPopupContextItem("SysPickerC",ImGuiPopupFlags_MouseButtonLeft)) {
122 DivSystem picked=systemPicker(false);
123 if (picked!=DIV_SYSTEM_NULL) {
124 if (e->changeSystem(i,picked,preserveChanPos)) {
125 MARK_MODIFIED;
126 if (e->song.autoSystem) {
127 autoDetectSystem();
128 }
129 updateWindowTitle();
130 updateROMExportAvail();
131 } else {
132 showError(fmt::sprintf(_("cannot change chip! (%s)"),e->getLastError()));
133 }
134 ImGui::CloseCurrentPopup();
135 }
136 if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
137 ImGui::CloseCurrentPopup();
138 }
139 ImGui::EndPopup();
140 }
141 ImGui::SameLine();
142 ImGui::BeginDisabled(e->song.systemLen<=1);
143 pushDestColor();
144 if (ImGui::Button(ICON_FA_TIMES "##SysRemove")) {
145 sysToDelete=i;
146 showWarning(_("Are you sure you want to remove this chip?"),GUI_WARN_SYSTEM_DEL);
147 }
148 popDestColor();
149 if (ImGui::IsItemHovered()) {
150 ImGui::SetTooltip(_("Remove"));
151 }
152 ImGui::EndDisabled();
153 ImGui::PopID();
154 }
155 if (e->song.systemLen<DIV_MAX_CHIPS) {
156 ImGui::TableNextRow();
157 ImGui::TableNextColumn();
158 ImGui::TableNextColumn();
159 ImGui::Button(ICON_FA_PLUS "##SysAdd");
160 if (ImGui::BeginPopupContextItem("SysPickerA",ImGuiPopupFlags_MouseButtonLeft)) {
161 DivSystem picked=systemPicker(false);
162 if (picked!=DIV_SYSTEM_NULL) {
163 if (!e->addSystem(picked)) {
164 showError(fmt::sprintf(_("cannot add chip! (%s)"),e->getLastError()));
165 } else {
166 MARK_MODIFIED;
167 }
168 if (e->song.autoSystem) {
169 autoDetectSystem();
170 }
171 updateWindowTitle();
172 updateROMExportAvail();
173 ImGui::CloseCurrentPopup();
174 }
175 if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
176 ImGui::CloseCurrentPopup();
177 }
178 ImGui::EndPopup();
179 }
180 }
181 ImGui::EndTable();
182 }
183 }
184 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_SYS_MANAGER;
185 ImGui::End();
186 }