Lua: added a message box. messagebox('message'), or messagebox('caption','message'). note that Lua supports concatenation (operator ..) and this function accepts backslash-n for carriage return. It performs word-wrapping if needed. Fixed the Hourglass cursor showing up in some error boxes, instead of the arrow cursor.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1340 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2010-02-13 19:00:13 +00:00
parent 683f8c6a18
commit 917847cdab
2 changed files with 34 additions and 1 deletions

View File

@ -569,6 +569,32 @@ int L_InputBox(lua_State* L)
return 1 + nb_settings; return 1 + nb_settings;
} }
int L_MessageBox(lua_State* L)
{
int nb_args = lua_gettop (L);
const char * caption;
const char * message;
if (nb_args == 1)
{
caption = "Script message";
message = lua_tostring(L,1);
}
else if (nb_args == 2)
{
caption = lua_tostring(L,1);
message = lua_tostring(L,2);
}
else
{
return luaL_error(L, "MessageBox: Needs one or two arguments.");
}
Verbose_message(caption, message);
return 0;
}
// Handlers for window internals // Handlers for window internals
T_Fileselector Scripts_list; T_Fileselector Scripts_list;
@ -758,6 +784,7 @@ void Button_Brush_Factory(void)
lua_register(L,"matchcolor",L_MatchColor); lua_register(L,"matchcolor",L_MatchColor);
lua_register(L,"getbrushtransparentcolor",L_GetBrushTransparentColor); lua_register(L,"getbrushtransparentcolor",L_GetBrushTransparentColor);
lua_register(L,"inputbox",L_InputBox); lua_register(L,"inputbox",L_InputBox);
lua_register(L,"messagebox",L_MessageBox);
lua_register(L,"getforecolor",L_GetForeColor); lua_register(L,"getforecolor",L_GetForeColor);
lua_register(L,"getbackcolor",L_GetBackColor); lua_register(L,"getbackcolor",L_GetBackColor);
lua_register(L,"gettranscolor",L_GetTransColor); lua_register(L,"gettranscolor",L_GetTransColor);

View File

@ -1113,7 +1113,9 @@ void Warning_message(char * message)
Display_cursor(); Display_cursor();
} }
/// Window that shows a big message (up to 34x12), and waits for a click on OK /// Window that shows a big message (up to 34x12), and waits for a click on OK.
/// On call: Cursor must be displayed
/// On exit: Cursor is displayed
void Verbose_message(const char *caption, const char * message ) void Verbose_message(const char *caption, const char * message )
{ {
short clicked_button; short clicked_button;
@ -1121,7 +1123,9 @@ void Verbose_message(const char *caption, const char * message )
int last_space; int last_space;
int nb_char; int nb_char;
char buffer[36]; char buffer[36];
byte original_cursor_shape = Cursor_shape;
Open_window(300,160,caption); Open_window(300,160,caption);
// Word-wrap the message // Word-wrap the message
@ -1160,6 +1164,7 @@ void Verbose_message(const char *caption, const char * message )
Window_set_normal_button(300/2-20,160-23,40,14,"OK",1,1,SDLK_RETURN); // 1 Window_set_normal_button(300/2-20,160-23,40,14,"OK",1,1,SDLK_RETURN); // 1
Update_window_area(0,0,Window_width,Window_height); Update_window_area(0,0,Window_width,Window_height);
Cursor_shape=CURSOR_SHAPE_ARROW;
Display_cursor(); Display_cursor();
do do
@ -1168,6 +1173,7 @@ void Verbose_message(const char *caption, const char * message )
Key=0; Key=0;
Close_window(); Close_window();
Cursor_shape=original_cursor_shape;
Display_cursor(); Display_cursor();
} }