layers.c: button functions receive button number as first argument

also minor improvements
This commit is contained in:
Thomas Bernard 2018-11-28 12:58:33 +01:00
parent 53296293ee
commit 811ae20534
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
4 changed files with 63 additions and 71 deletions

View File

@ -45,6 +45,7 @@
#include "tiles.h" #include "tiles.h"
#include "oldies.h" #include "oldies.h"
#include "palette.h" #include "palette.h"
#include "layers.h"
//---------- Menu dans lequel on tagge des couleurs (genre Stencil) ---------- //---------- Menu dans lequel on tagge des couleurs (genre Stencil) ----------
void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut) void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut)
@ -196,7 +197,7 @@ void Button_Constraint_mode(void)
Switch_layer_mode(IMAGE_MODE_LAYERED); Switch_layer_mode(IMAGE_MODE_LAYERED);
// auto-create extra layers // auto-create extra layers
while (Main.backups->Pages->Nb_layers < 5) while (Main.backups->Pages->Nb_layers < 5)
Button_Layer_add(); Button_Layer_add(-1);
for (pixel=0; pixel < Main.image_width*Main.image_height; pixel++) for (pixel=0; pixel < Main.image_width*Main.image_height; pixel++)
{ {
if (Main.backups->Pages->Image[4].Pixels[pixel]>3) if (Main.backups->Pages->Image[4].Pixels[pixel]>3)

View File

@ -387,6 +387,8 @@ void Draw_menu_button(byte btn_number,byte pressed)
///Deselect a button ///Deselect a button
void Unselect_button(int btn_number) void Unselect_button(int btn_number)
{ {
if (btn_number < 0 || btn_number >= NB_BUTTONS)
return;
if (Buttons_Pool[btn_number].Pressed) if (Buttons_Pool[btn_number].Pressed)
{ {
// On considère que le bouton est relâché // On considère que le bouton est relâché

View File

@ -25,6 +25,7 @@
#include "const.h" #include "const.h"
#include "struct.h" #include "struct.h"
#include "global.h" #include "global.h"
#include "gfx2log.h"
#include "windows.h" #include "windows.h"
#include "engine.h" #include "engine.h"
#include "pages.h" #include "pages.h"
@ -35,6 +36,7 @@
#include "readline.h" #include "readline.h"
#include "graph.h" #include "graph.h"
#include "keycodes.h" #include "keycodes.h"
#include "layers.h"
void Layer_activate(int layer, short side) void Layer_activate(int layer, short side)
{ {
@ -104,25 +106,26 @@ void Layer_activate(int layer, short side)
Display_cursor(); Display_cursor();
} }
void Button_Layer_add(void) static int Layers_max(void)
{ {
int max;
Hide_cursor();
switch (Main.backups->Pages->Image_mode) switch (Main.backups->Pages->Image_mode)
{ {
case IMAGE_MODE_LAYERED: case IMAGE_MODE_LAYERED:
max = MAX_NB_LAYERS; return MAX_NB_LAYERS;
break; break;
case IMAGE_MODE_ANIMATION: case IMAGE_MODE_ANIMATION:
max = MAX_NB_FRAMES; return MAX_NB_FRAMES;
break; break;
default: default:
max = 5; return 5;
}
} }
if (Main.backups->Pages->Nb_layers < max) void Button_Layer_add(int btn)
{
Hide_cursor();
if (Main.backups->Pages->Nb_layers < Layers_max())
{ {
// Backup with unchanged layers // Backup with unchanged layers
Backup_layers(LAYER_NONE); Backup_layers(LAYER_NONE);
@ -137,19 +140,16 @@ void Button_Layer_add(void)
} }
} }
Unselect_button(BUTTON_LAYER_ADD); Unselect_button(btn);
Unselect_button(BUTTON_ANIM_ADD_FRAME);
Display_cursor(); Display_cursor();
} }
void Button_Layer_duplicate(void) void Button_Layer_duplicate(int btn)
{ {
int max[] = {MAX_NB_LAYERS, MAX_NB_FRAMES, 5};
Hide_cursor(); Hide_cursor();
if (Main.backups->Pages->Nb_layers < max[Main.backups->Pages->Image_mode]) if (Main.backups->Pages->Nb_layers < Layers_max())
{ {
// Backup with unchanged layers // Backup with unchanged layers
Backup_layers(LAYER_NONE); Backup_layers(LAYER_NONE);
@ -161,7 +161,8 @@ void Button_Layer_duplicate(void)
Main.backups->Pages->Image[Main.current_layer-1].Pixels, Main.backups->Pages->Image[Main.current_layer-1].Pixels,
Main.backups->Pages->Width*Main.backups->Pages->Height); Main.backups->Pages->Width*Main.backups->Pages->Height);
if (Main.backups->Pages->Image_mode != IMAGE_MODE_ANIMATION) { if (Main.backups->Pages->Image_mode != IMAGE_MODE_ANIMATION)
{
Update_depth_buffer(); Update_depth_buffer();
// I just noticed this might be unneeded, since the new layer // I just noticed this might be unneeded, since the new layer
// is transparent, it shouldn't have any visible effect. // is transparent, it shouldn't have any visible effect.
@ -172,12 +173,11 @@ void Button_Layer_duplicate(void)
} }
} }
Unselect_button(BUTTON_LAYER_ADD); Unselect_button(btn);
Unselect_button(BUTTON_ANIM_ADD_FRAME);
Display_cursor(); Display_cursor();
} }
void Button_Layer_remove(void) void Button_Layer_remove(int btn)
{ {
Hide_cursor(); Hide_cursor();
@ -195,14 +195,13 @@ void Button_Layer_remove(void)
End_of_modification(); End_of_modification();
} }
} }
Unselect_button(BUTTON_LAYER_REMOVE); Unselect_button(btn);
Unselect_button(BUTTON_ANIM_REMOVE_FRAME);
Display_cursor(); Display_cursor();
} }
short Layer_under_mouse(void) static int Layer_under_mouse(void)
{ {
short layer; int layer;
// Determine which button is clicked according to mouse position // Determine which button is clicked according to mouse position
layer = (Mouse_X/Menu_factor_X - Menu_bars[MENUBAR_LAYERS].Skin_width) layer = (Mouse_X/Menu_factor_X - Menu_bars[MENUBAR_LAYERS].Skin_width)
/ Layer_button_width; / Layer_button_width;
@ -216,26 +215,18 @@ short Layer_under_mouse(void)
return layer; return layer;
} }
void Button_Layer_select(void) void Button_Layer_select(int btn)
{ {
short layer = Layer_under_mouse(); int layer = Layer_under_mouse();
(void)btn;
Layer_activate(layer, LEFT_SIDE); Layer_activate(layer, LEFT_SIDE);
Mouse_K=0; Mouse_K=0;
} }
void Button_Layer_toggle(void) void Button_Layer_toggle(int btn)
{ {
int layer; int layer = Layer_under_mouse();
// Determine which button is clicked according to mouse position (void)btn;
layer = (Mouse_X/Menu_factor_X - Menu_bars[MENUBAR_LAYERS].Skin_width)
/ Layer_button_width;
// Safety required because the mouse cursor can have slided outside button.
if (layer < 0)
layer=0;
else if (layer > Main.backups->Pages->Nb_layers-1)
layer=Main.backups->Pages->Nb_layers-1;
Layer_activate(layer, RIGHT_SIDE); Layer_activate(layer, RIGHT_SIDE);
Mouse_K=0; Mouse_K=0;
} }
@ -254,7 +245,7 @@ static void Draw_transparent_background(byte background)
} }
void Button_Layer_menu(void) void Button_Layer_menu(int btn)
{ {
byte transparent_color = Main.backups->Pages->Transparent_color; byte transparent_color = Main.backups->Pages->Transparent_color;
byte transparent_background = Main.backups->Pages->Background_transparent; byte transparent_background = Main.backups->Pages->Background_transparent;
@ -286,7 +277,7 @@ void Button_Layer_menu(void)
clicked_button=Window_clicked_button(); clicked_button=Window_clicked_button();
if (Is_shortcut(Key,0x100+BUTTON_HELP)) if (Is_shortcut(Key,0x100+BUTTON_HELP))
Window_help(BUTTON_LAYER_MENU, NULL); Window_help(btn, NULL);
switch(clicked_button) switch(clicked_button)
{ {
case 1: // color case 1: // color
@ -328,12 +319,11 @@ void Button_Layer_menu(void)
End_of_modification(); End_of_modification();
} }
} }
Unselect_button(BUTTON_LAYER_MENU); Unselect_button(btn);
Unselect_button(BUTTON_LAYER_MENU2);
Display_cursor(); Display_cursor();
} }
void Button_Layer_set_transparent(void) void Button_Layer_set_transparent(int btn)
{ {
Hide_cursor(); Hide_cursor();
@ -347,11 +337,11 @@ void Button_Layer_set_transparent(void)
End_of_modification(); End_of_modification();
} }
Unselect_button(BUTTON_LAYER_COLOR); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Layer_get_transparent(void) void Button_Layer_get_transparent(int btn)
{ {
Hide_cursor(); Hide_cursor();
@ -360,11 +350,11 @@ void Button_Layer_get_transparent(void)
Set_back_color(Main.backups->Pages->Transparent_color); Set_back_color(Main.backups->Pages->Transparent_color);
} }
Unselect_button(BUTTON_LAYER_COLOR); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Layer_merge(void) void Button_Layer_merge(int btn)
{ {
Hide_cursor(); Hide_cursor();
@ -382,11 +372,11 @@ void Button_Layer_merge(void)
End_of_modification(); End_of_modification();
} }
Unselect_button(BUTTON_LAYER_MERGE); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Layer_up(void) void Button_Layer_up(int btn)
{ {
Hide_cursor(); Hide_cursor();
@ -421,12 +411,11 @@ void Button_Layer_up(void)
End_of_modification(); End_of_modification();
} }
Unselect_button(BUTTON_LAYER_UP); Unselect_button(btn);
Unselect_button(BUTTON_ANIM_UP_FRAME);
Display_cursor(); Display_cursor();
} }
void Button_Layer_down(void) void Button_Layer_down(int btn)
{ {
Hide_cursor(); Hide_cursor();
@ -461,8 +450,7 @@ void Button_Layer_down(void)
End_of_modification(); End_of_modification();
} }
Unselect_button(BUTTON_LAYER_DOWN); Unselect_button(btn);
Unselect_button(BUTTON_ANIM_DOWN_FRAME);
Display_cursor(); Display_cursor();
} }
@ -475,7 +463,7 @@ int Interpret_delay(int delay)
return 100; return 100;
return 30; return 30;
} }
void Button_Anim_time(void) void Button_Anim_time(int btn)
{ {
short clicked_button; short clicked_button;
int mode=0; int mode=0;
@ -591,21 +579,21 @@ void Button_Anim_time(void)
End_of_modification(); End_of_modification();
} }
Unselect_button(BUTTON_ANIM_TIME); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Anim_first_frame(void) void Button_Anim_first_frame(int btn)
{ {
if (Main.current_layer>0) if (Main.current_layer>0)
Layer_activate(0,LEFT_SIDE); Layer_activate(0,LEFT_SIDE);
Hide_cursor(); Hide_cursor();
Unselect_button(BUTTON_ANIM_FIRST_FRAME); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Anim_prev_frame(void) void Button_Anim_prev_frame(int btn)
{ {
if (Main.backups->Pages->Nb_layers>1) if (Main.backups->Pages->Nb_layers>1)
{ {
@ -615,11 +603,11 @@ void Button_Anim_prev_frame(void)
Layer_activate(Main.current_layer-1,LEFT_SIDE); Layer_activate(Main.current_layer-1,LEFT_SIDE);
} }
Hide_cursor(); Hide_cursor();
Unselect_button(BUTTON_ANIM_PREV_FRAME); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Anim_next_frame(void) void Button_Anim_next_frame(int btn)
{ {
if (Main.backups->Pages->Nb_layers>1) if (Main.backups->Pages->Nb_layers>1)
{ {
@ -630,21 +618,21 @@ void Button_Anim_next_frame(void)
} }
Hide_cursor(); Hide_cursor();
Unselect_button(BUTTON_ANIM_NEXT_FRAME); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Anim_last_frame(void) void Button_Anim_last_frame(int btn)
{ {
if (Main.current_layer < (Main.backups->Pages->Nb_layers-1)) if (Main.current_layer < (Main.backups->Pages->Nb_layers-1))
Layer_activate((Main.backups->Pages->Nb_layers-1),LEFT_SIDE); Layer_activate((Main.backups->Pages->Nb_layers-1),LEFT_SIDE);
Hide_cursor(); Hide_cursor();
Unselect_button(BUTTON_ANIM_LAST_FRAME); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Anim_continuous_next(void) void Button_Anim_continuous_next(int btn)
{ {
dword time_start; dword time_start;
int time_in_current_frame=0; int time_in_current_frame=0;
@ -675,11 +663,11 @@ void Button_Anim_continuous_next(void)
} while (Mouse_K); } while (Mouse_K);
Hide_cursor(); Hide_cursor();
Unselect_button(BUTTON_ANIM_NEXT_FRAME); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }
void Button_Anim_continuous_prev(void) void Button_Anim_continuous_prev(int btn)
{ {
dword time_start; dword time_start;
int time_in_current_frame=0; int time_in_current_frame=0;
@ -710,6 +698,6 @@ void Button_Anim_continuous_prev(void)
} while (Mouse_K); } while (Mouse_K);
Hide_cursor(); Hide_cursor();
Unselect_button(BUTTON_ANIM_PREV_FRAME); Unselect_button(btn);
Display_cursor(); Display_cursor();
} }

View File

@ -19,6 +19,8 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/> along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/ */
#ifndef LAYERS_H__
#define LAYERS_H__
void Button_Layer_add(int); void Button_Layer_add(int);
void Button_Layer_duplicate(int); void Button_Layer_duplicate(int);
@ -40,5 +42,4 @@ void Button_Anim_last_frame(int);
void Button_Anim_play(int); void Button_Anim_play(int);
void Button_Anim_continuous_prev(int); void Button_Anim_continuous_prev(int);
void Button_Anim_continuous_next(int); void Button_Anim_continuous_next(int);
#endif
short Layer_under_mouse(void);