From 97060bc146de68156e29edfad1f87d0aa4a36ae2 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sun, 29 Aug 2010 23:56:42 +0000 Subject: [PATCH] Improved Gradation menu for cycling colors, including a horizontal scrollbar. Added helpfile. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1598 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 93 ++++++++++++++++++++++++++-------------- src/engine.c | 114 +++++++++++++++++++++++++++++++++++-------------- src/engine.h | 2 +- src/helpfile.h | 22 ++++++++++ 4 files changed, 167 insertions(+), 64 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 4b6e0d4b..da6ff168 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -2506,34 +2506,44 @@ void Button_Gradients(void) byte color; byte click; int changed_gradient_index; + byte cycling_mode=Cycling_mode; + // Enable cycling while this window is open + Cycling_mode=1; Gradient_pixel=Pixel; old_current_gradient=Current_gradient; changed_gradient_index=0; memcpy(backup_gradients,Gradient_array,sizeof(T_Gradient_array)*16); - Open_window(258,133,"Gradation menu"); + Open_window(235,146,"Gradation menu"); - Window_set_palette_button(48,21); // 1 - // Définition du scrolleur <=> indice du dégradé dans le tableau - gradient_scroller=Window_set_scroller_button(218,22,75,16,1,Current_gradient); // 2 - // Définition du scrolleur de mélange du dégradé - mix_scroller = Window_set_scroller_button(31,22,84,256,1, + Window_set_palette_button(48,19); // 1 + // Slider for gradient selection + gradient_scroller=Window_set_scroller_button(218,20,75,16,1,Current_gradient); // 2 + // Slider for mix + mix_scroller = Window_set_scroller_button(31,20,84,256,1, Gradient_array[Current_gradient].Mix); // 3 - // Définition du bouton de sens - Window_set_normal_button(8,22,15,14, + // Direction + Window_set_normal_button(8,20,15,14, (Gradient_array[Current_gradient].Inverse)?"\033":"\032",0,1,SDLK_TAB); // 4 - // Définition du bouton de technique - Window_set_normal_button(8,92,15,14,"",0,1,SDLK_TAB|MOD_SHIFT); // 5 - Draw_button_gradient_style(8,92,Gradient_array[Current_gradient].Technique); + // Technique + Window_set_normal_button(8,90,15,14,"",0,1,SDLK_TAB|MOD_SHIFT); // 5 + Draw_button_gradient_style(8,90,Gradient_array[Current_gradient].Technique); - Window_set_normal_button(178,112,51,14,"OK",0,1,SDLK_RETURN); // 6 - Window_set_normal_button(123,112,51,14,"Cancel",0,1,KEY_ESC); // 7 - speed_scroller = Window_set_scroller_button(238,22,88,65,1,64-Gradient_array[Current_gradient].Speed); // 8 - - Print_in_window(5,60,"MIX",MC_Dark,MC_Light); + Window_set_normal_button(178,128,51,14,"OK",0,1,SDLK_RETURN); // 6 + Window_set_normal_button(123,128,51,14,"Cancel",0,1,KEY_ESC); // 7 + // Scrolling speed + speed_scroller = Window_set_horizontal_scroller_button(76,111,88,65,1,Gradient_array[Current_gradient].Speed); // 8 + Num2str(Gradient_array[Current_gradient].Speed,str,2); + Print_in_window(169,113,str,MC_Black,MC_Light); + + Print_in_window(5,58,"MIX",MC_Dark,MC_Light); + // Cycling mode on/off + Window_set_normal_button(8,109,62,14,"",0,1,KEY_NONE); // 9 + Print_in_window(11,112,"Cycling",cycling_mode?MC_Black:MC_Dark,MC_Light); + // On tagge les couleurs qui vont avec Tag_color_range(Gradient_array[Current_gradient].Start,Gradient_array[Current_gradient].End); @@ -2541,9 +2551,9 @@ void Button_Gradients(void) Print_in_window(215,100,str,MC_Black,MC_Light); // On affiche le cadre autour de la préview - Window_display_frame_in(7,111,110,16); + Window_display_frame_in(7,127,110,16); // On affiche la preview - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); first_color=last_color=(Gradient_array[Current_gradient].Inverse)?Gradient_array[Current_gradient].End:Gradient_array[Current_gradient].Start; Update_window_area(0,0,Window_width, Window_height); @@ -2570,25 +2580,27 @@ void Button_Gradients(void) Tag_color_range(Gradient_array[Current_gradient].Start,Gradient_array[Current_gradient].End); // On affiche le sens qui va avec - Print_in_window(12,25,(Gradient_array[Current_gradient].Inverse)?"\033":"\032",MC_Black,MC_Light); + Print_in_window(12,23,(Gradient_array[Current_gradient].Inverse)?"\033":"\032",MC_Black,MC_Light); // On raffiche le mélange (jauge) qui va avec mix_scroller->Position=Gradient_array[Current_gradient].Mix; Window_draw_slider(mix_scroller); // Update speed - speed_scroller->Position=64-Gradient_array[Current_gradient].Speed; + speed_scroller->Position=Gradient_array[Current_gradient].Speed; Window_draw_slider(speed_scroller); + Num2str(Gradient_array[Current_gradient].Speed,str,2); + Print_in_window(169,113,str,MC_Black,MC_Light); // Gradient # gradient_scroller->Position=Current_gradient; Window_draw_slider(gradient_scroller); // Technique (flat, dithered, very dithered) - Draw_button_gradient_style(8,92,Gradient_array[Current_gradient].Technique); + Draw_button_gradient_style(8,90,Gradient_array[Current_gradient].Technique); // Rectangular gradient preview - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); Display_cursor(); } @@ -2615,7 +2627,7 @@ void Button_Gradients(void) // On tagge le bloc Tag_color_range(Gradient_array[Current_gradient].Start,Gradient_array[Current_gradient].End); // Tracé de la preview: - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); } else { @@ -2638,7 +2650,7 @@ void Button_Gradients(void) // On tagge le bloc Tag_color_range(Gradient_array[Current_gradient].Start,Gradient_array[Current_gradient].End); // Tracé de la preview: - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); last_color=temp_color; } } @@ -2655,7 +2667,7 @@ void Button_Gradients(void) // Nouvel mélange dans Window_attribute2 Gradient_array[Current_gradient].Mix=Window_attribute2; // On affiche la nouvelle preview - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); Display_cursor(); break; case 4 : // Changement de sens @@ -2664,21 +2676,31 @@ void Button_Gradients(void) Gradient_array[Current_gradient].Inverse^=1; Print_in_window(12,25,(Gradient_array[Current_gradient].Inverse)?"\033":"\032",MC_Black,MC_Light); // On affiche la nouvelle preview - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); Display_cursor(); break; case 5 : // Changement de technique Hide_cursor(); // On change la technique par (+1)%3 Gradient_array[Current_gradient].Technique=(Gradient_array[Current_gradient].Technique+1)%3; - Draw_button_gradient_style(8,92,Gradient_array[Current_gradient].Technique); + Draw_button_gradient_style(8,90,Gradient_array[Current_gradient].Technique); // On affiche la nouvelle preview - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); Display_cursor(); case 8 : // Speed - Gradient_array[Current_gradient].Speed=64-Window_attribute2; + Gradient_array[Current_gradient].Speed=Window_attribute2; + Num2str(Gradient_array[Current_gradient].Speed,str,2); + Hide_cursor(); + Print_in_window(169,113,str,MC_Black,MC_Light); + Display_cursor(); Allow_colorcycling=1; break; + case 9: // Cycling on/off + cycling_mode = !cycling_mode; + Hide_cursor(); + Print_in_window(11,112,"Cycling",cycling_mode?MC_Black:MC_Dark,MC_Light); + Display_cursor(); + break; } if (!Mouse_K) @@ -2697,7 +2719,7 @@ void Button_Gradients(void) // On tagge le bloc Tag_color_range(Gradient_array[Current_gradient].Start,Gradient_array[Current_gradient].End); // Tracé de la preview: - Draw_gradient_preview(8,112,108,14,Current_gradient); + Draw_gradient_preview(8,128,108,14,Current_gradient); Display_cursor(); Wait_end_of_click(); } @@ -2725,8 +2747,16 @@ void Button_Gradients(void) Key=0; break; } - if (Is_shortcut(Key,0x200+BUTTON_GRADRECT)) + else if (Is_shortcut(Key,0x200+BUTTON_GRADRECT)) clicked_button=6; + else if (Is_shortcut(Key,SPECIAL_CYCLE_MODE)) + { + // Cycling on/off + cycling_mode = !cycling_mode; + Hide_cursor(); + Print_in_window(11,112,"Cycling",cycling_mode?MC_Black:MC_Dark,MC_Light); + Display_cursor(); + } } } while (clicked_button!=6 && clicked_button!=7); @@ -2739,6 +2769,7 @@ void Button_Gradients(void) Display_cursor(); Gradient_pixel=Display_pixel; + Cycling_mode=cycling_mode; if (clicked_button==7) // Cancel { Current_gradient=old_current_gradient; diff --git a/src/engine.c b/src/engine.c index b1bd43b6..b76632f2 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1857,32 +1857,66 @@ void Window_draw_slider(T_Scroller_button * button) { word slider_position; - slider_position=button->Pos_Y+12; - - Block(Window_pos_X+(button->Pos_X*Menu_factor_X), - Window_pos_Y+(slider_position*Menu_factor_Y), - 11*Menu_factor_X,(button->Length-24)*Menu_factor_Y,MC_Black/*MC_Dark*/); - - if (button->Nb_elements>button->Nb_visibles) - slider_position+=Round_div(button->Position*(button->Length-24-button->Cursor_length),button->Nb_elements-button->Nb_visibles); - - Block(Window_pos_X+(button->Pos_X*Menu_factor_X), - Window_pos_Y+(slider_position*Menu_factor_Y), - 11*Menu_factor_X,button->Cursor_length*Menu_factor_Y,MC_OnBlack/*MC_White*/); - - Update_rect(Window_pos_X+(button->Pos_X*Menu_factor_X), - Window_pos_Y+button->Pos_Y*Menu_factor_Y, - 11*Menu_factor_X,(button->Length)*Menu_factor_Y); + if (button->Is_horizontal) + { + slider_position=button->Pos_X+12; + + Window_rectangle(slider_position, + button->Pos_Y, + button->Length-24,11,MC_Black/*MC_Dark*/); + + if (button->Nb_elements>button->Nb_visibles) + slider_position+=Round_div(button->Position*(button->Length-24-button->Cursor_length),button->Nb_elements-button->Nb_visibles); + + Window_rectangle(slider_position, + button->Pos_Y, + button->Cursor_length,11,MC_OnBlack/*MC_White*/); + + Update_window_area(button->Pos_X, + button->Pos_Y, + button->Length,11); + } + else + { + slider_position=button->Pos_Y+12; + + Window_rectangle(button->Pos_X, + slider_position, + 11,button->Length-24,MC_Black/*MC_Dark*/); + + if (button->Nb_elements>button->Nb_visibles) + slider_position+=Round_div(button->Position*(button->Length-24-button->Cursor_length),button->Nb_elements-button->Nb_visibles); + + Window_rectangle(button->Pos_X, + slider_position, + 11,button->Cursor_length,MC_OnBlack/*MC_White*/); + + Update_window_area(button->Pos_X, + button->Pos_Y, + 11,button->Length); + } } -void Window_draw_scroller_bouton(T_Scroller_button * button) +void Window_draw_scroller_button(T_Scroller_button * button) { - Window_display_frame_generic(button->Pos_X-1,button->Pos_Y-1,13,button->Length+2,MC_Black,MC_Black,MC_Dark,MC_Dark,MC_Dark); - Window_display_frame_mono(button->Pos_X-1,button->Pos_Y+11,13,button->Length-22,MC_Black); - Window_display_frame_out(button->Pos_X,button->Pos_Y,11,11); - Window_display_frame_out(button->Pos_X,button->Pos_Y+button->Length-11,11,11); - Print_in_window(button->Pos_X+2,button->Pos_Y+2,"\030",MC_Black,MC_Light); - Print_in_window(button->Pos_X+2,button->Pos_Y+button->Length-9,"\031",MC_Black,MC_Light); + if (button->Is_horizontal) + { + Window_display_frame_generic(button->Pos_X-1,button->Pos_Y-1,button->Length+2,13,MC_Black,MC_Black,MC_Dark,MC_Dark,MC_Dark); + Window_display_frame_mono(button->Pos_X+11,button->Pos_Y-1,button->Length-22,13,MC_Black); + Window_display_frame_out(button->Pos_X,button->Pos_Y,11,11); + Window_display_frame_out(button->Pos_X+button->Length-11,button->Pos_Y,11,11); + Print_in_window(button->Pos_X+2,button->Pos_Y+2,"\033",MC_Black,MC_Light); + Print_in_window(button->Pos_X+button->Length-9,button->Pos_Y+2,"\032",MC_Black,MC_Light); + } + else + { + Window_display_frame_generic(button->Pos_X-1,button->Pos_Y-1,13,button->Length+2,MC_Black,MC_Black,MC_Dark,MC_Dark,MC_Dark); + Window_display_frame_mono(button->Pos_X-1,button->Pos_Y+11,13,button->Length-22,MC_Black); + Window_display_frame_out(button->Pos_X,button->Pos_Y,11,11); + Window_display_frame_out(button->Pos_X,button->Pos_Y+button->Length-11,11,11); + Print_in_window(button->Pos_X+2,button->Pos_Y+2,"\030",MC_Black,MC_Light); + Print_in_window(button->Pos_X+2,button->Pos_Y+button->Length-9,"\031",MC_Black,MC_Light); + } Window_draw_slider(button); } @@ -2010,7 +2044,7 @@ T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos, temp->Next=Window_scroller_button_list; Window_scroller_button_list=temp; - Window_draw_scroller_bouton(temp); + Window_draw_scroller_button(temp); return temp; } @@ -2036,7 +2070,7 @@ T_Scroller_button * Window_set_horizontal_scroller_button(word x_pos, word y_pos temp->Next=Window_scroller_button_list; Window_scroller_button_list=temp; - Window_draw_scroller_bouton(temp); + Window_draw_scroller_button(temp); return temp; } @@ -2902,12 +2936,16 @@ short Window_get_clicked_button(void) // Button Down arrow if ((Input_sticky_control == 0 || Input_sticky_control == (temp3->Number|2048)) - && Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,temp3->Pos_X+10,temp3->Pos_Y+temp3->Length-1)) + && ((temp3->Is_horizontal && Window_click_in_rectangle(temp3->Pos_X+temp3->Length-11,temp3->Pos_Y,temp3->Pos_X+temp3->Length-1,temp3->Pos_Y+10)) + || (!temp3->Is_horizontal && Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,temp3->Pos_X+10,temp3->Pos_Y+temp3->Length-1)))) { Input_sticky_control = temp3->Number | 2048; Hide_cursor(); - Window_select_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,11,11); - + if (temp3->Is_horizontal) + Window_select_normal_button(temp3->Pos_X+temp3->Length-11,temp3->Pos_Y,11,11); + else + Window_select_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,11,11); + if (temp3->Position+temp3->Nb_visiblesNb_elements) { temp3->Position++; @@ -2923,14 +2961,18 @@ short Window_get_clicked_button(void) Delay_with_active_mouse((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); Hide_cursor(); - Window_unselect_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,11,11); + if (temp3->Is_horizontal) + Window_unselect_normal_button(temp3->Pos_X+temp3->Length-11,temp3->Pos_Y,11,11); + else + Window_unselect_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Length-11,11,11); Display_cursor(); return (Window_attribute1)? temp3->Number : 0; } // Middle slider if ((Input_sticky_control == temp3->Number) || (Input_sticky_control==0 && - Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+12,temp3->Pos_X+10,temp3->Pos_Y+temp3->Length-13))) + ((!temp3->Is_horizontal && Window_click_in_rectangle(temp3->Pos_X,temp3->Pos_Y+12,temp3->Pos_X+10,temp3->Pos_Y+temp3->Length-13)) + ||(temp3->Is_horizontal && Window_click_in_rectangle(temp3->Pos_X+12,temp3->Pos_Y,temp3->Pos_X+temp3->Length-13,temp3->Pos_Y+10))))) { Input_sticky_control = temp3->Number; if (temp3->Nb_elements>temp3->Nb_visibles) @@ -2940,8 +2982,16 @@ short Window_get_clicked_button(void) max_slider_height=(temp3->Length-24); // Window_attribute2 receives the position of the cursor. - Window_attribute2 =(Mouse_Y-Window_pos_Y) / Menu_factor_Y; - Window_attribute2-=(temp3->Pos_Y+12+((temp3->Cursor_length-1)>>1)); + if (temp3->Is_horizontal) + { + Window_attribute2 =(Mouse_X-Window_pos_X) / Menu_factor_X; + Window_attribute2-=(temp3->Pos_X+12+((temp3->Cursor_length-1)>>1)); + } + else + { + Window_attribute2 =(Mouse_Y-Window_pos_Y) / Menu_factor_Y; + Window_attribute2-=(temp3->Pos_Y+12+((temp3->Cursor_length-1)>>1)); + } Window_attribute2*=(temp3->Nb_elements-temp3->Nb_visibles); if (Window_attribute2<0) diff --git a/src/engine.h b/src/engine.h index c55ec378..03755e7d 100644 --- a/src/engine.h +++ b/src/engine.h @@ -47,7 +47,7 @@ void Window_draw_palette_bouton(word x_pos,word y_pos); void Compute_slider_cursor_length(T_Scroller_button * button); void Window_draw_slider(T_Scroller_button * button); -void Window_draw_scroller_bouton(T_Scroller_button * button); +void Window_draw_scroller_button(T_Scroller_button * button); void Window_input_content(T_Special_button * button, char * content); void Window_clear_input_button(T_Special_button * button); diff --git a/src/helpfile.h b/src/helpfile.h index 1b398bb9..7bb40ac5 100644 --- a/src/helpfile.h +++ b/src/helpfile.h @@ -156,6 +156,7 @@ static const T_Help_table helptable_help[] = HELP_LINK ("Filled polyform: %s", 0x200+BUTTON_POLYFILL) HELP_LINK ("Gradient rectangle: %s", 0x100+BUTTON_GRADRECT) HELP_LINK ("Gradation menu: %s", 0x200+BUTTON_GRADRECT) + HELP_LINK ("Toggle color cycling:%s", SPECIAL_CYCLE_MODE) HELP_LINK ("Spheres: %s", 0x100+BUTTON_SPHERES) HELP_LINK ("Gradient ellipses: %s", 0x200+BUTTON_SPHERES) HELP_LINK ("Adjust picture: %s", 0x100+BUTTON_ADJUST) @@ -1133,6 +1134,27 @@ static const T_Help_table helptable_grad_rect[] = HELP_TEXT ("- Index scroller: Defines the current") HELP_TEXT ("gradation among a set of 16 that will be") HELP_TEXT ("memorised.") + HELP_TEXT ("") + HELP_BOLD ("COLOR CYCLING") + HELP_TEXT ("") + HELP_TEXT ("These options allow you to use animation of") + HELP_TEXT ("colors: Grafx2 will shift palette entries") + HELP_TEXT ("at real-time. Note that only the LBM file") + HELP_TEXT ("format can record these settings, and very") + HELP_TEXT ("few image viewers will play it back.") + HELP_TEXT ("") + HELP_TEXT ("- Cycling: Activates or desactivates the") + HELP_TEXT ("cycling of colors when you're in the editor.") + HELP_LINK ("Key: %s", SPECIAL_CYCLE_MODE) + HELP_TEXT ("") + HELP_TEXT ("- Speed: Sets the speed for the cycling of") + HELP_TEXT ("this range. Zero means this range doesn't") + HELP_TEXT ("cycle. With 1, the range shifts 0.2856 times") + HELP_TEXT ("per second; at speed 64 it's 18.28 times") + HELP_TEXT ("per second. The program activates cycling") + HELP_TEXT ("while you hold the speed slider, so you can") + HELP_TEXT ("preview the speed.") + HELP_TEXT ("") }; static const T_Help_table helptable_spheres[] = {