From 4ea23b3e9a541da14d33a287522ca27cdcd28986 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sat, 14 Aug 2010 23:23:10 +0000 Subject: [PATCH] Color cycling based on the ranges in Grad menu. A speed slider has appeared. The speed data (and all cycling) is loaded from IFF/ILBM images from Deluxe Paint, Amiga and DOS versions. The data is not saved at the moment, so you shouldn't re-save cycling images git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1573 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 16 ++++++++-- src/engine.c | 2 ++ src/global.h | 2 ++ src/loadsave.c | 7 +++-- src/main.c | 84 ++++++++++++++++++++++++++++++++++++------------- src/sdlscreen.c | 2 ++ src/sdlscreen.h | 2 ++ src/struct.h | 1 + 8 files changed, 91 insertions(+), 25 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 7a967f88..c1abf945 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -2477,6 +2477,7 @@ void Button_Gradients(void) T_Gradient_array backup_gradients[16]; int old_current_gradient; T_Scroller_button * mix_scroller; + T_Scroller_button * speed_scroller; short old_mouse_x; short old_mouse_y; byte old_mouse_k; @@ -2491,7 +2492,7 @@ void Button_Gradients(void) old_current_gradient=Current_gradient; memcpy(backup_gradients,Gradient_array,sizeof(T_Gradient_array)*16); - Open_window(237,133,"Gradation menu"); + Open_window(258,133,"Gradation menu"); Window_set_palette_button(48,21); // 1 // Définition du scrolleur <=> indice du dégradé dans le tableau @@ -2508,6 +2509,7 @@ void Button_Gradients(void) 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); @@ -2534,6 +2536,8 @@ void Button_Gradients(void) old_mouse_k=Mouse_K; clicked_button=Window_clicked_button(); + if (Input_sticky_control!=8 || !Mouse_K) + Allow_colorcycling=0; switch(clicked_button) { @@ -2602,6 +2606,10 @@ void Button_Gradients(void) mix_scroller->Position=Gradient_array[Current_gradient].Mix; Window_draw_slider(mix_scroller); + // Update speed + speed_scroller->Position=64-Gradient_array[Current_gradient].Speed; + Window_draw_slider(speed_scroller); + // On raffiche la technique qui va avec Draw_button_gradient_style(8,92,Gradient_array[Current_gradient].Technique); @@ -2635,6 +2643,10 @@ void Button_Gradients(void) // On affiche la nouvelle preview Draw_gradient_preview(8,112,108,14,Current_gradient); Display_cursor(); + case 8 : // Speed + Gradient_array[Current_gradient].Speed=64-Window_attribute2; + Allow_colorcycling=1; + break; } if (!Mouse_K) @@ -2670,7 +2682,7 @@ void Button_Gradients(void) clicked_button=6; } } - while (clicked_button<6); + while (clicked_button!=6 && clicked_button!=7); Close_window(); // The Grad rect operation uses the same button as Grad menu. diff --git a/src/engine.c b/src/engine.c index d73a538c..ba2e160b 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1572,6 +1572,7 @@ void Open_window(word width,word height, const char * title) Cursor_shape=CURSOR_SHAPE_ARROW; Paintbrush_hidden_before_window=Paintbrush_hidden; Paintbrush_hidden=1; + Allow_colorcycling=0; } // Initialisation des listes de boutons de la fenêtre @@ -1661,6 +1662,7 @@ void Close_window(void) Display_all_screen(); Display_menu(); + Allow_colorcycling=1; } Key=0; diff --git a/src/global.h b/src/global.h index bb3661fb..ce469e90 100644 --- a/src/global.h +++ b/src/global.h @@ -766,6 +766,8 @@ GFX2_GLOBAL long Gradient_bounds_range; GFX2_GLOBAL long Gradient_total_range; /// Amount of randomness to use in gradient (1-256+) GFX2_GLOBAL long Gradient_random_factor; +/// Gradient speed of cycling (0-64) +GFX2_GLOBAL byte Gradient_speed; /// Pointer to a gradient function, depending on the selected method. GFX2_GLOBAL Func_gradient Gradient_function; /// diff --git a/src/loadsave.c b/src/loadsave.c index 02727b66..e972c9e0 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -134,7 +134,7 @@ void Load_SDL_Image(T_IO_Context *); // ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts T_Format File_formats[NB_KNOWN_FORMATS] = { - {FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;pcx;pkm;lbm;iff;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;kcf;pal;c64;koa;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"}, + {FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;pcx;pkm;lbm;ilbm;iff;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;kcf;pal;c64;koa;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"}, {FORMAT_ALL_FILES, "(*.*)", NULL, NULL, NULL, 0, 0, 0, "", "*"}, {FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 0, 1, 1, "gif", "gif"}, #ifndef __no_pnglib__ @@ -143,7 +143,7 @@ T_Format File_formats[NB_KNOWN_FORMATS] = { {FORMAT_BMP, " bmp", Test_BMP, Load_BMP, Save_BMP, 0, 0, 0, "bmp", "bmp"}, {FORMAT_PCX, " pcx", Test_PCX, Load_PCX, Save_PCX, 0, 0, 0, "pcx", "pcx"}, {FORMAT_PKM, " pkm", Test_PKM, Load_PKM, Save_PKM, 0, 1, 0, "pkm", "pkm"}, - {FORMAT_LBM, " lbm", Test_LBM, Load_LBM, Save_LBM, 0, 0, 0, "lbm", "lbm;iff"}, + {FORMAT_LBM, " lbm", Test_LBM, Load_LBM, Save_LBM, 0, 0, 0, "lbm", "lbm;iff;ilbm"}, {FORMAT_IMG, " img", Test_IMG, Load_IMG, Save_IMG, 0, 0, 0, "img", "img"}, {FORMAT_SCx, " sc?", Test_SCx, Load_SCx, Save_SCx, 0, 0, 0, "sc?", "sci;scq;scf;scn;sco"}, {FORMAT_PI1, " pi1", Test_PI1, Load_PI1, Save_PI1, 0, 0, 0, "pi1", "pi1"}, @@ -776,11 +776,14 @@ void Load_image(T_IO_Context *context) Main_image_height=1; // Color cyling ranges: + for (i=0; i<16; i++) + Gradient_array[i].Speed=0; for (i=0; iColor_cycles; i++) { Gradient_array[i].Start=context->Cycle_range[i].Start; Gradient_array[i].End=context->Cycle_range[i].End; Gradient_array[i].Inverse=context->Cycle_range[i].Inverse; + Gradient_array[i].Speed=context->Cycle_range[i].Speed; } } diff --git a/src/main.c b/src/main.c index 92d87c4f..6972f0c5 100644 --- a/src/main.c +++ b/src/main.c @@ -86,39 +86,81 @@ extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); #endif -int test_colorcycling(void* useless) +int Color_cycling(__attribute__((unused)) void* useless) { - static byte offset[16]; // static forces init at 0 + byte offset[16]; int i, color; static SDL_Color PaletteSDL[256]; + int changed; // boolean : true if the palette needs a change in this tick. + + long now; + long start; while(!Quitting) { - SDL_Delay(50); + start = SDL_GetTicks(); + memset(offset, 0, sizeof(offset)); + // Init palette - for(color=0;color<256;color++) + while (Allow_colorcycling) { - PaletteSDL[color].r=Main_palette[color].R; - PaletteSDL[color].g=Main_palette[color].G; - PaletteSDL[color].b=Main_palette[color].B; - } - for (i=0; i<16; i++) - { - byte len; + now = SDL_GetTicks(); + changed=0; - len=Gradient_array[i].End-Gradient_array[i].Start+1; - if (len) + // Check all cycles for a change at this tick + for (i=0; i<16; i++) { - for(color=Gradient_array[i].Start;color<=Gradient_array[i].End;color++) + int len; + + len=Gradient_array[i].End-Gradient_array[i].Start+1; + if (len>1 && Gradient_array[i].Speed) { - PaletteSDL[color].r=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].R; - PaletteSDL[color].g=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].G; - PaletteSDL[color].b=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].B; + int new_offset; + + new_offset=(now-start)/(int)(1000.0/(Gradient_array[i].Speed*0.2856)) % len; + if (!Gradient_array[i].Inverse) + new_offset=len - new_offset; + + if (new_offset!=offset[i]) + changed=1; + offset[i]=new_offset; } - offset[i]= (offset[i]+len-1)%len; } + + if (changed) + { + // Initialize the palette + for(color=0;color<256;color++) + { + PaletteSDL[color].r=Main_palette[color].R; + PaletteSDL[color].g=Main_palette[color].G; + PaletteSDL[color].b=Main_palette[color].B; + } + for (i=0; i<16; i++) + { + int len; + + len=Gradient_array[i].End-Gradient_array[i].Start+1; + if (len>1 && Gradient_array[i].Speed) + { + for(color=Gradient_array[i].Start;color<=Gradient_array[i].End;color++) + { + PaletteSDL[color].r=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].R; + PaletteSDL[color].g=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].G; + PaletteSDL[color].b=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].B; + } + } + } + SDL_SetPalette(Screen_SDL, SDL_PHYSPAL | SDL_LOGPAL, PaletteSDL,0,256); + } + SDL_Delay(20); + } + // Restore normal palette + Set_palette(Main_palette); + while (!Allow_colorcycling) + { + SDL_Delay(20); } - SDL_SetPalette(Screen_SDL, SDL_PHYSPAL | SDL_LOGPAL, PaletteSDL,0,256); } return 0; } @@ -863,10 +905,10 @@ int Init_program(int argc,char * argv[]) } } -#if 0 +#if 1 // Color cycling test { - SDL_Thread* t = SDL_CreateThread(test_colorcycling, NULL); + SDL_Thread* t = SDL_CreateThread(Color_cycling, NULL); } #endif diff --git a/src/sdlscreen.c b/src/sdlscreen.c index ca701530..93acc0ff 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -47,6 +47,8 @@ #endif #endif +volatile int Allow_colorcycling=1; + /// Sets the new screen/window dimensions. void Set_mode_SDL(int *width, int *height, int fullscreen) { diff --git a/src/sdlscreen.h b/src/sdlscreen.h index a7b83c2e..0b771ec8 100644 --- a/src/sdlscreen.h +++ b/src/sdlscreen.h @@ -65,4 +65,6 @@ void Get_SDL_Palette(const SDL_Palette * sdl_palette, T_Palette palette); /// size, eg: 3x3 pixels in 1024x768 leaves 1 column on the right, 0 rows on bottom. void Clear_border(byte color); +extern volatile int Allow_colorcycling; + #endif // SDLSCREEN_H_INCLUDED diff --git a/src/struct.h b/src/struct.h index adbe7647..fe13766d 100644 --- a/src/struct.h +++ b/src/struct.h @@ -224,6 +224,7 @@ typedef struct dword Inverse; ///< Boolean, true if the gradient goes in descending order dword Mix; ///< Amount of randomness to add to the mix (0-255) dword Technique;///< Gradient technique: 0 (no pattern) 1 (dithering), or 2 (big dithering) + byte Speed; ///< Speed of cycling. 0 for disabled, 1-64 otherwise. } T_Gradient_array; /// Data for one setting of shade. Warning, this one is saved/loaded as binary.