From de6b3ac8d1c6f9d13b8494625b6d3aab878b7da1 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sun, 4 Mar 2012 15:35:20 +0000 Subject: [PATCH] Toolbars now automatically switch to anim/layers when required git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1911 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 83 ++++++++------------------------- src/engine.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++- src/engine.h | 18 ++++++++ src/init.c | 25 ---------- src/init.h | 6 --- src/main.c | 2 + 6 files changed, 161 insertions(+), 97 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 368876fa..daa8252c 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -214,6 +214,7 @@ void Button_Undo(void) Set_palette(Main_palette); Compute_optimal_menu_colors(Main_palette); + Check_menu_mode(); Display_all_screen(); Unselect_button(BUTTON_UNDO); Draw_menu_button(BUTTON_MAGNIFIER,Main_magnifier_mode); @@ -228,6 +229,7 @@ void Button_Redo(void) Set_palette(Main_palette); Compute_optimal_menu_colors(Main_palette); + Check_menu_mode(); Display_all_screen(); Unselect_button(BUTTON_UNDO); Draw_menu_button(BUTTON_MAGNIFIER,Main_magnifier_mode); @@ -448,64 +450,6 @@ void Button_Hide_menu(void) Display_cursor(); } - -void Set_bar_visibility(word bar, byte visible) -{ - if (!visible && Menu_bars[bar].Visible) - { - // Hide it - Menu_bars[bar].Visible=0; - - Compute_menu_offsets(); - - if (Main_magnifier_mode) - { - Compute_magnifier_data(); - } - - // On repositionne le décalage de l'image pour qu'il n'y ait pas d'in- - // -cohérences lorsqu'on sortira du mode Loupe. - if (Main_offset_Y+Screen_height>Main_image_height) - { - if (Screen_height>Main_image_height) - Main_offset_Y=0; - else - Main_offset_Y=Main_image_height-Screen_height; - } - // On fait pareil pour le brouillon - if (Spare_offset_Y+Screen_height>Spare_image_height) - { - if (Screen_height>Spare_image_height) - Spare_offset_Y=0; - else - Spare_offset_Y=Spare_image_height-Screen_height; - } - - Compute_magnifier_data(); - if (Main_magnifier_mode) - Position_screen_according_to_zoom(); - Compute_limits(); - Compute_paintbrush_coordinates(); - Display_menu(); - Display_all_screen(); - } - else if (visible && !Menu_bars[bar].Visible) - { - // Show it - Menu_bars[bar].Visible = 1; - - Compute_menu_offsets(); - Compute_magnifier_data(); - if (Main_magnifier_mode) - Position_screen_according_to_zoom(); - Compute_limits(); - Compute_paintbrush_coordinates(); - Display_menu(); - if (Main_magnifier_mode) - Display_all_screen(); - } -} - void Button_Toggle_toolbar(void) { T_Dropdown_button dropdown; @@ -546,12 +490,12 @@ void Button_Toggle_toolbar(void) switch (item->Number) { case 0: // tools - Set_bar_visibility(MENUBAR_TOOLS, !Menu_bars[MENUBAR_TOOLS].Visible); + Set_bar_visibility(MENUBAR_TOOLS, !Menu_bars[MENUBAR_TOOLS].Visible, 0); break; case 1: // layers if (Menu_bars[MENUBAR_ANIMATION].Visible && !Menu_bars[MENUBAR_LAYERS].Visible) - Set_bar_visibility(MENUBAR_ANIMATION, 0); - Set_bar_visibility(MENUBAR_LAYERS, !Menu_bars[MENUBAR_LAYERS].Visible); + Set_bar_visibility(MENUBAR_ANIMATION, 0, 0); + Set_bar_visibility(MENUBAR_LAYERS, !Menu_bars[MENUBAR_LAYERS].Visible, 0); if (Main_backups->Pages->Image_mode == IMAGE_MODE_ANIMATION) { @@ -562,8 +506,8 @@ void Button_Toggle_toolbar(void) break; case 2: // anim if (Menu_bars[MENUBAR_LAYERS].Visible && !Menu_bars[MENUBAR_ANIMATION].Visible) - Set_bar_visibility(MENUBAR_LAYERS, 0); - Set_bar_visibility(MENUBAR_ANIMATION, !Menu_bars[MENUBAR_ANIMATION].Visible); + Set_bar_visibility(MENUBAR_LAYERS, 0, 0); + Set_bar_visibility(MENUBAR_ANIMATION, !Menu_bars[MENUBAR_ANIMATION].Visible, 0); if (Main_backups->Pages->Image_mode == IMAGE_MODE_LAYERED) { @@ -574,6 +518,9 @@ void Button_Toggle_toolbar(void) break; } + // redraw image and menu + Display_menu(); + Display_all_screen(); } // Closing @@ -603,14 +550,17 @@ void Button_Toggle_all_toolbars(void) // At least one is visible: Hide all Last_visibility=current_visibility; for (i=MENUBAR_STATUS+1;i=0; i--) + { + Menu_bars[i].Top = offset; + if(Menu_bars[i].Visible) + { + offset += Menu_bars[i].Height; + Menu_height += Menu_bars[i].Height; + } + } + // Update global menu coordinates + Menu_Y = Screen_height - Menu_height * Menu_factor_Y; +} + +/// +/// Shows or hides a tolbar from the menu. +/// If with_redraw is set to zero, the caller should +/// redraw itself using Display_menu() and Display_all_screen(). +void Set_bar_visibility(word bar, int visible, int with_redraw) +{ + if (!visible && Menu_bars[bar].Visible) + { + // Hide it + Menu_bars[bar].Visible=0; + + Compute_menu_offsets(); + + if (Main_magnifier_mode) + { + Compute_magnifier_data(); + } + + // On repositionne le décalage de l'image pour qu'il n'y ait pas d'in- + // -cohérences lorsqu'on sortira du mode Loupe. + if (Main_offset_Y+Screen_height>Main_image_height) + { + if (Screen_height>Main_image_height) + Main_offset_Y=0; + else + Main_offset_Y=Main_image_height-Screen_height; + } + // On fait pareil pour le brouillon + if (Spare_offset_Y+Screen_height>Spare_image_height) + { + if (Screen_height>Spare_image_height) + Spare_offset_Y=0; + else + Spare_offset_Y=Spare_image_height-Screen_height; + } + + Compute_magnifier_data(); + if (Main_magnifier_mode) + Position_screen_according_to_zoom(); + Compute_limits(); + Compute_paintbrush_coordinates(); + if (with_redraw) + { + Display_menu(); + Display_all_screen(); + } + } + else if (visible && !Menu_bars[bar].Visible) + { + // Show it + Menu_bars[bar].Visible = 1; + + Compute_menu_offsets(); + Compute_magnifier_data(); + if (Main_magnifier_mode) + Position_screen_according_to_zoom(); + Compute_limits(); + Compute_paintbrush_coordinates(); + if (with_redraw) + { + Display_menu(); + if (Main_magnifier_mode) + Display_all_screen(); + } + } +} + +/// +/// Checks if the current menu toolbars suit the current image type : +/// layered vs anim. If they don't fit, swap the toolbars and return 1: +/// The caller is then responsible for refreshing the screen by calling +/// Display_menu() and Display_all_screen() +int Check_menu_mode(void) +{ + if (Main_backups->Pages->Image_mode == IMAGE_MODE_ANIMATION + && Main_backups->Pages->Nb_layers>1 ) + { + if (Menu_bars[MENUBAR_LAYERS].Visible) + { + Set_bar_visibility(MENUBAR_LAYERS, 0, 0); + Set_bar_visibility(MENUBAR_ANIMATION, 1, 0); + return 1; + } + } + else if (Main_backups->Pages->Image_mode != IMAGE_MODE_ANIMATION + && Main_backups->Pages->Nb_layers>1 ) + { + if (Menu_bars[MENUBAR_ANIMATION].Visible) + { + Set_bar_visibility(MENUBAR_ANIMATION, 0, 0); + Set_bar_visibility(MENUBAR_LAYERS, 1, 0); + return 1; + } + } + return 0; +} diff --git a/src/engine.h b/src/engine.h index fb577db2..110bc98b 100644 --- a/src/engine.h +++ b/src/engine.h @@ -120,4 +120,22 @@ void Status_print_palette_color(byte color); /// though the mouse still works. void Delay_with_active_mouse(int delay); +/// +/// Based on which toolbars are visible, updates their offsets and +/// computes ::Menu_height and ::Menu_Y +void Compute_menu_offsets(void); + +/// +/// Shows or hides a tolbar from the menu. +/// If with_redraw is set to zero, the caller should +/// redraw itself using Display_menu() and Display_all_screen(). +void Set_bar_visibility(word bar, int visible, int with_redraw); + +/// +/// Checks if the current menu toolbars suit the current image type : +/// layered vs anim. If they don't fit, swap the toolbars and return 1: +/// The caller is then responsible for refreshing the screen by calling +/// Display_menu() and Display_all_screen() +int Check_menu_mode(void); + #endif diff --git a/src/init.c b/src/init.c index d68af14d..9fcdd3fa 100644 --- a/src/init.c +++ b/src/init.c @@ -84,7 +84,6 @@ #include "windows.h" #include "layers.h" #include "special.h" -#include "buttons.h" char Gui_loading_error_message[512]; @@ -2875,30 +2874,6 @@ void Set_current_skin(const char *skinfile, T_Gui_skin *gfx) } } -/// -/// Based on which toolbars are visible, updates their offsets and -/// computes ::Menu_height and ::Menu_Y -void Compute_menu_offsets(void) -{ - int i; - int offset; - - // Recompute all offsets - offset=0; - Menu_height=0; - for (i = MENUBAR_COUNT-1; i >=0; i--) - { - Menu_bars[i].Top = offset; - if(Menu_bars[i].Visible) - { - offset += Menu_bars[i].Height; - Menu_height += Menu_bars[i].Height; - } - } - // Update global menu coordinates - Menu_Y = Screen_height - Menu_height * Menu_factor_Y; -} - void Init_paintbrush(int index, int width, int height, byte shape, const char * bitmap) { if (bitmap!=NULL) diff --git a/src/init.h b/src/init.h index 3f64ae7a..14714cac 100644 --- a/src/init.h +++ b/src/init.h @@ -48,9 +48,3 @@ extern char Gui_loading_error_message[512]; /// If an error is encountered, it frees what needs it, prints an error message /// in ::Gui_loading_error_message, and returns NULL. byte * Load_font(const char * font_name); - -/// -/// Based on which toolbars are visible, updates their offsets and -/// computes ::Menu_height and ::Menu_Y -void Compute_menu_offsets(void); - diff --git a/src/main.c b/src/main.c index 2b765e0e..3ba824c0 100644 --- a/src/main.c +++ b/src/main.c @@ -817,6 +817,7 @@ int Init_program(int argc,char * argv[]) // Some files were loaded from last crash-exit. // Do not load files from command-line, nor show splash screen. Compute_optimal_menu_colors(Main_palette); + Check_menu_mode(); Display_all_screen(); Display_menu(); Display_cursor(); @@ -868,6 +869,7 @@ int Init_program(int argc,char * argv[]) Hide_cursor(); Compute_optimal_menu_colors(Main_palette); + Check_menu_mode(); Display_all_screen(); Display_menu(); Display_cursor();