diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-06-08 15:30:36 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-06-08 15:30:36 (GMT) |
| commit | 3ea25c83b7dc039b23af2eeb4279a046fa0bf259 (patch) | |
| tree | 2e665e8b179bc44c266c0aa090384bd2ba93fd37 /src | |
| parent | e94ed7bc113c42a3f8541aa6031f38ab6ddf8063 (diff) | |
| download | powder-3ea25c83b7dc039b23af2eeb4279a046fa0bf259.zip powder-3ea25c83b7dc039b23af2eeb4279a046fa0bf259.tar.gz | |
message_box and input for Lua API, also autorun.lua
Diffstat (limited to 'src')
| -rw-r--r-- | src/interface.c | 71 | ||||
| -rw-r--r-- | src/luaconsole.c | 43 | ||||
| -rw-r--r-- | src/main.c | 3 |
3 files changed, 116 insertions, 1 deletions
diff --git a/src/interface.c b/src/interface.c index b6d854e..86bc0eb 100644 --- a/src/interface.c +++ b/src/interface.c @@ -820,6 +820,75 @@ void error_ui(pixel *vid_buf, int err, char *txt) } } +char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shadow) +{ + int xsize = 244; + int ysize = 90; + int edity, editx; + int x0=(XRES-xsize)/2,y0=(YRES-MENUSIZE-ysize)/2,b=1,bq,mx,my; + ui_edit ed; + + edity = y0+50; + editx = x0+12; + + ed.x = editx; + ed.y = edity; + ed.w = xsize - 20; + ed.nx = 1; + ed.def = shadow; + ed.focus = 0; + ed.hide = 0; + ed.cursor = 0; + ed.multiline = 0; + strncpy(ed.str, text, 254); + + while (!sdl_poll()) + { + b = SDL_GetMouseState(&mx, &my); + if (!b) + break; + } + + while (!sdl_poll()) + { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); + drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); + drawtext(vid_buf, x0+8, y0+8, title, 160, 160, 255, 255); + drawtext(vid_buf, x0+8, y0+26, prompt, 255, 255, 255, 255); + + drawrect(vid_buf, ed.x-4, ed.y-5, ed.w+4, 16, 192, 192, 192, 255); + + ui_edit_draw(vid_buf, &ed); + ui_edit_process(mx, my, b, &ed); + + drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255); + drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255); + + sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE)); + + if (b && !bq && mx>=x0 && mx<x0+xsize && my>=y0+ysize-16 && my<=y0+ysize) + break; + + if (sdl_key==SDLK_RETURN) + break; + if (sdl_key==SDLK_ESCAPE) + break; + } + + while (!sdl_poll()) + { + b = SDL_GetMouseState(&mx, &my); + if (!b) + break; + } + return mystrdup(ed.str); +} + void info_ui(pixel *vid_buf, char *top, char *txt) { int x0=(XRES-240)/2,y0=(YRES-MENUSIZE)/2,b=1,bq,mx,my; @@ -2618,7 +2687,7 @@ int search_ui(pixel *vid_buf) pixel *thumb_rsdata = NULL; pixel *thumb_imgdata = ptif_unpack(search_thumbs[pos], search_thsizes[pos], &finw, &finh); if(thumb_imgdata!=NULL){ - thumb_rsdata = resample_img(thumb_imgdata, finw, finh, XRES/GRID_S, YRES/GRID_S); + thumb_rsdata = resample_img_nn(thumb_imgdata, finw, finh, XRES/GRID_S, YRES/GRID_S); draw_image(v_buf, thumb_rsdata, gx, gy, XRES/GRID_S, YRES/GRID_S, 255); free(thumb_imgdata); free(thumb_rsdata); diff --git a/src/luaconsole.c b/src/luaconsole.c index 052aa98..091b976 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -30,6 +30,8 @@ void luacon_open(){ {"delete", &luatpt_delete}, {"register_step", &luatpt_register_step}, {"unregister_step", &luatpt_unregister_step}, + {"input", &luatpt_input}, + {"message_box", &luatpt_message_box}, {NULL,NULL} }; @@ -703,4 +705,45 @@ int luatpt_unregister_step(lua_State* l) } return 0; } +int luatpt_input(lua_State* l) +{ + char *prompt, *title, *result, *shadow, *text; + title = mystrdup(luaL_optstring(l, 1, "Title")); + prompt = mystrdup(luaL_optstring(l, 2, "Enter some text:")); + text = mystrdup(luaL_optstring(l, 3, "")); + shadow = mystrdup(luaL_optstring(l, 4, "")); + + if (vid_buf!=NULL) + { + result = input_ui(vid_buf, title, prompt, text, shadow); + lua_pushstring(l, result); + free(result); + free(title); + free(prompt); + free(text); + free(shadow); + return 1; + } + free(title); + free(prompt); + free(text); + free(shadow); + return luaL_error(l, "Screen buffer does not exist"); +} +int luatpt_message_box(lua_State* l) +{ + char *title, *text; + title = mystrdup(luaL_optstring(l, 1, "Title")); + text = mystrdup(luaL_optstring(l, 2, "Message")); + if (vid_buf!=NULL) + { + info_ui(vid_buf, title, text); + free(title); + free(text); + return 0; + } + free(title); + free(text); + return luaL_error(l, "Screen buffer does not exist");; +} #endif @@ -1741,6 +1741,9 @@ int main(int argc, char *argv[]) http_session_check = http_async_req_start(NULL, "http://" SERVER "/Login.api?Action=CheckSession", NULL, 0, 0); http_auth_headers(http_session_check, svf_user_id, NULL, svf_session_id); } +#ifdef LUACONSOLE + luacon_eval("dofile(\"autorun.lua\")"); //Autorun lua script +#endif while (!sdl_poll()) //the main loop { frameidx++; |
