From 7bfdb28936cfd8fd67164b95b2a3c132dbd28dd8 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sun, 23 Aug 2009 00:41:40 +0000 Subject: [PATCH] Keyboard shortcuts that open a window now also close it (Issue 88). Fixed a recent bug that made contextual help in FX window only work once. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1004 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- buttons.c | 74 ++++++++++++++++++++++++++++++++++++----------------- buttons.h | 2 +- engine.c | 2 +- filesel.c | 14 +++++++++- help.c | 7 +++-- input.c | 2 +- palette.c | 7 ++++- shade.c | 4 +++ transform.c | 3 +++ 9 files changed, 85 insertions(+), 30 deletions(-) diff --git a/buttons.c b/buttons.c index 142bee0f..b368f470 100644 --- a/buttons.c +++ b/buttons.c @@ -429,6 +429,8 @@ byte Button_Quit_local_function(void) clicked_button=Window_clicked_button(); if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_QUIT, NULL); + else if (Is_shortcut(Key,0x100+BUTTON_QUIT)) + clicked_button=1; } while (clicked_button<=0); @@ -526,7 +528,7 @@ void Button_Clear_with_backcolor(void) } //---------- 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) +void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut) { short clicked_button; byte backup_table[256]; @@ -626,6 +628,10 @@ void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_ca Key=0; break; } + else if (Is_shortcut(Key,close_shortcut)) + { + clicked_button=4; + } } } while (clicked_button<4); @@ -664,7 +670,7 @@ void Stencil_update_color(byte color) void Button_Stencil_menu(void) { - Menu_tag_colors("Stencil",Stencil,&Stencil_mode,1, "STENCIL"); + Menu_tag_colors("Stencil",Stencil,&Stencil_mode,1, "STENCIL", SPECIAL_STENCIL_MENU); } @@ -677,7 +683,7 @@ void Button_Mask_mode(void) void Button_Mask_menu(void) { - Menu_tag_colors("Mask",Mask_table,&Mask_mode,1, "MASK"); + Menu_tag_colors("Mask",Mask_table,&Mask_mode,1, "MASK", SPECIAL_MASK_MENU); } @@ -805,7 +811,7 @@ void Button_Settings(void) // Button Show/Hide dans le fileselect Window_set_normal_button(167, 28,131,14,"Hidden files: ",0,1,SDLK_LAST); // 1 Window_set_normal_button(167, 43,131,14,"Hidden dir. : ",0,1,SDLK_LAST); // 2 -// Window_set_normal_button(167, 58,131,14,"System dir. : ",0,1,SDLK_LAST); // 3 +// Window_set_normal_button(167, 58,131,14,"System dir. : ",0,1,SDLK_LAST); // Button Show/Hide Picture limits Window_set_normal_button( 9, 81,107,14,"Limits : ",0,1,SDLK_LAST); // 3 @@ -817,31 +823,31 @@ void Button_Settings(void) Window_set_normal_button( 9,126,107,14,"Backup : ",0,1,SDLK_LAST); // 6 // Button Safety colors - Window_set_normal_button(117, 81,131,14,"Safe. colors: ",0,1,SDLK_LAST); // 8 + Window_set_normal_button(117, 81,131,14,"Safe. colors: ",0,1,SDLK_LAST); // 7 // Button Adjust Brush Pick - Window_set_normal_button(117, 96,131,14,"AdjBrushPick: ",0,1,SDLK_LAST); // 9 + Window_set_normal_button(117, 96,131,14,"AdjBrushPick: ",0,1,SDLK_LAST); // 8 // Button Separate colors - Window_set_normal_button(117,111,131,14,"Separate col: ",0,1,SDLK_LAST); // 10 + Window_set_normal_button(117,111,131,14,"Separate col: ",0,1,SDLK_LAST); // 9 // Button Passer dans la résolution appropriée après un chargement - Window_set_normal_button(117,126,131,14,"Auto-set res: ",0,1,SDLK_LAST); // 11 + Window_set_normal_button(117,126,131,14,"Auto-set res: ",0,1,SDLK_LAST); // 10 // Button Adapter la palette après un chargement (<=> Shift+BkSpc) - Window_set_normal_button(117,141,131,14,"Coords: ",0,1,SDLK_LAST); // 12 + Window_set_normal_button(117,141,131,14,"Coords: ",0,1,SDLK_LAST); // 11 // Button Reload - Window_set_normal_button( 6,163, 51,14,"Reload" ,0,1,SDLK_LAST); // 13 + Window_set_normal_button( 6,163, 51,14,"Reload" ,0,1,SDLK_LAST); // 12 // Button Auto-save - Window_set_normal_button( 73,163,107,14,"Auto-save: ",0,1,SDLK_LAST); // 14 + Window_set_normal_button( 73,163,107,14,"Auto-save: ",0,1,SDLK_LAST); // 13 // Button Save - Window_set_normal_button(183,163, 51,14,"Save" ,0,1,SDLK_LAST); // 15 + Window_set_normal_button(183,163, 51,14,"Save" ,0,1,SDLK_LAST); // 14 // Button Close - Window_set_normal_button(250,163, 51,14,"Close" ,0,1,KEY_ESC); // 16 + Window_set_normal_button(250,163, 51,14,"Close" ,0,1,KEY_ESC); // 15 // Jauges de sensibilité de la souris (X puis Y) - Window_set_scroller_button(265,99,56,4,1,0); // 17 - Window_set_scroller_button(279,99,56,4,1,0); // 18 + Window_set_scroller_button(265,99,56,4,1,0); // 16 + Window_set_scroller_button(279,99,56,4,1,0); // 17 // Zone de saisie du nb de pages de Undo - Window_set_input_button(140,50,2); // 19 + Window_set_input_button(140,50,2); // 18 Update_window_area(0,0,Window_width, Window_height); @@ -944,6 +950,8 @@ void Button_Settings(void) if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_SETTINGS, NULL); + else if (Is_shortcut(Key,0x100+BUTTON_SETTINGS)) + clicked_button=15; } while ( (clicked_button!=15) && (Key!=SDLK_RETURN) ); @@ -1418,7 +1426,7 @@ void Copy_some_colors(void) static byte mask_color_to_copy[256]; // static to use less stack memset(mask_color_to_copy,1,256); - Menu_tag_colors("Tag colors to copy",mask_color_to_copy,&confirmation,0, NULL); + Menu_tag_colors("Tag colors to copy",mask_color_to_copy,&confirmation,0, NULL, 0xFFFF); if (confirmation && (!Spare_image_is_modified || Confirmation_box("Spare page was modified. Proceed?"))) @@ -1455,6 +1463,8 @@ void Button_Copy_page(void) clicked_button=Window_clicked_button(); if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_PAGE, NULL); + else if (Is_shortcut(Key,0x200+BUTTON_PAGE)) + clicked_button=6; } while (clicked_button<=0); @@ -2374,6 +2384,8 @@ void Button_Gradients(void) Key=0; break; } + if (Is_shortcut(Key,0x200+BUTTON_GRADRECT)) + clicked_button=6; } } while (clicked_button<6); @@ -2512,7 +2524,6 @@ void Button_Paintbrush_menu(void) clicked_button=Window_clicked_button(); if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_PAINTBRUSHES, NULL); - // Brush container if (clicked_button>(NB_PAINTBRUSH_SPRITES+1)) { @@ -2559,7 +2570,7 @@ void Button_Paintbrush_menu(void) break; } - else if (clicked_button==1) + else if (clicked_button==1 || Is_shortcut(Key,0x100+BUTTON_PAINTBRUSHES)) { Close_window(); break; @@ -3371,6 +3382,8 @@ void Button_Magnify_menu(void) clicked_button=Window_clicked_button(); if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_MAGNIFIER, NULL); + else if (Is_shortcut(Key,0x200+BUTTON_MAGNIFIER)) + clicked_button=1; } while (clicked_button<=0); @@ -3684,6 +3697,10 @@ void Button_Brush_FX(void) Key=0; Window_help(BUTTON_BRUSH_EFFECTS, NULL); } + else if (Is_shortcut(Key,0x100+BUTTON_BRUSH_EFFECTS)) + { + clicked_button=1; + } } while (clicked_button<=0); @@ -3858,6 +3875,8 @@ void Button_Smooth_menu(void) } if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_EFFECTS, "SMOOTH"); + else if (Is_shortcut(Key,SPECIAL_SMOOTH_MENU)) + clicked_button=2; } while ((clicked_button!=1) && (clicked_button!=2)); @@ -4023,6 +4042,8 @@ void Button_Colorize_menu(void) } if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_EFFECTS, "TRANSPARENCY"); + else if (Is_shortcut(Key,SPECIAL_COLORIZE_MENU)) + clicked_button=6; } while (clicked_button<5); @@ -4558,7 +4579,11 @@ void Button_Airbrush_menu(void) Key=0; break; } - + if (Is_shortcut(Key,0x200+BUTTON_AIRBRUSH)) + { + clicked_button=2; + break; + } } } while ( (clicked_button!=1) && (clicked_button!=2) ); @@ -5175,14 +5200,13 @@ void Button_Effects(void) { clicked_button=Window_clicked_button(); - if (Key==KEY_ESC) + if (Key==KEY_ESC || Is_shortcut(Key,0x100+BUTTON_EFFECTS)) { clicked_button=11; Key=0; } else if (Is_shortcut(Key,0x100+BUTTON_HELP)) { - Key=0; // Aide contextuelle switch(Window_get_clicked_button()) { @@ -5219,7 +5243,9 @@ void Button_Effects(void) default: Window_help(BUTTON_EFFECTS, NULL); } - continue; + // Hack because we have used Window_get_clicked_button() + Input_sticky_control=0; + // } switch (clicked_button) @@ -5540,6 +5566,8 @@ void Button_Text() { if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_TEXT, NULL); + else if (Is_shortcut(Key,0x100+BUTTON_TEXT)) + clicked_button=12; } switch(clicked_button) { diff --git a/buttons.h b/buttons.h index 8376dcc5..a75b38de 100644 --- a/buttons.h +++ b/buttons.h @@ -637,7 +637,7 @@ void Save_picture(byte image); /*! Generic color tagging menu, for various effects. */ -void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section); +void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut ); /*! diff --git a/engine.c b/engine.c index 085fdadb..f4f104ab 100644 --- a/engine.c +++ b/engine.c @@ -778,7 +778,7 @@ void Main_handler(void) Key=0; break; case SPECIAL_EXCLUDE_COLORS_MENU : // Exclude colors menu - Menu_tag_colors("Tag colors to exclude",Exclude_color,&temp,1, NULL); + Menu_tag_colors("Tag colors to exclude",Exclude_color,&temp,1, NULL, SPECIAL_EXCLUDE_COLORS_MENU); Key=0; break; case SPECIAL_INVERT_SIEVE : diff --git a/filesel.c b/filesel.c index b7b3cc2e..4f2ed269 100644 --- a/filesel.c +++ b/filesel.c @@ -1030,6 +1030,12 @@ byte Button_Load_or_Save(byte load, byte image) char quicksearch_filename[MAX_PATH_CHARACTERS]=""; char save_filename[MAX_PATH_CHARACTERS]; char * most_matching_filename; + short window_shortcut; + + if (image) + window_shortcut = load?(0x100+BUTTON_LOAD):(0x100+BUTTON_SAVE); + else + window_shortcut = load?SPECIAL_LOAD_BRUSH:SPECIAL_SAVE_BRUSH; initial_palette=(T_Components *)malloc(sizeof(T_Palette)); memcpy(initial_palette,Main_palette,sizeof(T_Palette)); @@ -1550,7 +1556,7 @@ byte Button_Load_or_Save(byte load, byte image) } Key=0; break; - default: // Autre => On se place sur le nom de fichier qui correspond + default: if (clicked_button<=0) { if (Is_shortcut(Key,0x100+BUTTON_HELP)) @@ -1558,6 +1564,12 @@ byte Button_Load_or_Save(byte load, byte image) Window_help(load?BUTTON_LOAD:BUTTON_SAVE, NULL); break; } + if (Is_shortcut(Key,window_shortcut)) + { + clicked_button=2; + break; + } + // Autre => On se place sur le nom de fichier qui correspond temp=strlen(quicksearch_filename); if (Key_ANSI>= ' ' && Key_ANSI < 255 && temp<50) { diff --git a/help.c b/help.c index c8291ea7..7dc1079a 100644 --- a/help.c +++ b/help.c @@ -585,11 +585,12 @@ void Window_help(int section, const char *sub_section) } break; } - + if (Is_shortcut(Key,0x100+BUTTON_HELP)) + clicked_button=1; } while ((clicked_button!=1) && (Key!=SDLK_RETURN)); - if(Key==SDLK_RETURN) Key=0; + Key=0; Close_window(); Unselect_button(BUTTON_HELP); Display_cursor(); @@ -698,6 +699,8 @@ void Button_Stats(void) do { clicked_button=Window_clicked_button(); + if (Is_shortcut(Key,0x200+BUTTON_HELP)) + clicked_button=1; } while ( (clicked_button!=1) && (Key!=SDLK_RETURN) ); diff --git a/input.c b/input.c index 0e2ea19b..f5cb582d 100644 --- a/input.c +++ b/input.c @@ -82,7 +82,7 @@ short Joybutton_right_click=0; // Button number that serves as right-click int Is_shortcut(word Key, word function) { - if (Key == 0) + if (Key == 0 || function == 0xFFFF) return 0; if (function & 0x100) diff --git a/palette.c b/palette.c index f8bcaa00..c4df752e 100644 --- a/palette.c +++ b/palette.c @@ -2097,6 +2097,8 @@ void Button_Palette(void) Window_help(BUTTON_PALETTE, NULL); break; } + else if (Is_shortcut(Key,0x100+BUTTON_PALETTE)) + clicked_button=14; } if (need_to_remap) @@ -2221,6 +2223,9 @@ void Button_Secondary_palette(void) Key=0; Window_help(BUTTON_PALETTE, "PALETTE OPTIONS"); } + else if (Is_shortcut(Key,0x200+BUTTON_PALETTE)) + clicked_button=3; + switch(clicked_button) { case 5: @@ -2298,7 +2303,7 @@ void Button_Secondary_palette(void) if (clicked_button==1) { - Menu_tag_colors("Tag colors to exclude",Exclude_color,&dummy,1, NULL); + Menu_tag_colors("Tag colors to exclude",Exclude_color,&dummy,1, NULL, SPECIAL_EXCLUDE_COLORS_MENU); } else if (clicked_button==2) { diff --git a/shade.c b/shade.c index 7d8e5782..32d0dfed 100644 --- a/shade.c +++ b/shade.c @@ -978,6 +978,8 @@ int Menu_shade(void) Key=0; Window_help(BUTTON_EFFECTS, "SHADE"); } + else if (Is_shortcut(Key,SPECIAL_SHADE_MENU)) + clicked_button=5; } } while ((clicked_button!=4) && (clicked_button!=5)); @@ -1097,6 +1099,8 @@ void Button_Quick_shade_menu(void) } if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_EFFECTS, "QUICK SHADE"); + else if (Is_shortcut(Key,SPECIAL_QUICK_SHADE_MENU)) + clicked_button=1; } while ((clicked_button!=1) && (clicked_button!=2)); diff --git a/transform.c b/transform.c index 3305d89c..1707ab6f 100644 --- a/transform.c +++ b/transform.c @@ -196,6 +196,9 @@ void Button_Transform_menu(void) Key=0; Window_help(BUTTON_ADJUST, "PICTURE TRANSFORM"); } + else if (Is_shortcut(Key,0x200+BUTTON_ADJUST)) + clicked_button=1; + else switch(clicked_button) { case 9: // Unit