| 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 <imgui.h> |
| 24 |
|
| 25 |
void FurnaceGUI::drawPatManager() { |
| 26 |
if (nextWindow==GUI_WINDOW_PAT_MANAGER) { |
| 27 |
patManagerOpen=true; |
| 28 |
ImGui::SetNextWindowFocus(); |
| 29 |
nextWindow=GUI_WINDOW_NOTHING; |
| 30 |
} |
| 31 |
if (!patManagerOpen) return; |
| 32 |
char id[1024]; |
| 33 |
unsigned char isUsed[DIV_MAX_PATTERNS]; |
| 34 |
bool isNull[DIV_MAX_PATTERNS]; |
| 35 |
if (ImGui::Begin("Pattern Manager",&patManagerOpen,globalWinFlags,_("Pattern Manager"))) { |
| 36 |
if (ImGui::Button(_("De-duplicate patterns"))) { |
| 37 |
e->lockEngine([this]() { |
| 38 |
e->curSubSong->optimizePatterns(); |
| 39 |
}); |
| 40 |
MARK_MODIFIED; |
| 41 |
} |
| 42 |
ImGui::SameLine(); |
| 43 |
if (ImGui::Button(_("Re-arrange patterns"))) { |
| 44 |
e->lockEngine([this]() { |
| 45 |
e->curSubSong->rearrangePatterns(); |
| 46 |
}); |
| 47 |
MARK_MODIFIED; |
| 48 |
} |
| 49 |
ImGui::SameLine(); |
| 50 |
if (ImGui::Button(_("Sort orders"))) { |
| 51 |
e->lockEngine([this]() { |
| 52 |
e->curSubSong->sortOrders(); |
| 53 |
}); |
| 54 |
MARK_MODIFIED; |
| 55 |
} |
| 56 |
ImGui::SameLine(); |
| 57 |
if (ImGui::Button(_("Make patterns unique"))) { |
| 58 |
e->lockEngine([this]() { |
| 59 |
e->curSubSong->makePatUnique(); |
| 60 |
}); |
| 61 |
MARK_MODIFIED; |
| 62 |
} |
| 63 |
|
| 64 |
if (ImGui::BeginTable("PatManTable",257,ImGuiTableFlags_ScrollX|ImGuiTableFlags_SizingFixedFit)) { |
| 65 |
ImGui::PushFont(patFont); |
| 66 |
|
| 67 |
for (int i=0; i<e->getTotalChannelCount(); i++) { |
| 68 |
ImGui::TableNextRow(); |
| 69 |
memset(isUsed,0,DIV_MAX_PATTERNS); |
| 70 |
memset(isNull,0,DIV_MAX_PATTERNS*sizeof(bool)); |
| 71 |
for (int j=0; j<e->curSubSong->ordersLen; j++) { |
| 72 |
isUsed[e->curSubSong->orders.ord[i][j]]++; |
| 73 |
} |
| 74 |
for (int j=0; j<DIV_MAX_PATTERNS; j++) { |
| 75 |
isNull[j]=(e->curSubSong->pat[i].data[j]==NULL); |
| 76 |
} |
| 77 |
ImGui::TableNextColumn(); |
| 78 |
ImGui::Text("%s",e->getChannelShortName(i)); |
| 79 |
|
| 80 |
ImGui::PushID(1000+i); |
| 81 |
for (int k=0; k<DIV_MAX_PATTERNS; k++) { |
| 82 |
ImGui::TableNextColumn(); |
| 83 |
|
| 84 |
snprintf(id,1023,"%.2X",k); |
| 85 |
if (isNull[k]) { |
| 86 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_NULL]); |
| 87 |
} else if (isUsed[k]>=e->curSubSong->ordersLen) { |
| 88 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_COMBO_BREAKER]); |
| 89 |
} else if (isUsed[k]>=0.7*(double)e->curSubSong->ordersLen) { |
| 90 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_EXTREMELY_OVERUSED]); |
| 91 |
} else if (isUsed[k]>=0.4*(double)e->curSubSong->ordersLen) { |
| 92 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_OVERUSED]); |
| 93 |
} else if (isUsed[k]) { |
| 94 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_USED]); |
| 95 |
} else { |
| 96 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_UNUSED]); |
| 97 |
} |
| 98 |
ImGui::Selectable(id,isUsed[k]); |
| 99 |
if (ImGui::IsItemHovered()) { |
| 100 |
ImGui::PushFont(mainFont); |
| 101 |
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_TEXT]); |
| 102 |
if (isNull[k]) { |
| 103 |
ImGui::SetTooltip(_("Pattern %.2X\n- not allocated"),k); |
| 104 |
} else { |
| 105 |
ImGui::SetTooltip(_("Pattern %.2X\n- use count: %d (%.0f%%)\n\nright-click to erase"),k,isUsed[k],100.0*(double)isUsed[k]/(double)e->curSubSong->ordersLen); |
| 106 |
} |
| 107 |
ImGui::PopStyleColor(); |
| 108 |
ImGui::PopFont(); |
| 109 |
} |
| 110 |
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { |
| 111 |
e->lockEngine([this,i,k]() { |
| 112 |
delete e->curSubSong->pat[i].data[k]; |
| 113 |
e->curSubSong->pat[i].data[k]=NULL; |
| 114 |
}); |
| 115 |
MARK_MODIFIED; |
| 116 |
} |
| 117 |
ImGui::PopStyleColor(); |
| 118 |
} |
| 119 |
ImGui::PopID(); |
| 120 |
} |
| 121 |
ImGui::PopFont(); |
| 122 |
|
| 123 |
ImGui::EndTable(); |
| 124 |
} |
| 125 |
} |
| 126 |
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PAT_MANAGER; |
| 127 |
ImGui::End(); |
| 128 |
} |