Lua window: shortcut 'return' runs highlighted script, and the script selector remembers which filename was highlighted (during current session)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1348 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
aa316b066e
commit
d5353b378d
45
factory.c
45
factory.c
@ -694,12 +694,39 @@ void Add_script(const char *name)
|
|||||||
Add_element_to_list(&Scripts_list, Find_last_slash(name)+1, 0);
|
Add_element_to_list(&Scripts_list, Find_last_slash(name)+1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Highlight_script(T_Fileselector *selector, T_List_button *list, const char *selected_script)
|
||||||
|
{
|
||||||
|
short index;
|
||||||
|
|
||||||
|
index=Find_file_in_fileselector(selector, selected_script);
|
||||||
|
|
||||||
|
if ((list->Scroller->Nb_elements<=list->Scroller->Nb_visibles) || (index<list->Scroller->Nb_visibles/2))
|
||||||
|
{
|
||||||
|
list->List_start=0;
|
||||||
|
list->Cursor_position=index;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (index>=list->Scroller->Nb_elements-list->Scroller->Nb_visibles/2)
|
||||||
|
{
|
||||||
|
list->List_start=list->Scroller->Nb_elements-list->Scroller->Nb_visibles;
|
||||||
|
list->Cursor_position=index-list->List_start;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list->List_start=index-(list->Scroller->Nb_visibles-1)/2;
|
||||||
|
list->Cursor_position=(list->Scroller->Nb_visibles-1)/2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Button_Brush_Factory(void)
|
void Button_Brush_Factory(void)
|
||||||
{
|
{
|
||||||
short clicked_button;
|
short clicked_button;
|
||||||
T_List_button* scriptlist;
|
T_List_button* scriptlist;
|
||||||
T_Scroller_button* scriptscroll;
|
T_Scroller_button* scriptscroll;
|
||||||
char scriptdir[MAX_PATH_CHARACTERS];
|
char scriptdir[MAX_PATH_CHARACTERS];
|
||||||
|
static char selected_script[MAX_PATH_CHARACTERS]="";
|
||||||
|
|
||||||
Open_window(33+8*NAME_WIDTH, 162, "Brush Factory");
|
Open_window(33+8*NAME_WIDTH, 162, "Brush Factory");
|
||||||
|
|
||||||
@ -714,7 +741,7 @@ void Button_Brush_Factory(void)
|
|||||||
Sort_list_of_files(&Scripts_list);
|
Sort_list_of_files(&Scripts_list);
|
||||||
|
|
||||||
Window_set_normal_button(85, 141, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1
|
Window_set_normal_button(85, 141, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1
|
||||||
Window_set_normal_button(10, 141, 67, 14, "Run", 0, 1, 0); // 2
|
Window_set_normal_button(10, 141, 67, 14, "Run", 0, 1, SDLK_RETURN); // 2
|
||||||
|
|
||||||
Window_display_frame_in(6, FILESEL_Y - 2, NAME_WIDTH*8+4, 84); // File selector
|
Window_display_frame_in(6, FILESEL_Y - 2, NAME_WIDTH*8+4, 84); // File selector
|
||||||
scriptlist = Window_set_list_button(
|
scriptlist = Window_set_list_button(
|
||||||
@ -722,11 +749,18 @@ void Button_Brush_Factory(void)
|
|||||||
Window_set_special_button(8, FILESEL_Y + 1, NAME_WIDTH*8, 80), // 3
|
Window_set_special_button(8, FILESEL_Y + 1, NAME_WIDTH*8, 80), // 3
|
||||||
// Scroller for the fileselector
|
// Scroller for the fileselector
|
||||||
(scriptscroll = Window_set_scroller_button(NAME_WIDTH*8+14, FILESEL_Y - 1, 82,
|
(scriptscroll = Window_set_scroller_button(NAME_WIDTH*8+14, FILESEL_Y - 1, 82,
|
||||||
Scripts_list.Nb_elements, 10, 0)), // 4
|
Scripts_list.Nb_elements,10, 0)), // 4
|
||||||
Draw_script_name); // 5
|
Draw_script_name); // 5
|
||||||
|
|
||||||
Window_display_frame_in(6, FILESEL_Y + 88, (NAME_WIDTH+2)*8+4, 3*8+2); // Descr.
|
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);
|
Window_redraw_list(scriptlist);
|
||||||
Draw_script_information(Get_item_by_index(&Scripts_list,
|
Draw_script_information(Get_item_by_index(&Scripts_list,
|
||||||
scriptlist->List_start + scriptlist->Cursor_position));
|
scriptlist->List_start + scriptlist->Cursor_position));
|
||||||
@ -753,6 +787,9 @@ void Button_Brush_Factory(void)
|
|||||||
|
|
||||||
} while (clicked_button <= 0 || clicked_button >= 3);
|
} while (clicked_button <= 0 || clicked_button >= 3);
|
||||||
|
|
||||||
|
strcpy(selected_script, Get_item_by_index(&Scripts_list,
|
||||||
|
scriptlist->List_start + scriptlist->Cursor_position)-> Full_name);
|
||||||
|
|
||||||
if (clicked_button == 2) // Run the script
|
if (clicked_button == 2) // Run the script
|
||||||
{
|
{
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
@ -800,9 +837,7 @@ void Button_Brush_Factory(void)
|
|||||||
|
|
||||||
luaopen_math(L);
|
luaopen_math(L);
|
||||||
|
|
||||||
strcat(scriptdir, Get_item_by_index(&Scripts_list,
|
strcat(scriptdir, selected_script);
|
||||||
scriptlist->List_start + scriptlist->Cursor_position)
|
|
||||||
-> Full_name);
|
|
||||||
|
|
||||||
// TODO The script may modify the picture, so we do a backup here.
|
// 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...
|
// If the script is only touching the brush, this isn't needed...
|
||||||
|
|||||||
@ -961,7 +961,7 @@ void Scroll_fileselector(T_Scroller_button * file_scroller)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
short Find_file_in_fileselector(T_Fileselector *list, char * fname)
|
short Find_file_in_fileselector(T_Fileselector *list, const char * fname)
|
||||||
{
|
{
|
||||||
T_Fileselector_item * item;
|
T_Fileselector_item * item;
|
||||||
short index;
|
short index;
|
||||||
|
|||||||
@ -46,6 +46,6 @@ void Recount_files(T_Fileselector *list);
|
|||||||
|
|
||||||
T_Fileselector_item * Get_item_by_index(T_Fileselector *list, short index);
|
T_Fileselector_item * Get_item_by_index(T_Fileselector *list, short index);
|
||||||
|
|
||||||
short Find_file_in_fileselector(T_Fileselector *list, char * fname);
|
short Find_file_in_fileselector(T_Fileselector *list, const char * fname);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user