2022-08-16 04:42:17 -04:00
/**
* Furnace Tracker - multi - system chiptune tracker
2024-01-16 21:26:57 -05:00
* Copyright ( C ) 2021 - 2024 tildearrow and contributors
2022-08-16 04:42:17 -04:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
*/
# include "gui.h"
# include "misc/cpp/imgui_stdlib.h"
# include "IconsFontAwesome4.h"
# include <imgui.h>
void FurnaceGUI : : drawPatManager ( ) {
if ( nextWindow = = GUI_WINDOW_PAT_MANAGER ) {
patManagerOpen = true ;
ImGui : : SetNextWindowFocus ( ) ;
nextWindow = GUI_WINDOW_NOTHING ;
}
if ( ! patManagerOpen ) return ;
2022-08-16 05:19:00 -04:00
char id [ 1024 ] ;
2022-12-09 00:30:27 -05:00
unsigned char isUsed [ DIV_MAX_PATTERNS ] ;
bool isNull [ DIV_MAX_PATTERNS ] ;
2024-05-27 18:53:46 -04:00
if ( ImGui : : Begin ( " Pattern Manager " , & patManagerOpen , globalWinFlags , _ ( " Pattern Manager " ) ) ) {
2024-05-26 20:31:17 -04:00
if ( ImGui : : Button ( _ ( " De-duplicate patterns " ) ) ) {
2022-08-16 05:19:00 -04:00
e - > lockEngine ( [ this ] ( ) {
e - > curSubSong - > optimizePatterns ( ) ;
} ) ;
2023-09-06 19:26:58 -04:00
MARK_MODIFIED ;
2022-08-16 05:19:00 -04:00
}
ImGui : : SameLine ( ) ;
2024-05-26 20:31:17 -04:00
if ( ImGui : : Button ( _ ( " Re-arrange patterns " ) ) ) {
2022-08-16 05:19:00 -04:00
e - > lockEngine ( [ this ] ( ) {
e - > curSubSong - > rearrangePatterns ( ) ;
} ) ;
2023-09-06 19:26:58 -04:00
MARK_MODIFIED ;
2022-08-16 05:19:00 -04:00
}
2024-02-21 18:05:39 -05:00
ImGui : : SameLine ( ) ;
2024-05-26 20:31:17 -04:00
if ( ImGui : : Button ( _ ( " Sort orders " ) ) ) {
2024-02-21 18:05:39 -05:00
e - > lockEngine ( [ this ] ( ) {
e - > curSubSong - > sortOrders ( ) ;
} ) ;
MARK_MODIFIED ;
}
ImGui : : SameLine ( ) ;
2024-05-26 20:31:17 -04:00
if ( ImGui : : Button ( _ ( " Make patterns unique " ) ) ) {
2024-02-21 18:05:39 -05:00
e - > lockEngine ( [ this ] ( ) {
e - > curSubSong - > makePatUnique ( ) ;
} ) ;
MARK_MODIFIED ;
}
2022-08-16 05:19:00 -04:00
2022-08-25 19:13:46 -04:00
if ( ImGui : : BeginTable ( " PatManTable " , 257 , ImGuiTableFlags_ScrollX | ImGuiTableFlags_SizingFixedFit ) ) {
2022-08-16 05:19:00 -04:00
ImGui : : PushFont ( patFont ) ;
2022-08-25 19:13:46 -04:00
for ( int i = 0 ; i < e - > getTotalChannelCount ( ) ; i + + ) {
ImGui : : TableNextRow ( ) ;
2022-12-09 00:30:27 -05:00
memset ( isUsed , 0 , DIV_MAX_PATTERNS ) ;
memset ( isNull , 0 , DIV_MAX_PATTERNS * sizeof ( bool ) ) ;
2022-08-25 19:13:46 -04:00
for ( int j = 0 ; j < e - > curSubSong - > ordersLen ; j + + ) {
isUsed [ e - > curSubSong - > orders . ord [ i ] [ j ] ] + + ;
}
2022-12-09 00:30:27 -05:00
for ( int j = 0 ; j < DIV_MAX_PATTERNS ; j + + ) {
2022-08-25 19:13:46 -04:00
isNull [ j ] = ( e - > curSubSong - > pat [ i ] . data [ j ] = = NULL ) ;
}
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " %s " , e - > getChannelShortName ( i ) ) ;
ImGui : : PushID ( 1000 + i ) ;
2022-12-09 00:30:27 -05:00
for ( int k = 0 ; k < DIV_MAX_PATTERNS ; k + + ) {
2022-08-16 05:19:00 -04:00
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 ] ) {
2024-05-26 20:31:17 -04:00
ImGui : : SetTooltip ( _ ( " Pattern %.2X \n - not allocated " ) , k ) ;
2022-08-16 05:19:00 -04:00
} else {
2024-05-26 20:31:17 -04:00
ImGui : : SetTooltip ( _ ( " Pattern %.2X \n - use count: %d (%.0f%%) \n \n right-click to erase " ) , k , isUsed [ k ] , 100.0 * ( double ) isUsed [ k ] / ( double ) e - > curSubSong - > ordersLen ) ;
2022-08-16 05:19:00 -04:00
}
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 ;
} ) ;
2023-09-06 19:26:58 -04:00
MARK_MODIFIED ;
2022-08-16 05:19:00 -04:00
}
ImGui : : PopStyleColor ( ) ;
}
2022-08-25 19:13:46 -04:00
ImGui : : PopID ( ) ;
2022-08-16 05:19:00 -04:00
}
ImGui : : PopFont ( ) ;
2022-08-25 19:13:46 -04:00
ImGui : : EndTable ( ) ;
2022-08-16 05:19:00 -04:00
}
2022-08-16 04:42:17 -04:00
}
if ( ImGui : : IsWindowFocused ( ImGuiFocusedFlags_ChildWindows ) ) curWindow = GUI_WINDOW_PAT_MANAGER ;
ImGui : : End ( ) ;
}