From 775ee56ed06eea14b2e9474f0636468ab1a9d000 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sat, 1 Oct 2011 19:26:13 +0000 Subject: [PATCH] Paste in Text tool: fix a graphic overflow. Palette reduce: use DawnBringer's formula for color likeness git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1837 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/input.h | 13 +++++++++++++ src/palette.c | 19 +++++++++++-------- src/readline.c | 27 +++++++++++++++++---------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/input.h b/src/input.h index 9ee0d7e7..74485db2 100644 --- a/src/input.h +++ b/src/input.h @@ -64,3 +64,16 @@ extern int Snap_axis_origin_Y; /// This malloced string is set when a drag-and-drop event /// brings a file to Grafx2's window. extern char * Drop_file_name; + +#if defined __HAIKU__ + #define SHORTCUT_COPY (SDLK_c|MOD_ALT) +#else + #define SHORTCUT_COPY (SDLK_c|MOD_CTRL) +#endif + +#if defined __HAIKU__ + #define SHORTCUT_PASTE (SDLK_v|MOD_ALT) +#else + #define SHORTCUT_PASTE (SDLK_v|MOD_CTRL) +#endif + diff --git a/src/palette.c b/src/palette.c index 3ca1f7d3..d3f3aca2 100644 --- a/src/palette.c +++ b/src/palette.c @@ -559,8 +559,8 @@ void Reduce_palette(short * used_colors,int nb_colors_asked,T_Palette palette,dw int color_2; // | de la palette int best_color_1=0; int best_color_2=0; - int difference; - int best_difference; + long difference; + long best_difference; dword used; dword best_used; @@ -621,16 +621,19 @@ void Reduce_palette(short * used_colors,int nb_colors_asked,T_Palette palette,dw // une seule couleur qui est la moyenne pondérée de ces 2 couleurs // en fonction de leur utilisation dans l'image. - best_difference =0x7FFF; + best_difference =26*255*26*255+55*255*255+19*255*19*255; best_used=0x7FFFFFFF; for (color_1=0;color_1<(*used_colors);color_1++) for (color_2=color_1+1;color_2<(*used_colors);color_2++) if (color_1!=color_2) { - difference =abs((short)palette[color_1].R-palette[color_2].R)+ - abs((short)palette[color_1].G-palette[color_2].G)+ - abs((short)palette[color_1].B-palette[color_2].B); + difference =26*abs((long)palette[color_1].R-palette[color_2].R)* + 26*abs((long)palette[color_1].R-palette[color_2].R)+ + 55*abs((long)palette[color_1].G-palette[color_2].G)* + 55*abs((long)palette[color_1].G-palette[color_2].G)+ + 19*abs((long)palette[color_1].B-palette[color_2].B)* + 19*abs((long)palette[color_1].B-palette[color_2].B); if (difference<=best_difference) { @@ -2673,11 +2676,11 @@ void Button_Palette(void) // Close (confirm) clicked_button=14; } - else if (Key == (SDLK_c|MOD_CTRL)) // Ctrl-C + else if (Key == SHORTCUT_COPY) { Set_clipboard_colors(block_end+1-block_start,working_palette + block_start); } - else if (Key == (SDLK_v|MOD_CTRL)) // Ctrl-V + else if (Key == SHORTCUT_PASTE) { int nb_colors; diff --git a/src/readline.c b/src/readline.c index c33d7dfe..dd2953d9 100644 --- a/src/readline.c +++ b/src/readline.c @@ -526,23 +526,30 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz input_key=SDLK_RETURN; // Handle paste request on CTRL+v -#if defined __HAIKU__ - #define SHORTCUTKEY MOD_ALT -#else - #define SHORTCUTKEY MOD_CTRL -#endif - if ((Key & SHORTCUTKEY) && ((Key & 0xFFF) == 'v')) + if (Key == SHORTCUT_PASTE) { + int nb_added; char* data = getClipboard(); if (data == NULL) continue; // No clipboard data - Cleanup_string(data, input_type); + Cleanup_string(data, input_type); // Insert it at the cursor position - position += Prepend_string(str + position, data, max_size - position); + nb_added = Prepend_string(str + position, data, max_size - position); + while (nb_added) + { + size++; + if (size=visible_size) + offset++; + } + nb_added--; + } free(data); goto affichage; } + } while(input_key==0); -#undef SHORTCUTKEY } Hide_cursor(); @@ -639,7 +646,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz if (size