Added a key shortcut to open Brush factory (Lua scripts), and another one to repeat the last used Lua script. Updated helpfile. At the moment no key is affected by default, so if DawnBringer has a preference...

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1527 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2010-07-06 21:48:38 +00:00
parent d459f3f824
commit 272cc59395
7 changed files with 198 additions and 138 deletions

View File

@ -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 \ $(OBJDIR)/brush.o: brush.c global.h struct.h const.h graph.h misc.h errors.h \
windows.h sdlscreen.h brush.h windows.h sdlscreen.h brush.h
$(OBJDIR)/brush_ops.o: brush_ops.c brush.h struct.h const.h buttons.h engine.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 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 \ $(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 \ 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 \ $(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 \ 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 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 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 \ $(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 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)/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 \ $(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 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 pxquad.h
$(OBJDIR)/pxsimple.o: pxsimple.c global.h struct.h const.h sdlscreen.h misc.h \ $(OBJDIR)/pxsimple.o: pxsimple.c global.h struct.h const.h sdlscreen.h misc.h \
graph.h pxsimple.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 \ $(OBJDIR)/pxtall.o: pxtall.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
pxtall.h pxsimple.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 \ $(OBJDIR)/pxtriple.o: pxtriple.c global.h struct.h const.h sdlscreen.h misc.h \
graph.h pxtriple.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 \ $(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
pxwide.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)/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 \ $(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h \
sdlscreen.h readline.h windows.h input.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 \ $(OBJDIR)/sdlscreen.o: sdlscreen.c global.h struct.h const.h sdlscreen.h errors.h \
misc.h misc.h
$(OBJDIR)/setup.o: setup.c struct.h const.h io.h setup.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 \ $(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 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 \ $(OBJDIR)/special.o: special.c const.h struct.h global.h graph.h engine.h windows.h \

View File

@ -37,7 +37,7 @@
#define BETA1 98 ///< Version number for gfx2.cfg (3/4) #define BETA1 98 ///< Version number for gfx2.cfg (3/4)
#define BETA2 0 ///< Version number for gfx2.cfg (4/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 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 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_WIDTH 254 ///< Width of the menu (not counting the palette)
#define MENU_HEIGHT 44 ///< Height of the menu. #define MENU_HEIGHT 44 ///< Height of the menu.
@ -465,6 +465,7 @@ enum SPECIAL_ACTIONS
SPECIAL_LAYER7_TOGGLE, SPECIAL_LAYER7_TOGGLE,
SPECIAL_LAYER8_SELECT, SPECIAL_LAYER8_SELECT,
SPECIAL_LAYER8_TOGGLE, SPECIAL_LAYER8_TOGGLE,
SPECIAL_REPEAT_SCRIPT,
NB_SPECIAL_SHORTCUTS ///< Number of special shortcuts NB_SPECIAL_SHORTCUTS ///< Number of special shortcuts
}; };

View File

@ -40,6 +40,7 @@
#include "engine.h" #include "engine.h"
#include "pages.h" #include "pages.h"
#include "layers.h" #include "layers.h"
#include "factory.h"
// we need this as global // we need this as global
@ -1193,6 +1194,10 @@ void Main_handler(void)
Layer_activate((key_index-SPECIAL_LAYER1_TOGGLE)/2, RIGHT_SIDE); Layer_activate((key_index-SPECIAL_LAYER1_TOGGLE)/2, RIGHT_SIDE);
action++; action++;
break; break;
case SPECIAL_REPEAT_SCRIPT:
Repeat_script();
action++;
break;
} }
} }
} // End of special keys } // End of special keys

View File

@ -920,90 +920,17 @@ void Highlight_script(T_Fileselector *selector, T_List_button *list, const char
} }
} }
void Button_Brush_Factory(void) static char selected_script[MAX_PATH_CHARACTERS]="";
// Before: Cursor hidden
// After: Cursor shown
void Run_script(char *scriptdir)
{ {
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");
// Here we use the same data container as the fileselectors.
// Reinitialize the list
Free_fileselector_list(&Scripts_list);
strcpy(scriptdir, Data_directory);
strcat(scriptdir, "scripts/");
// Add each found file to the list
For_each_file(scriptdir, Add_script);
// Sort it
Sort_list_of_files(&Scripts_list);
Window_set_normal_button(85, 141, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1
Window_display_frame_in(6, FILESEL_Y - 2, NAME_WIDTH*8+4, 84); // File selector
scriptlist = Window_set_list_button(
// Fileselector
Window_set_special_button(8, FILESEL_Y + 1, NAME_WIDTH*8, 80), // 2
// Scroller for the fileselector
(scriptscroll = Window_set_scroller_button(NAME_WIDTH*8+14, FILESEL_Y - 1, 82,
Scripts_list.Nb_elements,10, 0)), // 3
Draw_script_name); // 4
Window_set_normal_button(10, 141, 67, 14, "Run", 0, Scripts_list.Nb_elements!=0, SDLK_RETURN); // 5
Window_display_frame_in(6, FILESEL_Y + 88, (NAME_WIDTH+2)*8+4, 3*8+2); // Descr.
// Update position
Highlight_script(&Scripts_list, scriptlist, selected_script);
// Update the scroller position
scriptscroll->Position=scriptlist->List_start;
if (scriptscroll->Position)
Window_draw_slider(scriptscroll);
Window_redraw_list(scriptlist);
Draw_script_information(Get_item_by_index(&Scripts_list,
scriptlist->List_start + scriptlist->Cursor_position));
Update_window_area(0, 0, Window_width, Window_height);
Display_cursor();
do
{
clicked_button = Window_clicked_button();
if (Is_shortcut(Key,0x100+BUTTON_HELP))
Window_help(BUTTON_BRUSH_EFFECTS, "BRUSH FACTORY");
switch (clicked_button)
{
case 4:
Hide_cursor();
Draw_script_information(Get_item_by_index(&Scripts_list,
scriptlist->List_start + scriptlist->Cursor_position));
Display_cursor();
break;
default:
break;
}
} while (clicked_button != 1 && clicked_button != 5);
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; lua_State* L;
const char* message; const char* message;
byte old_cursor_shape=Cursor_shape;
// Some scripts are slow // Some scripts are slow
Hide_cursor();
Cursor_shape=CURSOR_SHAPE_HOURGLASS; Cursor_shape=CURSOR_SHAPE_HOURGLASS;
Display_cursor(); Display_cursor();
Flush_update(); Flush_update();
@ -1107,22 +1034,124 @@ void Button_Brush_Factory(void)
End_of_modification(); End_of_modification();
lua_close(L); 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];
Open_window(33+8*NAME_WIDTH, 162, "Brush Factory");
// Here we use the same data container as the fileselectors.
// Reinitialize the list
Free_fileselector_list(&Scripts_list);
strcpy(scriptdir, Data_directory);
strcat(scriptdir, "scripts/");
// Add each found file to the list
For_each_file(scriptdir, Add_script);
// Sort it
Sort_list_of_files(&Scripts_list);
Window_set_normal_button(85, 141, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1
Window_display_frame_in(6, FILESEL_Y - 2, NAME_WIDTH*8+4, 84); // File selector
scriptlist = Window_set_list_button(
// Fileselector
Window_set_special_button(8, FILESEL_Y + 1, NAME_WIDTH*8, 80), // 2
// Scroller for the fileselector
(scriptscroll = Window_set_scroller_button(NAME_WIDTH*8+14, FILESEL_Y - 1, 82,
Scripts_list.Nb_elements,10, 0)), // 3
Draw_script_name); // 4
Window_set_normal_button(10, 141, 67, 14, "Run", 0, Scripts_list.Nb_elements!=0, SDLK_RETURN); // 5
Window_display_frame_in(6, FILESEL_Y + 88, (NAME_WIDTH+2)*8+4, 3*8+2); // Descr.
// Update position
Highlight_script(&Scripts_list, scriptlist, selected_script);
// Update the scroller position
scriptscroll->Position=scriptlist->List_start;
if (scriptscroll->Position)
Window_draw_slider(scriptscroll);
Window_redraw_list(scriptlist);
Draw_script_information(Get_item_by_index(&Scripts_list,
scriptlist->List_start + scriptlist->Cursor_position));
Update_window_area(0, 0, Window_width, Window_height);
Display_cursor();
do
{
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)
{
case 4:
Hide_cursor();
Draw_script_information(Get_item_by_index(&Scripts_list,
scriptlist->List_start + scriptlist->Cursor_position));
Display_cursor();
break;
default:
break;
}
} 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(); Close_window();
if (Brush_was_altered)
Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH);
Unselect_button(BUTTON_BRUSH_EFFECTS); 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(); if (clicked_button == 5) // Run the script
{
Run_script(scriptdir);
}
else
{
Display_cursor(); Display_cursor();
}
} }
#else // NOLUA #else // NOLUA

View File

@ -1,3 +1,4 @@
/* vim:expandtab:ts=2 sw=2: /* vim:expandtab:ts=2 sw=2:
*/ */
void Button_Brush_Factory(void); void Button_Brush_Factory(void);
void Repeat_script(void);

View File

@ -228,6 +228,8 @@ static const T_Help_table helptable_help[] =
HELP_LINK (" 18:1 %s", SPECIAL_ZOOM_18) HELP_LINK (" 18:1 %s", SPECIAL_ZOOM_18)
HELP_LINK (" 20:1 %s", SPECIAL_ZOOM_20) HELP_LINK (" 20:1 %s", SPECIAL_ZOOM_20)
HELP_LINK ("Brush effects menu: %s", 0x100+BUTTON_BRUSH_EFFECTS) 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 ("Text: %s", 0x100+BUTTON_TEXT)
HELP_LINK ("Resolution menu: %s", 0x100+BUTTON_RESOL) HELP_LINK ("Resolution menu: %s", 0x100+BUTTON_RESOL)
HELP_LINK ("Safety resolution: %s", 0x200+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_TEXT ("")
HELP_TITLE("BRUSH FACTORY") HELP_TITLE("BRUSH FACTORY")
HELP_TEXT ("") HELP_TEXT ("")
HELP_LINK ("(Key:%s)",0x200+BUTTON_BRUSH_EFFECTS)
HELP_TEXT ("")
HELP_TEXT ("This menu allows you to run scripts. Scripts") HELP_TEXT ("This menu allows you to run scripts. Scripts")
HELP_TEXT ("are written in the Lua language, and allow") HELP_TEXT ("are written in the Lua language, and allow")
HELP_TEXT ("you to modify the brush (hence the name") 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 ("time you open the window. Scripts are loaded")
HELP_TEXT ("from disk when you run them.") HELP_TEXT ("from disk when you run them.")
HELP_TEXT ("") HELP_TEXT ("")
HELP_LINK ("- Repeat last script: %s", SPECIAL_REPEAT_SCRIPT)
HELP_TEXT ("")
}; };
static const T_Help_table helptable_effects[] = static const T_Help_table helptable_effects[] =
{ {

View File

@ -1477,6 +1477,22 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = {
true, true,
SDLK_HOME|MOD_ALT, // Alt + Home SDLK_HOME|MOD_ALT, // Alt + Home
0}, 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]= word Ordering[NB_SHORTCUTS]=
@ -1662,4 +1678,6 @@ word Ordering[NB_SHORTCUTS]=
0x100+BUTTON_LAYER_UP, 0x100+BUTTON_LAYER_UP,
0x100+BUTTON_LAYER_DOWN, 0x100+BUTTON_LAYER_DOWN,
0x100+BUTTON_LAYER_MENU, 0x100+BUTTON_LAYER_MENU,
0x200+BUTTON_BRUSH_EFFECTS,
SPECIAL_REPEAT_SCRIPT,
}; };