diff --git a/const.h b/const.h index 0adad495..4573245e 100644 --- a/const.h +++ b/const.h @@ -431,12 +431,6 @@ enum SPECIAL_ACTIONS SPECIAL_LAYER7_TOGGLE, SPECIAL_LAYER8_SELECT, SPECIAL_LAYER8_TOGGLE, - SPECIAL_LAYER_ADD, - SPECIAL_LAYER_DELETE, - SPECIAL_LAYER_MERGE, - SPECIAL_LAYER_SWAP_UP, - SPECIAL_LAYER_SWAP_DOWN, - SPECIAL_LAYER_MENU, NB_SPECIAL_SHORTCUTS ///< Number of special shortcuts }; diff --git a/engine.c b/engine.c index 705c742c..0c459ccb 100644 --- a/engine.c +++ b/engine.c @@ -39,6 +39,7 @@ #include "input.h" #include "engine.h" #include "pages.h" +#include "layers.h" // we need this as global @@ -1066,119 +1067,6 @@ void Main_handler(void) Layer_activate((key_index-SPECIAL_LAYER1_TOGGLE)/2, RIGHT_SIDE); action++; break; - case SPECIAL_LAYER_ADD: - // Backup with unchanged layers - Backup_layers(0); - if (!Add_layer(Main_backups,Main_current_layer+1)) - { - Update_depth_buffer(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); - } - action++; - break; - case SPECIAL_LAYER_DELETE: - // Backup with unchanged layers - Backup_layers(0); - if (!Delete_layer(Main_backups,Main_current_layer)) - { - Update_screen_targets(); - Redraw_layered_image(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); - } - action++; - break; - case SPECIAL_LAYER_MERGE: - if (Main_current_layer>0) - { - // Backup layer below the current - Backup_layers(1<<(Main_current_layer-1)); - - Merge_layer(); - - Update_screen_targets(); - Redraw_layered_image(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); - } - action++; - break; - case SPECIAL_LAYER_SWAP_UP: - if (Main_current_layer < (Main_backups->Pages->Nb_layers-1)) - { - byte * tmp; - dword layer_flags; - - // Backup with unchanged layers - Backup_layers(0); - - // swap - tmp = Main_backups->Pages->Image[Main_current_layer]; - Main_backups->Pages->Image[Main_current_layer] = Main_backups->Pages->Image[Main_current_layer+1]; - Main_backups->Pages->Image[Main_current_layer+1] = tmp; - - // Swap visibility indicators - layer_flags = (Main_layers_visible >> Main_current_layer) & 3; - // Only needed if they are different. - if (layer_flags == 1 || layer_flags == 2) - { - // One is on, the other is off. Negating them will - // perform the swap. - Main_layers_visible ^= (3 << Main_current_layer); - } - Main_current_layer++; - - Update_screen_targets(); - Redraw_layered_image(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); - } - action++; - break; - - case SPECIAL_LAYER_SWAP_DOWN: - if (Main_current_layer > 0) - { - byte * tmp; - dword layer_flags; - - // Backup with unchanged layers - Backup_layers(0); - - // swap - tmp = Main_backups->Pages->Image[Main_current_layer]; - Main_backups->Pages->Image[Main_current_layer] = Main_backups->Pages->Image[Main_current_layer-1]; - Main_backups->Pages->Image[Main_current_layer-1] = tmp; - - // Swap visibility indicators - layer_flags = (Main_layers_visible >> (Main_current_layer-1)) & 3; - // Only needed if they are different. - if (layer_flags == 1 || layer_flags == 2) - { - // Only needed if they are different. - // One is on, the other is off. Negating them will - // perform the swap. - Main_layers_visible ^= (3 << (Main_current_layer-1)); - } - Main_current_layer--; - Update_screen_targets(); - Redraw_layered_image(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); - } - action++; - break; } } } // End of special keys diff --git a/helpfile.h b/helpfile.h index cc6a6115..2e089084 100644 --- a/helpfile.h +++ b/helpfile.h @@ -287,12 +287,13 @@ static const T_Help_table helptable_help[] = HELP_TEXT ("") HELP_TEXT ("LAYERS") HELP_TEXT ("") - HELP_LINK (" Menu : %s", SPECIAL_LAYER_MENU) - HELP_LINK (" Add new : %s", SPECIAL_LAYER_ADD) - HELP_LINK (" Delete : %s", SPECIAL_LAYER_DELETE) - HELP_LINK (" Merge : %s", SPECIAL_LAYER_MERGE) - HELP_LINK (" Move up : %s", SPECIAL_LAYER_SWAP_UP) - HELP_LINK (" Move down : %s", SPECIAL_LAYER_SWAP_DOWN) + HELP_LINK (" Menu : %s", 0x100+BUTTON_LAYER_MENU) + HELP_LINK (" Add new : %s", 0x100+BUTTON_LAYER_ADD) + HELP_LINK (" Delete : %s", 0x100+BUTTON_LAYER_REMOVE) + HELP_LINK (" Merge : %s", 0x100+BUTTON_LAYER_MERGE) + HELP_LINK (" Move up : %s", 0x100+BUTTON_LAYER_UP) + HELP_LINK (" Move down : %s", 0x100+BUTTON_LAYER_DOWN) + //HELP_LINK (" Set transp: %s", 0x100+BUTTON_LAYER_COLOR) HELP_TEXT (" Select :") HELP_LINK (" 1 : %s", SPECIAL_LAYER1_SELECT) HELP_LINK (" 2 : %s", SPECIAL_LAYER2_SELECT) @@ -2487,6 +2488,8 @@ static const T_Help_table helptable_layermenu[] = HELP_TITLE("LAYERS MENU") HELP_TEXT ("") + HELP_LINK ("(Key:%s)",0x100+BUTTON_LAYER_MENU) + HELP_TEXT ("") HELP_TEXT ("* Not implemented yet! *") }; @@ -2495,7 +2498,8 @@ static const T_Help_table helptable_layertrans[] = HELP_TITLE("LAYERS TRANSPARENCY") HELP_TEXT ("") - HELP_TEXT ("* Not implemented yet! *") + HELP_TEXT ("The current Background color becomes the") + HELP_TEXT ("color considered transparent for the layers.") }; static const T_Help_table helptable_layermerge[] = @@ -2503,15 +2507,24 @@ static const T_Help_table helptable_layermerge[] = HELP_TITLE("LAYERS MERGE") HELP_TEXT ("") - HELP_TEXT ("Merge layer with the one below") - + HELP_LINK ("(Key:%s)",0x100+BUTTON_LAYER_MERGE) + HELP_TEXT ("") + HELP_TEXT ("Merges the current layer with the one below") + HELP_TEXT ("it, and sets the resulting layer as current") + HELP_TEXT ("one for editing.") + HELP_TEXT ("This function has no effect if you're") + HELP_TEXT ("editing the lowest layer.") }; static const T_Help_table helptable_layeradd[] = { HELP_TITLE("ADD LAYER") HELP_TEXT ("") - HELP_TEXT ("Add a new layer above the current one") + HELP_LINK ("(Key:%s)",0x100+BUTTON_LAYER_ADD) + HELP_TEXT ("") + HELP_TEXT ("Add a new layer above the current one,") + HELP_TEXT ("and selects this new (empty) layer for") + HELP_TEXT ("editing.") }; static const T_Help_table helptable_layerdel[] = @@ -2519,7 +2532,9 @@ static const T_Help_table helptable_layerdel[] = HELP_TITLE("DROP LAYER") HELP_TEXT ("") - HELP_TEXT ("Drop the current layer") + HELP_LINK ("(Key:%s)",0x100+BUTTON_LAYER_REMOVE) + HELP_TEXT ("") + HELP_TEXT ("Deletes the current layer.") }; static const T_Help_table helptable_layerup[] = @@ -2527,7 +2542,11 @@ static const T_Help_table helptable_layerup[] = HELP_TITLE("MOVE LAYER UP") HELP_TEXT ("") - HELP_TEXT ("Move current layer above the next one") + HELP_LINK ("(Key:%s)",0x100+BUTTON_LAYER_UP) + HELP_TEXT ("") + HELP_TEXT ("Swaps the current layer with the one") + HELP_TEXT ("above it. This has no effect if this") + HELP_TEXT ("layer is already on top.") }; static const T_Help_table helptable_layerdown[] = @@ -2535,8 +2554,11 @@ static const T_Help_table helptable_layerdown[] = HELP_TITLE("MOVE LAYER DOWN") HELP_TEXT ("") - HELP_TEXT ("Move the current layer below the previous one") - + HELP_LINK ("(Key:%s)",0x100+BUTTON_LAYER_DOWN) + HELP_TEXT ("") + HELP_TEXT ("Swaps the current layer with the one") + HELP_TEXT ("below it. This has no effect if this") + HELP_TEXT ("layer is already on the bottom.") }; static const T_Help_table helptable_layerselect[] = { diff --git a/hotkeys.c b/hotkeys.c index d5da99b9..16120236 100644 --- a/hotkeys.c +++ b/hotkeys.c @@ -1656,10 +1656,10 @@ word Ordering[NB_SHORTCUTS]= SPECIAL_LAYER7_TOGGLE, SPECIAL_LAYER8_SELECT, SPECIAL_LAYER8_TOGGLE, - SPECIAL_LAYER_ADD, - SPECIAL_LAYER_DELETE, - SPECIAL_LAYER_MERGE, - SPECIAL_LAYER_SWAP_UP, - SPECIAL_LAYER_SWAP_DOWN, - SPECIAL_LAYER_MENU, + 0x100+BUTTON_LAYER_ADD, + 0x100+BUTTON_LAYER_REMOVE, + 0x100+BUTTON_LAYER_MERGE, + 0x100+BUTTON_LAYER_UP, + 0x100+BUTTON_LAYER_DOWN, + 0x100+BUTTON_LAYER_MENU, }; diff --git a/init.c b/init.c index d7754c8e..12e0542b 100644 --- a/init.c +++ b/init.c @@ -1313,7 +1313,7 @@ void Init_buttons(void) 142,0, 13,9, // Will be updated according to actual number of layers BUTTON_SHAPE_NO_FRAME, - Button_Layer_select, Button_Layer_select, + Button_Layer_select, Button_Layer_toggle, Do_nothing, FAMILY_INSTANT); // Status bar diff --git a/layers.c b/layers.c index 373491bf..31aae61a 100644 --- a/layers.c +++ b/layers.c @@ -26,107 +26,132 @@ #include "engine.h" #include "pages.h" +void Layer_activate(short layer, short side) +{ + word old_layers; + + if (layer >= Main_backups->Pages->Nb_layers) + return; + + // Keep a copy of which layers were visible + old_layers = Main_layers_visible; + + #ifndef NOLAYERS + + if (side == RIGHT_SIDE) + { + // Right-click on current layer + if (Main_current_layer == layer) + { + if (Main_layers_visible == (dword)(1<Pages); + //Download_infos_backup(Main_backups); + Display_all_screen(); + Display_layerbar(); + Display_cursor(); +} void Button_Layer_add(void) { - // Backup with unchanged layers - Backup_layers(0); - if (!Add_layer(Main_backups,Main_current_layer+1)) + Hide_cursor(); + + if (Main_backups->Pages->Nb_layers < 32) { - Update_depth_buffer(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); + // Backup with unchanged layers + Backup_layers(0); + if (!Add_layer(Main_backups,Main_current_layer+1)) + { + Update_depth_buffer(); + Display_all_screen(); + Display_layerbar(); + End_of_modification(); + } } - Hide_cursor(); Unselect_button(BUTTON_LAYER_ADD); Display_cursor(); } void Button_Layer_remove(void) { - // Backup with unchanged layers - Backup_layers(0); - if (!Delete_layer(Main_backups,Main_current_layer)) - { - Update_screen_targets(); - Redraw_layered_image(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); - } - Hide_cursor(); + + if (Main_backups->Pages->Nb_layers > 1) + { + // Backup with unchanged layers + Backup_layers(0); + if (!Delete_layer(Main_backups,Main_current_layer)) + { + Update_screen_targets(); + Redraw_layered_image(); + + Display_all_screen(); + Display_layerbar(); + End_of_modification(); + } + } Unselect_button(BUTTON_LAYER_REMOVE); Display_cursor(); } + void Button_Layer_select(void) { - Hide_cursor(); - Unselect_button(BUTTON_LAYER_SELECT); - Display_cursor(); + word layer; + // Determine which button is clicked according to mouse position + layer = (Mouse_X/Menu_factor_X - Menu_bars[MENUBAR_LAYERS].Skin_width) + / Layer_button_width; + + Layer_activate(layer, LEFT_SIDE); } -/* -void Button_Layer_1(void) +void Button_Layer_toggle(void) { - Hide_cursor(); - Unselect_button(BUTTON_LAYER_1); - Display_cursor(); + word layer; + // Determine which button is clicked according to mouse position + layer = (Mouse_X/Menu_factor_X - Menu_bars[MENUBAR_LAYERS].Skin_width) + / Layer_button_width; + + Layer_activate(layer, RIGHT_SIDE); } -void Button_Layer_2(void) -{ - Hide_cursor(); - Unselect_button(BUTTON_LAYER_2); - Display_cursor(); -} - -void Button_Layer_3(void) -{ - Hide_cursor(); - Unselect_button(BUTTON_LAYER_3); - Display_cursor(); -} - -void Button_Layer_4(void) -{ - Hide_cursor(); - Unselect_button(BUTTON_LAYER_4); - Display_cursor(); -} - -void Button_Layer_5(void) -{ - Hide_cursor(); - Unselect_button(BUTTON_LAYER_5); - Display_cursor(); -} - -void Button_Layer_6(void) -{ - Hide_cursor(); - Unselect_button(BUTTON_LAYER_6); - Display_cursor(); -} - -void Button_Layer_7(void) -{ - Hide_cursor(); - Unselect_button(BUTTON_LAYER_7); - Display_cursor(); -} - -void Button_Layer_8(void) -{ - Hide_cursor(); - Unselect_button(BUTTON_LAYER_8); - Display_cursor(); -} -*/ void Button_Layer_menu(void) { Hide_cursor(); @@ -136,25 +161,27 @@ void Button_Layer_menu(void) void Button_Layer_color(void) { + Hide_cursor(); + if (Main_backups->Pages->Transparent_color != Back_color) { Backup_layers(-1); Main_backups->Pages->Transparent_color = Back_color; Redraw_layered_image(); - Hide_cursor(); Display_all_screen(); Display_cursor(); End_of_modification(); } - Hide_cursor(); Unselect_button(BUTTON_LAYER_COLOR); Display_cursor(); } void Button_Layer_merge(void) { + Hide_cursor(); + if (Main_current_layer>0) { // Backup layer below the current @@ -164,58 +191,58 @@ void Button_Layer_merge(void) Update_screen_targets(); Redraw_layered_image(); - Hide_cursor(); Display_all_screen(); - Display_cursor(); + Display_layerbar(); End_of_modification(); } - Hide_cursor(); Unselect_button(BUTTON_LAYER_MERGE); Display_cursor(); } void Button_Layer_up(void) { + Hide_cursor(); + if (Main_current_layer < (Main_backups->Pages->Nb_layers-1)) { - byte * tmp; - dword layer_flags; - - // Backup with unchanged layers - Backup_layers(0); - - // swap - tmp = Main_backups->Pages->Image[Main_current_layer]; - Main_backups->Pages->Image[Main_current_layer] = Main_backups->Pages->Image[Main_current_layer+1]; - Main_backups->Pages->Image[Main_current_layer+1] = tmp; - - // Swap visibility indicators - layer_flags = (Main_layers_visible >> Main_current_layer) & 3; - // Only needed if they are different. - if (layer_flags == 1 || layer_flags == 2) - { - // One is on, the other is off. Negating them will - // perform the swap. - Main_layers_visible ^= (3 << Main_current_layer); - } - Main_current_layer++; - - Update_screen_targets(); - Redraw_layered_image(); - Hide_cursor(); - Display_all_screen(); - Display_cursor(); - End_of_modification(); + byte * tmp; + dword layer_flags; + + // Backup with unchanged layers + Backup_layers(0); + + // swap + tmp = Main_backups->Pages->Image[Main_current_layer]; + Main_backups->Pages->Image[Main_current_layer] = Main_backups->Pages->Image[Main_current_layer+1]; + Main_backups->Pages->Image[Main_current_layer+1] = tmp; + + // Swap visibility indicators + layer_flags = (Main_layers_visible >> Main_current_layer) & 3; + // Only needed if they are different. + if (layer_flags == 1 || layer_flags == 2) + { + // One is on, the other is off. Negating them will + // perform the swap. + Main_layers_visible ^= (3 << Main_current_layer); + } + Main_current_layer++; + + Update_screen_targets(); + Redraw_layered_image(); + Display_all_screen(); + Display_layerbar(); + End_of_modification(); } - Hide_cursor(); Unselect_button(BUTTON_LAYER_UP); Display_cursor(); } void Button_Layer_down(void) { + Hide_cursor(); + if (Main_current_layer > 0) { byte * tmp; @@ -242,12 +269,11 @@ void Button_Layer_down(void) Main_current_layer--; Update_screen_targets(); Redraw_layered_image(); - Hide_cursor(); + Display_layerbar(); Display_all_screen(); - Display_cursor(); End_of_modification(); } - Hide_cursor(); + Unselect_button(BUTTON_LAYER_DOWN); Display_cursor(); } diff --git a/layers.h b/layers.h index 10f01f9f..154557f1 100644 --- a/layers.h +++ b/layers.h @@ -22,20 +22,13 @@ void Button_Layer_add(void); void Button_Layer_remove(void); -/* -void Button_Layer_1(void); -void Button_Layer_2(void); -void Button_Layer_3(void); -void Button_Layer_4(void); -void Button_Layer_5(void); -void Button_Layer_6(void); -void Button_Layer_7(void); -void Button_Layer_8(void); -*/ void Button_Layer_menu(void); void Button_Layer_color(void); void Button_Layer_merge(void); void Button_Layer_up(void); void Button_Layer_down(void); void Button_Layer_select(void); +void Button_Layer_toggle(void); +void Layer_activate(short layer, short side); + diff --git a/special.c b/special.c index eeb5778b..b04a29d1 100644 --- a/special.c +++ b/special.c @@ -469,65 +469,4 @@ void Transparency_set(byte amount) Compute_colorize_table(); } -void Layer_activate(short layer, short side) -{ - word old_layers; - - if (layer >= Main_backups->Pages->Nb_layers) - return; - - // Keep a copy of which layers were visible - old_layers = Main_layers_visible; - - #ifndef NOLAYERS - - if (side == RIGHT_SIDE) - { - // Right-click on current layer - if (Main_current_layer == layer) - { - if (Main_layers_visible == (dword)(1<Pages); - //Download_infos_backup(Main_backups); - Display_all_screen(); - Display_cursor(); -} diff --git a/windows.c b/windows.c index 0e22d039..25007708 100644 --- a/windows.c +++ b/windows.c @@ -39,6 +39,9 @@ #include "readline.h" #include "sdlscreen.h" +/// Width of one layer button, in pixels before scaling +word Layer_button_width = 1; + // L'encapsulation tente une percée...ou un dernier combat. // Nombre de cellules réel dans la palette du menu @@ -420,6 +423,18 @@ int Pick_color_in_palette() return color; } +/// Draws a solid textured area, to the right of a toolbar. +void Draw_bar_remainder(word current_menu, word x_off, word y_off) +{ + word y_pos; + word x_pos; + + for (y_pos=0;y_pos 16) + button_number = 16; // Enlarge the buttons themselves if there's enough room while (button_number*(button_width+2) < horiz_space && repeats < 20) @@ -494,8 +512,22 @@ void Display_layerbar(void) // Next button x_off+=button_width; } + // Texture any remaining space to the right. + // This overwrites any junk like deleted buttons. + Draw_bar_remainder(MENUBAR_LAYERS, x_off, y_off); + // Update the active area of the layers pseudo-button Buttons_Pool[BUTTON_LAYER_SELECT].Width = button_number * button_width; + + // Required to determine which layer button is clicked + Layer_button_width = button_width; + + // A screen refresh required by some callers + Update_rect( + Menu_bars[MENUBAR_LAYERS].Skin_width, + Menu_Y+y_off*Menu_factor_Y, + horiz_space*Menu_factor_X, + Menu_bars[MENUBAR_LAYERS].Height*Menu_factor_Y); } @@ -520,14 +552,18 @@ void Display_menu(void) for (x_pos=0;x_pos