From 1e0cafdae147c21aaea5f684a0ff10078191969f Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sun, 11 Apr 2010 18:43:32 +0000 Subject: [PATCH] Fix issue 340: Inaccurate cursor position when selecting palette colors. Also improved greatly the picking of color: It's now on mouse down (instead of release), you can drag the mouse to another cell. Dragging won't activate any other buttons, only palette cells. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1453 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 72 +++++++++++++++++++++++++++++++++++++++------------ src/engine.c | 25 +++++++++++++----- src/engine.h | 5 +++- src/init.c | 4 +-- src/windows.c | 4 +-- 5 files changed, 82 insertions(+), 28 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 21dd6027..d22462b8 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -300,12 +300,13 @@ void Button_Select_forecolor(void) { static long time_click = 0; long time_previous; - - int color=Pick_color_in_palette(); - + int color; + time_previous = time_click; time_click = SDL_GetTicks(); - + + color=Pick_color_in_palette(); + if (color == Fore_color) { // Check if it's a double-click @@ -313,27 +314,66 @@ void Button_Select_forecolor(void) { // Open palette window Button_Palette(); + return; } } - else if (color!=-1) + + do { - Hide_cursor(); - Set_fore_color(color); - Display_cursor(); - } + if (color != Fore_color && color!=-1) + { + Hide_cursor(); + Set_fore_color(color); + Display_cursor(); + } + // Wait loop after initial click + while(Mouse_K) + { + if(!Get_input()) + SDL_Delay(20); + + if (Button_under_mouse()==BUTTON_CHOOSE_COL) + { + color=Pick_color_in_palette(); + if (color != Fore_color && color!=-1) + { + Hide_cursor(); + Status_print_palette_color(color); + Set_fore_color(color); + Display_cursor(); + } + } + } + } while(Mouse_K); } //-------------------- item de la backcolor dans le menu -------------------- void Button_Select_backcolor(void) { - int color=Pick_color_in_palette(); - - if (color!=-1) + int color; + + do { - Hide_cursor(); - Set_back_color(color); - Display_cursor(); - } + color=Pick_color_in_palette(); + + if (color!=-1 && color != Back_color) + { + Hide_cursor(); + Status_print_palette_color(color); + Set_back_color(color); + Display_cursor(); + } + // Wait loop after initial click + do + { + if(!Get_input()) + SDL_Delay(20); + + if (Button_under_mouse()==BUTTON_CHOOSE_COL) + break; // This will repeat this button's action + + } while(Mouse_K); + } while(Mouse_K); } void Button_Hide_menu(void) diff --git a/src/engine.c b/src/engine.c index d02cb7b8..7a4dcea7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -504,6 +504,23 @@ void Move_separator(void) Display_cursor(); } +/// +/// Updates the status bar line with a color number. +/// Used when hovering the menu palette. +void Status_print_palette_color(byte color) +{ + char str[25]; + int i; + + strcpy(str,Menu_tooltip[BUTTON_CHOOSE_COL]); + sprintf(str+strlen(str),"%d (%d,%d,%d)",color,Main_palette[color].R,Main_palette[color].G,Main_palette[color].B); + // Pad spaces + for (i=strlen(str); i<24; i++) + str[i]=' '; + str[24]='\0'; + + Print_in_menu(str,0); +} ///Main handler for everything. This is the main loop of the program void Main_handler(void) @@ -513,7 +530,6 @@ void Main_handler(void) int prev_button_number=0; // Numéro de bouton de menu sur lequel on était précédemment byte blink; // L'opération demande un effacement du curseur int key_index; // index du tableau de touches spéciales correspondant à la touche enfoncée - char str[25]; byte temp; byte effect_modified; byte action; @@ -1179,12 +1195,7 @@ void Main_handler(void) if ((color=Pick_color_in_palette())!=-1) { Hide_cursor(); - strcpy(str,Menu_tooltip[button_index]); - sprintf(str+strlen(str),"%d (%d,%d,%d)",color,Main_palette[color].R,Main_palette[color].G,Main_palette[color].B); - for (temp=strlen(str); temp<24; temp++) - str[temp]=' '; - str[24]=0; - Print_in_menu(str,0); + Status_print_palette_color(color); Display_cursor(); } else diff --git a/src/engine.h b/src/engine.h index 391879f0..4f89e73f 100644 --- a/src/engine.h +++ b/src/engine.h @@ -106,5 +106,8 @@ int Button_under_mouse(void); short Window_get_clicked_button(void); void Remap_window_backgrounds(byte * conversion_table, int Min_Y, int Max_Y); void Pixel_background(int x_pos, int y_pos, byte color); - +/// +/// Updates the status bar line with a color number. +/// Used when hovering the menu palette. +void Status_print_palette_color(byte color); #endif diff --git a/src/init.c b/src/init.c index ad603b6f..36f104bf 100644 --- a/src/init.c +++ b/src/init.c @@ -1296,11 +1296,11 @@ void Init_buttons(void) FAMILY_INSTANT); Init_button(BUTTON_CHOOSE_COL, - MENU_WIDTH+1,2, + MENU_WIDTH+1,1, 1,32, // La largeur est mise à jour à chq chngmnt de mode BUTTON_SHAPE_NO_FRAME, Button_Select_forecolor,Button_Select_backcolor, - 0,0, + 1,1, Do_nothing, FAMILY_INSTANT); diff --git a/src/windows.c b/src/windows.c index 963c8358..43634c64 100644 --- a/src/windows.c +++ b/src/windows.c @@ -416,7 +416,7 @@ void Change_palette_cells() // Mise à jour de la taille du bouton dans le menu. C'est pour pas que // la bordure noire soit active. Buttons_Pool[BUTTON_CHOOSE_COL].Width=(Menu_palette_cell_width*Menu_cells_X)-1; - Buttons_Pool[BUTTON_CHOOSE_COL].Height=(Menu_height-11)/Menu_cells_Y*Menu_cells_Y-1; + Buttons_Pool[BUTTON_CHOOSE_COL].Height=(MENU_HEIGHT-9)/Menu_cells_Y*Menu_cells_Y-1; } // Retrouve la couleur sur laquelle pointe le curseur souris. @@ -431,7 +431,7 @@ int Pick_color_in_palette() int line; int column; - line=(((Mouse_Y-Menu_Y)/Menu_factor_Y)-2)/((Menu_bars[MENUBAR_TOOLS].Height)/Menu_cells_Y); + line=(((Mouse_Y-Menu_Y)/Menu_factor_Y)-1)/((Menu_bars[MENUBAR_TOOLS].Height)/Menu_cells_Y); column=(((Mouse_X/Menu_factor_X)-(MENU_WIDTH+1))/Menu_palette_cell_width); if (Config.Palette_vertical) {