diff --git a/buttons.c b/buttons.c index 82854e33..420a4579 100644 --- a/buttons.c +++ b/buttons.c @@ -70,7 +70,7 @@ #define isHidden(x) ((x)->d_name[0]=='.') #endif -//extern char Program_version[]; // generated in pversion.c +extern char Program_version[]; // generated in pversion.c extern short Old_MX; extern short Old_MY; @@ -793,15 +793,6 @@ void Button_Settings(void) Window_display_frame(163, 16,139,48); // Show in filelist Window_display_frame(253, 77, 49,82); // Mouse sens. Window_display_frame( 5, 65,247,96); // |_ Misc. -/* Window_display_frame( 5, 65,157,14); // | - // On découpe le Frame bizarre des "Miscellaneous" - Pixel_in_window(6,77,MC_White); - Pixel_in_window(5,78,MC_Dark); - Block(Window_pos_X+(7*Menu_factor_X),Window_pos_Y+(77*Menu_factor_Y), - Menu_factor_X*154,Menu_factor_Y<<1,MC_Light); - Pixel_in_window(161,77,MC_Light); - Pixel_in_window(160,77,MC_Dark); -*/ // On affiche maintenant tout le blabla Print_in_window(169, 19,"Show in filelist",MC_Dark,MC_Light); Print_in_window( 9, 52,"Nb of UNDO pages",MC_Dark,MC_Light); @@ -815,7 +806,6 @@ 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); // Button Show/Hide Picture limits Window_set_normal_button( 9, 81,107,14,"Limits : ",0,1,SDLK_LAST); // 3 diff --git a/engine.h b/engine.h index e3de8d0f..94e0704a 100644 --- a/engine.h +++ b/engine.h @@ -49,33 +49,39 @@ void Window_draw_scroller_bouton(T_Scroller_button * button); void Window_input_content(T_Special_button * button, char * content); void Window_clear_input_button(T_Special_button * button); -void Window_draw_input_bouton(word x_pos,word y_pos,word width_in_characters); +void Window_draw_input_bouton(word x_pos, word y_pos, word width_in_characters); T_Normal_button * Window_set_normal_button(word x_pos, word y_pos, - word width, word height, - char * title,byte undersc_letter, - byte clickable, word shortcut); + word width, word height, char * title, byte undersc_letter, + byte clickable, word shortcut); + T_Normal_button * Window_set_repeatable_button(word x_pos, word y_pos, - word width, word height, - char * title,byte undersc_letter, - byte clickable, word shortcut); + word width, word height, char * title, byte undersc_letter, + byte clickable, word shortcut); T_Palette_button * Window_set_palette_button(word x_pos, word y_pos); void Window_clear_tags(void); -void Tag_color_range(byte start,byte end); +void Tag_color_range(byte start, byte end); T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos, word height, word nb_elements, word nb_elements_visible, word initial_position); -T_Special_button * Window_set_special_button(word x_pos,word y_pos,word width, + +T_Special_button * Window_set_special_button(word x_pos, word y_pos, word width, word height); -T_Special_button * Window_set_input_button(word x_pos,word y_pos, + +T_Special_button * Window_set_input_button(word x_pos, word y_pos, word width_in_characters); -T_Dropdown_button * Window_set_dropdown_button(word x_pos,word y_pos,word width, - word height,word dropdown_width,const char *label,byte display_choice, - byte display_centered,byte display_arrow,byte active_button); + +T_Dropdown_button * Window_set_dropdown_button(word x_pos, word y_pos, + word width, word height, word dropdown_width, const char *label, + byte display_choice, byte display_centered, byte display_arrow, + byte active_button); + +/// Adds an item to a dropdown menu void Window_dropdown_add_item(T_Dropdown_button * dropdown, word btn_number, const char *label); + void Window_dropdown_clear_items(T_Dropdown_button * dropdown); T_List_button * Window_set_list_button(T_Special_button * entry_button, T_Scroller_button * scroller, Func_draw_list_item draw_list_item); diff --git a/help.c b/help.c index f5e75e5b..53e39674 100644 --- a/help.c +++ b/help.c @@ -46,6 +46,9 @@ #include "hotkeys.h" #include "errors.h" +extern char Program_version[]; // generated in pversion.c +extern char SVN_revision[]; // generated in pversion.c + // Recherche un raccourci clavier: word * Shortcut(word shortcut_number) { diff --git a/main.c b/main.c index ecb63bb8..ba1f8aaa 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* Grafx2 - The Ultimate 256-color bitmap paint program +/* Grafx1 - The Ultimate 256-color bitmap paint program Copyright 2008 Peter Gordon Copyright 2008 Franck Charlet diff --git a/palette.c b/palette.c index 8a1abb81..0574781a 100644 --- a/palette.c +++ b/palette.c @@ -752,68 +752,81 @@ void Draw_all_palette_sliders(T_Scroller_button * red_slider, void Button_Palette(void) { - static short reducer_index=0; - static short reduce_colors_number=256; - short temp_color; // Variable pouvant reservir pour différents calculs intermédiaires - dword temp; - byte color,click; // Variables pouvant reservir pour différents calculs intermédiaires - short clicked_button; - word old_mouse_x; - word old_mouse_y; - byte old_mouse_k; - byte block_start; - byte block_end; - byte first_color; - byte last_color; - char str[10]; - word i; - //short x_pos,y_pos; + static short reduce_colors_number = 256; + short temp_color; // Variable pouvant reservir pour différents calculs intermédiaires + dword temp; + byte color,click; // Variables pouvant reservir pour différents calculs intermédiaires + short clicked_button; + word old_mouse_x; + word old_mouse_y; + byte old_mouse_k; + byte block_start; + byte block_end; + byte first_color; + byte last_color; + char str[10]; + word i; T_Normal_button * button_used; T_Scroller_button * red_slider; T_Scroller_button * green_slider; T_Scroller_button * blue_slider; - T_Scroller_button * reduce_slider; - byte image_is_backed_up=0; - byte need_to_remap=0; + T_Dropdown_button * reduce_dropdown; + byte image_is_backed_up = 0; + byte need_to_remap = 0; dword color_usage[256]; - short used_colors=-1; // -1 <=> Inconnu + short used_colors = -1; // -1 <=> Inconnu byte conversion_table[256]; T_Components * backup_palette; T_Components * temp_palette; T_Components * working_palette; - backup_palette =(T_Components *)malloc(sizeof(T_Palette)); + backup_palette =(T_Components *)malloc(sizeof(T_Palette)); temp_palette=(T_Components *)malloc(sizeof(T_Palette)); working_palette=(T_Components *)malloc(sizeof(T_Palette)); Componant_unit(RGB_scale); - Open_window(299,188,"Palette"); + Open_window(299, 188,"Palette"); - memcpy(working_palette,Main_palette,sizeof(T_Palette)); - memcpy(backup_palette ,Main_palette,sizeof(T_Palette)); - memcpy(temp_palette,Main_palette,sizeof(T_Palette)); + memcpy(working_palette, Main_palette, sizeof(T_Palette)); + memcpy(backup_palette, Main_palette, sizeof(T_Palette)); + memcpy(temp_palette, Main_palette, sizeof(T_Palette)); - Window_set_palette_button(5,79); // 1 + Window_set_palette_button(5, 79); // 1 - Window_display_frame (173, 67,121,116); - Window_display_frame (128, 16, 91, 39); - Window_display_frame (221, 16, 73, 39); - // Frame creux destiné à l'affichage de la(les) couleur(s) sélectionnée(s) - Window_display_frame_in(259, 88, 26, 74); + Window_display_frame (173, 67, 121, 116); + Window_display_frame (128, 16, 91, 39); // Graduation des jauges de couleur - Block(Window_pos_X+(Menu_factor_X*179),Window_pos_Y+(Menu_factor_Y*109),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*206),Window_pos_Y+(Menu_factor_Y*109),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*233),Window_pos_Y+(Menu_factor_Y*109),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*179),Window_pos_Y+(Menu_factor_Y*125),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*206),Window_pos_Y+(Menu_factor_Y*125),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*233),Window_pos_Y+(Menu_factor_Y*125),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*179),Window_pos_Y+(Menu_factor_Y*141),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*206),Window_pos_Y+(Menu_factor_Y*141),Menu_factor_X*17,Menu_factor_Y,MC_Dark); - Block(Window_pos_X+(Menu_factor_X*233),Window_pos_Y+(Menu_factor_Y*141),Menu_factor_X*17,Menu_factor_Y,MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 179), + Window_pos_Y + (Menu_factor_Y * 109), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 206), + Window_pos_Y + (Menu_factor_Y * 109), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 233), + Window_pos_Y + (Menu_factor_Y * 109), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 179), + Window_pos_Y + (Menu_factor_Y * 125), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 206), + Window_pos_Y + (Menu_factor_Y * 125), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 233), + Window_pos_Y + (Menu_factor_Y * 125), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 179), + Window_pos_Y + (Menu_factor_Y * 141), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 206), + Window_pos_Y + (Menu_factor_Y * 141), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); + Block(Window_pos_X + (Menu_factor_X * 233), + Window_pos_Y + (Menu_factor_Y * 141), Menu_factor_X * 17, Menu_factor_Y, + MC_Dark); // Jauges de couleur red_slider = Window_set_scroller_button(182, 81, 88,Color_count,1,Color_max-working_palette[Fore_color].R*Color_max/255);// 2 green_slider = Window_set_scroller_button(209, 81, 88,Color_count,1,Color_max-working_palette[Fore_color].G*Color_max/255);// 3 @@ -853,8 +866,16 @@ void Button_Palette(void) Window_set_normal_button(66,32,29,14,"Cpy" ,1,1,SDLK_c); // 9 Window_set_normal_button( 6,32,59,14,"Spread" ,4,1,SDLK_e); // 10 - Window_set_normal_button(239,20,51,14,"Reduce" ,1,1,SDLK_r); // 11 - Print_in_window(241,41,"to",MC_Dark,MC_Light); + reduce_dropdown = Window_set_dropdown_button(222, 18, 60, 14, 60, "Reduce", 0, + 0, 1, 1); // 11 + Window_dropdown_add_item(reduce_dropdown, 0, "to 128"); + Window_dropdown_add_item(reduce_dropdown, 1, "to 64"); + Window_dropdown_add_item(reduce_dropdown, 2, "to 32"); + Window_dropdown_add_item(reduce_dropdown, 3, "to 16"); + Window_dropdown_add_item(reduce_dropdown, 4, "to 8"); + Window_dropdown_add_item(reduce_dropdown, 5, "to 4"); + Window_dropdown_add_item(reduce_dropdown, 6, "to 2"); + Window_dropdown_add_item(reduce_dropdown, 7, "Other"); Window_set_normal_button( 6,168,35,14,"Undo" ,1,1,SDLK_u); // 12 Window_set_normal_button( 62,168,51,14,"Cancel",0,1,KEY_ESC); // 13 @@ -863,23 +884,15 @@ void Button_Palette(void) button_used = Window_set_normal_button(132,20,83,14,"Used: ???",4,1,SDLK_d);// 15 Window_set_normal_button(132,37,83,14,"Zap unused",0,1,SDLK_DELETE);//16 - // Jauge de réduction de palette - reduce_slider = Window_set_scroller_button(225,20,31,7,1,reducer_index);// 17 + Window_set_repeatable_button(266, 74,12,11,"+",0,1,SDLK_KP_PLUS); // 17 + Window_set_repeatable_button(266,165,12,11,"-",0,1,SDLK_KP_MINUS); // 18 - Window_set_repeatable_button(266, 74,12,11,"+",0,1,SDLK_KP_PLUS); // 18 - Window_set_repeatable_button(266,165,12,11,"-",0,1,SDLK_KP_MINUS); // 19 + Window_set_normal_button(96,17,29,14,"Neg" ,1,1,SDLK_n); // 19 + Window_set_normal_button(66,62,29,14,"Inv" ,1,1,SDLK_i); // 20 + Window_set_normal_button( 6,62,59,14,"X-Inv." ,5,1,SDLK_v); // 21 - Window_set_normal_button(96,17,29,14,"Neg" ,1,1,SDLK_n); // 20 - Window_set_normal_button(66,62,29,14,"Inv" ,1,1,SDLK_i); // 21 - Window_set_normal_button( 6,62,59,14,"X-Inv." ,5,1,SDLK_v); // 22 - - Window_set_input_button(263,39,3); // 23 - - Window_set_normal_button(96,32,29,14,"HSL" ,1,1,SDLK_h); // 24 - Window_set_normal_button(96,47,29,14,"Srt" ,1,1,SDLK_s); // 25 - // Affichage du facteur de réduction de la palette - Num2str(reduce_colors_number,str,3); - Print_in_window(265,41,str,MC_Black,MC_Light); + Window_set_normal_button(96,32,29,14,"HSL" ,1,1,SDLK_h); // 22 + Window_set_normal_button(96,47,29,14,"Srt" ,1,1,SDLK_s); // 23 // Dessin des petits effets spéciaux pour les boutons [+] et [-] Draw_thingumajig(263, 74,MC_White,-1); @@ -1400,29 +1413,64 @@ void Button_Palette(void) break; case 11: // Reduce - memcpy(backup_palette,working_palette,sizeof(T_Palette)); + memcpy(backup_palette, working_palette, sizeof(T_Palette)); + switch(Window_attribute2) // Get the dropdown value + { + case 0: // 128 + reduce_colors_number = 128; + break; + case 1: // 64 + reduce_colors_number = 64; + break; + case 2: // 32 + reduce_colors_number = 32; + break; + case 3: // 16 + reduce_colors_number = 16; + break; + case 4: // 8 + reduce_colors_number = 8; + break; + case 5: // 4 + reduce_colors_number = 4; + break; + case 6: // 2 + reduce_colors_number = 2; + break; + case 7: // other + reduce_colors_number + = Requester_window("Enter the max. number of colors", + reduce_colors_number); + if (reduce_colors_number < 2 || reduce_colors_number > 256) + reduce_colors_number = 256; + break; + } + if (!image_is_backed_up) { Backup(); - image_is_backed_up=1; + image_is_backed_up = 1; } - Reduce_palette(&used_colors,reduce_colors_number,working_palette,color_usage); + + Reduce_palette(&used_colors, reduce_colors_number, working_palette, + color_usage); if ((Config.Safety_colors) && (used_colors<4)) { - memcpy(temp_palette,Main_palette,sizeof(T_Palette)); - memcpy(Main_palette,working_palette,sizeof(T_Palette)); - Set_nice_menu_colors(color_usage,0); - memcpy(working_palette,Main_palette,sizeof(T_Palette)); - memcpy(Main_palette,temp_palette,sizeof(T_Palette)); + memcpy(temp_palette, Main_palette, sizeof(T_Palette)); + memcpy(Main_palette, working_palette, sizeof(T_Palette)); + Set_nice_menu_colors(color_usage, 0); + memcpy(working_palette, Main_palette, sizeof(T_Palette)); + memcpy(Main_palette, temp_palette, sizeof(T_Palette)); } - Set_palette(working_palette); // On définit la nouvelle palette - Draw_all_palette_sliders(red_slider,green_slider,blue_slider,working_palette,block_start,block_end); - memcpy(temp_palette,working_palette,sizeof(T_Palette)); + Set_palette(working_palette); // On définit la nouvelle palette + Draw_all_palette_sliders(red_slider, green_slider, blue_slider, + working_palette, block_start, block_end); + memcpy(temp_palette, working_palette, sizeof(T_Palette)); End_of_modification(); - need_to_remap=1; + need_to_remap = 1; break; case 12: // Undo @@ -1470,19 +1518,7 @@ void Button_Palette(void) need_to_remap=1; break; - case 17 : // Jauge de réduction de palette - if (reducer_index!=reduce_slider->Position) - { - reducer_index=reduce_slider->Position; - // Affichage du facteur de réduction de la palette - Hide_cursor(); - Print_in_window(265,41,Palette_reduce_label[reducer_index],MC_Black,MC_Light); - Display_cursor(); - reduce_colors_number=atoi(Palette_reduce_label[reducer_index]); - } - break; - - case 18 : // [+] + case 17 : // [+] if (!Palette_view_is_RGB) break; Hide_cursor(); @@ -1607,7 +1643,7 @@ void Button_Palette(void) Set_palette(working_palette); break; - case 19 : // [-] + case 18 : // [-] if (!Palette_view_is_RGB) break; Hide_cursor(); @@ -1732,7 +1768,7 @@ void Button_Palette(void) Set_palette(working_palette); break; - case 20 : // Negative + case 19 : // Negative // Backup memcpy(backup_palette,working_palette,sizeof(T_Palette)); // Negative @@ -1750,8 +1786,8 @@ void Button_Palette(void) need_to_remap=1; break; - case 21 : // Inversion - case 22 : // X-Inversion + case 20 : // Inversion + case 21 : // X-Inversion // Backup memcpy(backup_palette,working_palette,sizeof(T_Palette)); // On initialise la table de conversion @@ -1795,30 +1831,7 @@ void Button_Palette(void) need_to_remap=1; break; - case 23 : // Saisie du nombre de couleurs pour la réduction de palette - Num2str(reduce_colors_number,str,3); - - if (Readline(265,41,str,3,1)) - { - temp_color=atoi(str); - // Correction de la valeur lue - if ( (temp_color>256) || (temp_color<2) ) - { - if (temp_color>256) - temp_color=256; - else - temp_color=2; - - Num2str(temp_color,str,3); - Window_input_content(Window_special_button_list,str); - } - - reduce_colors_number=temp_color; - } - Display_cursor(); - break; - - case 24 : // HSL <> RGB + case 22 : // HSL <> RGB // Acte les changements en cours sur une ou plusieurs couleurs memcpy(temp_palette,working_palette,sizeof(T_Palette)); @@ -1854,7 +1867,7 @@ void Button_Palette(void) Update_window_area(265,73,14,103); break; - case 25 : // Sort palette + case 23 : // Sort palette { byte h = 0, l = 0, s=0; byte oh=0,ol=0,os=0; // Valeur pour la couleur précédente diff --git a/windows.c b/windows.c index a22377e1..52b3b1a9 100644 --- a/windows.c +++ b/windows.c @@ -26,13 +26,15 @@ #include // strncpy() strlen() #include "windows.h" + +#include "engine.h" +#include "errors.h" #include "global.h" #include "graph.h" -#include "engine.h" -#include "misc.h" -#include "sdlscreen.h" -#include "errors.h" #include "input.h" +#include "misc.h" +#include "readline.h" +#include "sdlscreen.h" // L'encapsulation tente une percée...ou un dernier combat. @@ -836,6 +838,47 @@ byte Confirmation_box(char * message) } +/// Window that allows you to enter a single value +int Requester_window(char* message, int initial_value) +{ + short clicked_button = 0; + word window_width; + char str[10]; + + window_width=(strlen(message)<<3)+20; + + if (window_width<120) + window_width = 120; + + Open_window(window_width, 60, "Request"); + + Print_in_window((window_width>>1)-(strlen(message)<<2), 20, message, + MC_Black, MC_Light); + sprintf(str, "%d", initial_value); + Window_set_input_button((window_width / 3) - 20, 37, 10); // 1 + Print_in_window((window_width / 3) - 18, 39, str, MC_Black, MC_Light); + + Update_rect(Window_pos_X, Window_pos_Y, Menu_factor_X * window_width, + Menu_factor_Y * 60); + Display_cursor(); + + do + { + clicked_button = Window_clicked_button(); + if (clicked_button == 1) + Readline((window_width / 3) - 18, 39, str, 10, 1); + if (Key == SDLK_ESCAPE) clicked_button = 2; + } + while (clicked_button <= 0); + + Key = 0; + + Close_window(); + Display_cursor(); + + return clicked_button==2?-1:atoi(str); +} + /// Window that show a warning message and wait for a click on the OK button void Warning_message(char * message) diff --git a/windows.h b/windows.h index 7feff36f..d87b3bb6 100644 --- a/windows.h +++ b/windows.h @@ -71,6 +71,7 @@ void Print_counter(short x,short y,const char * str,byte text_color,byte backgro byte Confirmation_box(char * message); void Warning_message(char * message); void Verbose_error_message(char * message); +int Requester_window(char* message, int initial_value); void Display_image_limits(void); void Display_all_screen(void);