GUI: pattern manager, part 1

This commit is contained in:
tildearrow 2022-08-16 04:19:00 -05:00
parent d1c5a4725b
commit 8a3358ba5a
4 changed files with 96 additions and 1 deletions

View file

@ -200,6 +200,13 @@ enum FurnaceGUIColors {
GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY,
GUI_COLOR_PATTERN_EFFECT_MISC,
GUI_COLOR_PAT_MANAGER_NULL,
GUI_COLOR_PAT_MANAGER_USED,
GUI_COLOR_PAT_MANAGER_OVERUSED,
GUI_COLOR_PAT_MANAGER_EXTREMELY_OVERUSED,
GUI_COLOR_PAT_MANAGER_COMBO_BREAKER,
GUI_COLOR_PAT_MANAGER_UNUSED,
GUI_COLOR_PIANO_BACKGROUND,
GUI_COLOR_PIANO_KEY_BOTTOM,
GUI_COLOR_PIANO_KEY_TOP,

View file

@ -812,6 +812,13 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={
D(GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY,"",ImVec4(0.0f,1.0f,0.5f,1.0f)),
D(GUI_COLOR_PATTERN_EFFECT_MISC,"",ImVec4(0.3f,0.3f,1.0f,1.0f)),
D(GUI_COLOR_PAT_MANAGER_NULL,"",ImVec4(0.15f,0.15f,0.15f,1.0f)),
D(GUI_COLOR_PAT_MANAGER_USED,"",ImVec4(0.15f,1.0f,0.15f,1.0f)),
D(GUI_COLOR_PAT_MANAGER_OVERUSED,"",ImVec4(1.0f,1.0f,0.15f,1.0f)),
D(GUI_COLOR_PAT_MANAGER_EXTREMELY_OVERUSED,"",ImVec4(1.0f,0.5f,0.15f,1.0f)),
D(GUI_COLOR_PAT_MANAGER_COMBO_BREAKER,"",ImVec4(1.0f,0.15f,1.0f,1.0f)),
D(GUI_COLOR_PAT_MANAGER_UNUSED,"",ImVec4(1.0f,0.15f,0.15f,1.0f)),
D(GUI_COLOR_PIANO_BACKGROUND,"",ImVec4(0.0f,0.0f,0.0f,1.0f)),
D(GUI_COLOR_PIANO_KEY_BOTTOM,"",ImVec4(1.0f,1.0f,1.0f,1.0f)),
D(GUI_COLOR_PIANO_KEY_TOP,"",ImVec4(0.0f,0.0f,0.0f,1.0f)),

View file

@ -29,8 +29,80 @@ void FurnaceGUI::drawPatManager() {
nextWindow=GUI_WINDOW_NOTHING;
}
if (!patManagerOpen) return;
char id[1024];
unsigned char isUsed[256];
bool isNull[256];
if (ImGui::Begin("Pattern Manager",&patManagerOpen,globalWinFlags)) {
ImGui::Text("Hello World!");
ImGui::Text("Global Tasks");
if (ImGui::Button("De-duplicate patterns")) {
e->lockEngine([this]() {
e->curSubSong->optimizePatterns();
});
}
ImGui::SameLine();
if (ImGui::Button("Re-arrange patterns")) {
e->lockEngine([this]() {
e->curSubSong->rearrangePatterns();
});
}
for (int i=0; i<e->getTotalChannelCount(); i++) {
memset(isUsed,0,256);
memset(isNull,0,256*sizeof(bool));
for (int j=0; j<e->curSubSong->ordersLen; j++) {
isUsed[e->curSubSong->orders.ord[i][j]]++;
}
for (int j=0; j<256; j++) {
isNull[j]=(e->curSubSong->pat[i].data[j]==NULL);
}
ImGui::Text("%d. %s",i+1,e->getChannelName(i));
ImGui::PushID(1000+i);
ImGui::PushFont(patFont);
if (ImGui::BeginTable("PatManTable",32)) {
for (int k=0; k<256; k++) {
if ((k&31)==0) ImGui::TableNextRow();
ImGui::TableNextColumn();
snprintf(id,1023,"%.2X",k);
if (isNull[k]) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_NULL]);
} else if (isUsed[k]>=e->curSubSong->ordersLen) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_COMBO_BREAKER]);
} else if (isUsed[k]>=0.7*(double)e->curSubSong->ordersLen) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_EXTREMELY_OVERUSED]);
} else if (isUsed[k]>=0.4*(double)e->curSubSong->ordersLen) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_OVERUSED]);
} else if (isUsed[k]) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_USED]);
} else {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PAT_MANAGER_UNUSED]);
}
ImGui::Selectable(id,isUsed[k]);
if (ImGui::IsItemHovered()) {
ImGui::PushFont(mainFont);
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_TEXT]);
if (isNull[k]) {
ImGui::SetTooltip("Pattern %.2X\n- not allocated",k);
} else {
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);
}
ImGui::PopStyleColor();
ImGui::PopFont();
}
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
e->lockEngine([this,i,k]() {
delete e->curSubSong->pat[i].data[k];
e->curSubSong->pat[i].data[k]=NULL;
});
}
ImGui::PopStyleColor();
}
ImGui::EndTable();
}
ImGui::PopFont();
ImGui::PopID();
}
}
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PAT_MANAGER;
ImGui::End();

View file

@ -1583,6 +1583,15 @@ void FurnaceGUI::drawSettings() {
UI_COLOR_CONFIG(GUI_COLOR_EE_VALUE,"External command output");
ImGui::TreePop();
}
if (ImGui::TreeNode("Pattern Manager")) {
UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_NULL,"Unallocated");
UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_UNUSED,"Unused");
UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_USED,"Used");
UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_OVERUSED,"Overused");
UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_EXTREMELY_OVERUSED,"Really overused");
UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_COMBO_BREAKER,"Combo Breaker");
ImGui::TreePop();
}
if (ImGui::TreeNode("Piano")) {
UI_COLOR_CONFIG(GUI_COLOR_PIANO_BACKGROUND,"Background");
UI_COLOR_CONFIG(GUI_COLOR_PIANO_KEY_TOP,"Upper key");