diff --git a/src/Makefile.dep b/src/Makefile.dep index 73930c02..82d0e417 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep @@ -1,3 +1,4 @@ +$(OBJDIR)/SFont.o: SFont.c SFont.h $(OBJDIR)/brush.o: brush.c global.h struct.h const.h graph.h misc.h errors.h \ windows.h sdlscreen.h brush.h $(OBJDIR)/brush_ops.o: brush_ops.c brush.h struct.h const.h buttons.h engine.h \ @@ -10,7 +11,7 @@ $(OBJDIR)/buttons_effects.o: buttons_effects.c buttons.h struct.h const.h engine global.h graph.h help.h input.h misc.h readline.h sdlscreen.h windows.h $(OBJDIR)/engine.o: engine.c const.h struct.h global.h graph.h misc.h special.h \ buttons.h operatio.h shade.h errors.h sdlscreen.h windows.h brush.h \ - input.h engine.h pages.h layers.h + input.h engine.h pages.h layers.h factory.h $(OBJDIR)/factory.o: factory.c brush.h struct.h const.h buttons.h engine.h errors.h \ filesel.h loadsave.h global.h graph.h io.h misc.h pages.h readline.h \ sdlscreen.h windows.h palette.h input.h help.h @@ -47,7 +48,7 @@ $(OBJDIR)/misc.o: misc.c struct.h const.h sdlscreen.h global.h errors.h buttons. engine.h misc.h keyboard.h windows.h palette.h input.h graph.h pages.h $(OBJDIR)/miscfileformats.o: miscfileformats.c engine.h struct.h const.h errors.h \ global.h io.h libraw2crtc.h loadsave.h misc.h sdlscreen.h windows.h -$(OBJDIR)/mountlist.o: mountlist.c mountlist.h +$(OBJDIR)/mountlist.o: mountlist.c $(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h errors.h $(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h misc.h engine.h graph.h \ operatio.h buttons.h pages.h errors.h sdlscreen.h brush.h windows.h @@ -63,16 +64,16 @@ $(OBJDIR)/pxquad.o: pxquad.c global.h struct.h const.h sdlscreen.h misc.h graph. pxquad.h $(OBJDIR)/pxsimple.o: pxsimple.c global.h struct.h const.h sdlscreen.h misc.h \ graph.h pxsimple.h -$(OBJDIR)/pxtall2.o: pxtall2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ - pxtall2.h $(OBJDIR)/pxtall.o: pxtall.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ pxtall.h pxsimple.h +$(OBJDIR)/pxtall2.o: pxtall2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ + pxtall2.h $(OBJDIR)/pxtriple.o: pxtriple.c global.h struct.h const.h sdlscreen.h misc.h \ graph.h pxtriple.h -$(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ - pxwide2.h $(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ pxwide.h +$(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ + pxwide2.h $(OBJDIR)/readini.o: readini.c const.h errors.h global.h struct.h misc.h readini.h $(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h \ sdlscreen.h readline.h windows.h input.h @@ -82,7 +83,6 @@ $(OBJDIR)/saveini.o: saveini.c const.h global.h struct.h readini.h io.h errors.h $(OBJDIR)/sdlscreen.o: sdlscreen.c global.h struct.h const.h sdlscreen.h errors.h \ misc.h $(OBJDIR)/setup.o: setup.c struct.h const.h io.h setup.h -$(OBJDIR)/SFont.o: SFont.c SFont.h $(OBJDIR)/shade.o: shade.c global.h struct.h const.h graph.h engine.h errors.h \ misc.h readline.h help.h sdlscreen.h windows.h input.h shade.h $(OBJDIR)/special.o: special.c const.h struct.h global.h graph.h engine.h windows.h \ diff --git a/src/const.h b/src/const.h index 2efc2454..9ff44b8b 100644 --- a/src/const.h +++ b/src/const.h @@ -37,7 +37,7 @@ #define BETA1 98 ///< Version number for gfx2.cfg (3/4) #define BETA2 0 ///< Version number for gfx2.cfg (4/4) #define MAX_VIDEO_MODES 100 ///< Maximum number of video modes Grafx2 can propose. -#define NB_SHORTCUTS 181 ///< Number of actions that can have a key combination associated to it. +#define NB_SHORTCUTS 183 ///< Number of actions that can have a key combination associated to it. #define NB_ZOOM_FACTORS 15 ///< Number of zoom levels available in the magnifier. #define MENU_WIDTH 254 ///< Width of the menu (not counting the palette) #define MENU_HEIGHT 44 ///< Height of the menu. @@ -465,6 +465,7 @@ enum SPECIAL_ACTIONS SPECIAL_LAYER7_TOGGLE, SPECIAL_LAYER8_SELECT, SPECIAL_LAYER8_TOGGLE, + SPECIAL_REPEAT_SCRIPT, NB_SPECIAL_SHORTCUTS ///< Number of special shortcuts }; diff --git a/src/engine.c b/src/engine.c index 86afcece..6eebec2d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -40,6 +40,7 @@ #include "engine.h" #include "pages.h" #include "layers.h" +#include "factory.h" // we need this as global @@ -1193,6 +1194,10 @@ void Main_handler(void) Layer_activate((key_index-SPECIAL_LAYER1_TOGGLE)/2, RIGHT_SIDE); action++; break; + case SPECIAL_REPEAT_SCRIPT: + Repeat_script(); + action++; + break; } } } // End of special keys diff --git a/src/factory.c b/src/factory.c index 49bc2bc5..02beb86c 100644 --- a/src/factory.c +++ b/src/factory.c @@ -920,13 +920,152 @@ void Highlight_script(T_Fileselector *selector, T_List_button *list, const char } } +static char selected_script[MAX_PATH_CHARACTERS]=""; + +// Before: Cursor hidden +// After: Cursor shown +void Run_script(char *scriptdir) +{ + lua_State* L; + const char* message; + byte old_cursor_shape=Cursor_shape; + + // Some scripts are slow + Cursor_shape=CURSOR_SHAPE_HOURGLASS; + Display_cursor(); + Flush_update(); + + chdir(scriptdir); + + L = lua_open(); + + lua_register(L,"putbrushpixel",L_PutBrushPixel); + lua_register(L,"getbrushpixel",L_GetBrushPixel); + lua_register(L,"getbrushbackuppixel",L_GetBrushBackupPixel); + lua_register(L,"putpicturepixel",L_PutPicturePixel); + lua_register(L,"getpicturepixel",L_GetPicturePixel); + lua_register(L,"getlayerpixel",L_GetLayerPixel); + lua_register(L,"getbackuppixel",L_GetBackupPixel); + lua_register(L,"setbrushsize",L_SetBrushSize); + lua_register(L,"setpicturesize",L_SetPictureSize); + lua_register(L,"getbrushsize",L_GetBrushSize); + lua_register(L,"getpicturesize",L_GetPictureSize); + lua_register(L,"setcolor",L_SetColor); + lua_register(L,"getcolor",L_GetColor); + lua_register(L,"getbackupcolor",L_GetBackupColor); + lua_register(L,"matchcolor",L_MatchColor); + lua_register(L,"getbrushtransparentcolor",L_GetBrushTransparentColor); + lua_register(L,"inputbox",L_InputBox); + lua_register(L,"messagebox",L_MessageBox); + lua_register(L,"getforecolor",L_GetForeColor); + lua_register(L,"getbackcolor",L_GetBackColor); + lua_register(L,"gettranscolor",L_GetTransColor); + lua_register(L,"getsparepicturesize ",L_GetSparePictureSize); + lua_register(L,"getsparelayerpixel ",L_GetSpareLayerPixel); + lua_register(L,"getsparepicturepixel",L_GetSparePicturePixel); + lua_register(L,"getsparecolor",L_GetSpareColor); + lua_register(L,"getsparetranscolor",L_GetSpareTransColor); + lua_register(L,"clearpicture",L_ClearPicture); + + + // For debug only + // luaL_openlibs(L); + + luaopen_base(L); + //luaopen_package(L); // crashes on Windows, for unknown reason + luaopen_table(L); + //luaopen_io(L); // crashes on Windows, for unknown reason + //luaopen_os(L); + //luaopen_string(L); + luaopen_math(L); + //luaopen_debug(L); + + strcat(scriptdir, selected_script); + + // TODO The script may modify the picture, so we do a backup here. + // If the script is only touching the brush, this isn't needed... + // The backup also allows the script to read from it to make something + // like a feedback off effect (convolution matrix comes to mind). + Backup(); + + Palette_has_changed=0; + Brush_was_altered=0; + + // Backup the brush + Brush_backup=(byte *)malloc(((long)Brush_height)*Brush_width); + Brush_backup_width = Brush_width; + Brush_backup_height = Brush_height; + + if (Brush_backup == NULL) + { + Verbose_message("Error!", "Out of memory!"); + } + else + { + memcpy(Brush_backup, Brush, ((long)Brush_height)*Brush_width); + + if (luaL_loadfile(L,scriptdir) != 0) + { + int stack_size; + stack_size= lua_gettop(L); + if (stack_size>0 && (message = lua_tostring(L, stack_size))!=NULL) + Verbose_message("Error!", message); + else + Warning_message("Unknown error loading script!"); + } + else if (lua_pcall(L, 0, 0, 0) != 0) + { + int stack_size; + stack_size= lua_gettop(L); + if (stack_size>0 && (message = lua_tostring(L, stack_size))!=NULL) + Verbose_message("Error running script", message); + else + Warning_message("Unknown error running script!"); + } + } + // Cleanup + free(Brush_backup); + Brush_backup=NULL; + if (Palette_has_changed) + { + Set_palette(Main_palette); + Compute_optimal_menu_colors(Main_palette); + } + End_of_modification(); + + lua_close(L); + + if (Brush_was_altered) + Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH); + + Display_all_screen(); + Cursor_shape=old_cursor_shape; + Display_cursor(); +} + +void Repeat_script(void) +{ + char scriptdir[MAX_PATH_CHARACTERS]; + + if (selected_script==NULL || selected_script[0]=='\0') + { + Warning_message("No script to repeat."); + return; + } + + strcpy(scriptdir, Data_directory); + strcat(scriptdir, "scripts/"); + + Hide_cursor(); + Run_script(scriptdir); +} + void Button_Brush_Factory(void) { short clicked_button; T_List_button* scriptlist; T_Scroller_button* scriptscroll; char scriptdir[MAX_PATH_CHARACTERS]; - static char selected_script[MAX_PATH_CHARACTERS]=""; Open_window(33+8*NAME_WIDTH, 162, "Brush Factory"); @@ -974,6 +1113,8 @@ void Button_Brush_Factory(void) clicked_button = Window_clicked_button(); if (Is_shortcut(Key,0x100+BUTTON_HELP)) Window_help(BUTTON_BRUSH_EFFECTS, "BRUSH FACTORY"); + else if (Is_shortcut(Key,0x200+BUTTON_BRUSH_EFFECTS)) + clicked_button=1; // Cancel switch (clicked_button) { @@ -990,139 +1131,27 @@ void Button_Brush_Factory(void) } } while (clicked_button != 1 && clicked_button != 5); + + if (clicked_button == 5) // OK + { + if (Scripts_list.Nb_elements == 0) + selected_script[0]='\0'; + else + strcpy(selected_script, Get_item_by_index(&Scripts_list, + scriptlist->List_start + scriptlist->Cursor_position)-> Full_name); + } + + Close_window(); + Unselect_button(BUTTON_BRUSH_EFFECTS); - if (Scripts_list.Nb_elements == 0) - selected_script[0]='\0'; - else - strcpy(selected_script, Get_item_by_index(&Scripts_list, - scriptlist->List_start + scriptlist->Cursor_position)-> Full_name); - if (clicked_button == 5) // Run the script { - lua_State* L; - const char* message; - - // Some scripts are slow - Hide_cursor(); - Cursor_shape=CURSOR_SHAPE_HOURGLASS; - Display_cursor(); - Flush_update(); - - chdir(scriptdir); - - L = lua_open(); - - lua_register(L,"putbrushpixel",L_PutBrushPixel); - lua_register(L,"getbrushpixel",L_GetBrushPixel); - lua_register(L,"getbrushbackuppixel",L_GetBrushBackupPixel); - lua_register(L,"putpicturepixel",L_PutPicturePixel); - lua_register(L,"getpicturepixel",L_GetPicturePixel); - lua_register(L,"getlayerpixel",L_GetLayerPixel); - lua_register(L,"getbackuppixel",L_GetBackupPixel); - lua_register(L,"setbrushsize",L_SetBrushSize); - lua_register(L,"setpicturesize",L_SetPictureSize); - lua_register(L,"getbrushsize",L_GetBrushSize); - lua_register(L,"getpicturesize",L_GetPictureSize); - lua_register(L,"setcolor",L_SetColor); - lua_register(L,"getcolor",L_GetColor); - lua_register(L,"getbackupcolor",L_GetBackupColor); - lua_register(L,"matchcolor",L_MatchColor); - lua_register(L,"getbrushtransparentcolor",L_GetBrushTransparentColor); - lua_register(L,"inputbox",L_InputBox); - lua_register(L,"messagebox",L_MessageBox); - lua_register(L,"getforecolor",L_GetForeColor); - lua_register(L,"getbackcolor",L_GetBackColor); - lua_register(L,"gettranscolor",L_GetTransColor); - lua_register(L,"getsparepicturesize ",L_GetSparePictureSize); - lua_register(L,"getsparelayerpixel ",L_GetSpareLayerPixel); - lua_register(L,"getsparepicturepixel",L_GetSparePicturePixel); - lua_register(L,"getsparecolor",L_GetSpareColor); - lua_register(L,"getsparetranscolor",L_GetSpareTransColor); - lua_register(L,"clearpicture",L_ClearPicture); - - - // For debug only - // luaL_openlibs(L); - - luaopen_base(L); - //luaopen_package(L); // crashes on Windows, for unknown reason - luaopen_table(L); - //luaopen_io(L); // crashes on Windows, for unknown reason - //luaopen_os(L); - //luaopen_string(L); - luaopen_math(L); - //luaopen_debug(L); - - strcat(scriptdir, selected_script); - - // TODO The script may modify the picture, so we do a backup here. - // If the script is only touching the brush, this isn't needed... - // The backup also allows the script to read from it to make something - // like a feedback off effect (convolution matrix comes to mind). - Backup(); - - Palette_has_changed=0; - Brush_was_altered=0; - - // Backup the brush - Brush_backup=(byte *)malloc(((long)Brush_height)*Brush_width); - Brush_backup_width = Brush_width; - Brush_backup_height = Brush_height; - - if (Brush_backup == NULL) - { - Verbose_message("Error!", "Out of memory!"); - } - else - { - memcpy(Brush_backup, Brush, ((long)Brush_height)*Brush_width); - - if (luaL_loadfile(L,scriptdir) != 0) - { - int stack_size; - stack_size= lua_gettop(L); - if (stack_size>0 && (message = lua_tostring(L, stack_size))!=NULL) - Verbose_message("Error!", message); - else - Warning_message("Unknown error loading script!"); - } - else if (lua_pcall(L, 0, 0, 0) != 0) - { - int stack_size; - stack_size= lua_gettop(L); - if (stack_size>0 && (message = lua_tostring(L, stack_size))!=NULL) - Verbose_message("Error running script", message); - else - Warning_message("Unknown error running script!"); - } - } - // Cleanup - free(Brush_backup); - Brush_backup=NULL; - if (Palette_has_changed) - { - Set_palette(Main_palette); - Compute_optimal_menu_colors(Main_palette); - } - End_of_modification(); - - lua_close(L); + Run_script(scriptdir); + } + else + { + Display_cursor(); } - - Close_window(); - if (Brush_was_altered) - Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH); - Unselect_button(BUTTON_BRUSH_EFFECTS); - // If the image has been resized, Compute_limits() has been called and it - // has computed wrong values because a window was open : In this - // context, Menu_Y and Menu_is_visible are artificially set to "menu hidden". - // This whole "_before_window" looks like it's completely useless anyway, - // but we're too close to release to scrap it and re-test everything. - // So: call Compute_limits() one more time, and be done with it. - Compute_limits(); - - Display_all_screen(); - Display_cursor(); } #else // NOLUA diff --git a/src/factory.h b/src/factory.h index ff12d081..5e033974 100644 --- a/src/factory.h +++ b/src/factory.h @@ -1,3 +1,4 @@ /* vim:expandtab:ts=2 sw=2: */ void Button_Brush_Factory(void); +void Repeat_script(void); diff --git a/src/helpfile.h b/src/helpfile.h index d59660fd..507a1183 100644 --- a/src/helpfile.h +++ b/src/helpfile.h @@ -228,6 +228,8 @@ static const T_Help_table helptable_help[] = HELP_LINK (" 18:1 %s", SPECIAL_ZOOM_18) HELP_LINK (" 20:1 %s", SPECIAL_ZOOM_20) HELP_LINK ("Brush effects menu: %s", 0x100+BUTTON_BRUSH_EFFECTS) + HELP_LINK ("Brush factory: %s", 0x200+BUTTON_BRUSH_EFFECTS) + HELP_LINK ("Repeat last script: %s", SPECIAL_REPEAT_SCRIPT) HELP_LINK ("Text: %s", 0x100+BUTTON_TEXT) HELP_LINK ("Resolution menu: %s", 0x100+BUTTON_RESOL) HELP_LINK ("Safety resolution: %s", 0x200+BUTTON_RESOL) @@ -1306,6 +1308,8 @@ static const T_Help_table helptable_brush_fx[] = HELP_TEXT ("") HELP_TITLE("BRUSH FACTORY") HELP_TEXT ("") + HELP_LINK ("(Key:%s)",0x200+BUTTON_BRUSH_EFFECTS) + HELP_TEXT ("") HELP_TEXT ("This menu allows you to run scripts. Scripts") HELP_TEXT ("are written in the Lua language, and allow") HELP_TEXT ("you to modify the brush (hence the name") @@ -1325,6 +1329,8 @@ static const T_Help_table helptable_brush_fx[] = HELP_TEXT ("time you open the window. Scripts are loaded") HELP_TEXT ("from disk when you run them.") HELP_TEXT ("") + HELP_LINK ("- Repeat last script: %s", SPECIAL_REPEAT_SCRIPT) + HELP_TEXT ("") }; static const T_Help_table helptable_effects[] = { diff --git a/src/hotkeys.c b/src/hotkeys.c index 764275bb..316dc3ee 100644 --- a/src/hotkeys.c +++ b/src/hotkeys.c @@ -1477,6 +1477,22 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = { true, SDLK_HOME|MOD_ALT, // Alt + Home 0}, + {181, + "Brush factory", + "Opens a window where you can run a", + "Lua script.", + "", + true, + 0, // No shortcut + 0}, + {182, + "Repeat script", + "Re-run the last script selected", + "in the Brush factory window.", + "", + true, + 0, // No shortcut + 0}, }; word Ordering[NB_SHORTCUTS]= @@ -1662,4 +1678,6 @@ word Ordering[NB_SHORTCUTS]= 0x100+BUTTON_LAYER_UP, 0x100+BUTTON_LAYER_DOWN, 0x100+BUTTON_LAYER_MENU, + 0x200+BUTTON_BRUSH_EFFECTS, + SPECIAL_REPEAT_SCRIPT, };