44typedef struct dialogue_update_s {
46 int (*update)(double,
void*);
50 int (*event)(
unsigned int, SDL_Event*,
void*);
59static int dialogue_custom_event(
unsigned int wid, SDL_Event *event );
71 const char* msg,
int* width,
int* height );
75static void dialogue_listClose(
unsigned int wid,
const char *str );
76static void dialogue_listCancel(
unsigned int wid,
const char *str );
83typedef struct InputDialogue_ {
89 void (*item_select_cb) (
unsigned int wid,
const char* wgtname,
90 int x,
int y,
int w,
int h
134 char msg[STRMAX_SHORT];
139 if (fmt == NULL)
return;
142 vsnprintf(msg,
sizeof(msg), fmt, ap);
149 wdw =
window_create(
"dlgAlert", _(
"Warning"), -1, -1, 300, 90 + h );
151 window_addText( wdw, 20, -30, 260, h, 0,
"txtAlert",
153 window_addButton( wdw, 135, 20, 50, 30,
"btnOK", _(
"OK"),
169 const char* msg,
int* width,
int* height )
173 int i, titlelen, msglen;
188 if (msglen < (260 + i * 50) * (2 + i))
192 w =
MAX(w, titlelen+40);
198 d = ((double)w/(
double)h)*(3./4.);
223 if (fmt == NULL)
return;
226 vsnprintf(msg,
sizeof(msg), fmt, ap);
245 if (fmt == NULL)
return;
248 vsnprintf(msg,
sizeof(msg), fmt, ap);
265 unsigned int msg_wid;
271 msg_wid =
window_create(
"dlgMsg", caption, -1, -1, w, 110 + h );
273 window_addText( msg_wid, 20, -40, w-40, h, 0,
"txtMsg",
275 window_addButton( msg_wid, (w-50)/2, 20, 50, 30,
"btnOK", _(
"OK"),
290void dialogue_msgImgRaw(
const char* caption,
const char *msg,
const char *img,
int width,
int height )
292 int w, h, img_width, img_height;
294 unsigned int msg_wid;
301 snprintf( buf,
sizeof(buf),
"%s%s", GFX_PATH, img );
307 img_width = (width < 0) ? gfx->
w : width;
308 img_height = (height < 0) ? gfx->
h : height;
315 msg_wid =
window_create(
"dlgMsgImg", caption, -1, -1, img_width + w, 110 + h );
319 window_addText( msg_wid, img_width+40, -40, w-40, h, 0,
"txtMsg",
323 window_addRect( msg_wid, 20, -40, img_width, img_height,
324 "rctGFX", &cGrey10, 1 );
327 window_addImage( msg_wid, 20, -40, img_width, img_height,
331 window_addButton( msg_wid, (img_width+w -50)/2, 20, 50, 30,
"btnOK", _(
"OK"),
349 if (fmt == NULL)
return -1;
352 vsnprintf(msg,
sizeof(msg), fmt, ap);
372 char buf[STRMAX_SHORT];
377 snprintf( buf,
sizeof(buf),
"dlgYesNo%d", ++
dlgid );
381 window_addText( wid, 20, -40, w-40, h, 0,
"txtYesNo",
384 window_addButtonKey( wid, w/2-100-10, 20, 100, 30,
"btnYes", _(
"Yes"),
386 window_addButtonKey( wid, w/2+10, 20, 100, 30,
"btnNo", _(
"No"),
406 int *loop_done, result;
409 if (strcmp(str,
"btnYes")==0)
411 else if (strcmp(str,
"btnNo")==0)
414 WARN(_(
"Unknown button clicked in YesNo dialogue!"));
421 loop_done[1] = result;
444 if (fmt == NULL)
return NULL;
447 vsnprintf(msg,
sizeof(msg), fmt, ap);
495 while ((done >= 0) && (!input ||
496 ((
int)strlen(input) < min))) {
500 "Input must be at least %d character long!",
501 "Input must be at least %d characters long!", min),
542static int dialogue_listSelected = -1;
543static void dialogue_listCancel(
unsigned int wid,
const char *str )
545 dialogue_listSelected = -1;
548static void dialogue_listClose(
unsigned int wid,
const char *str )
550 dialogue_listSelected = toolkit_getListPos( wid,
"lstDialogue" );
576int dialogue_list(
const char* title,
char **items,
int nitems,
const char *fmt, ... )
578 char msg[STRMAX_SHORT];
583 if (fmt == NULL)
return -1;
586 vsnprintf(msg,
sizeof(msg), fmt, ap);
622 int minheight,
void (*add_widgets) (
unsigned int wid,
int x,
int y,
int w,
int h),
623 void (*select_call) (
unsigned int wid,
const char* wgtname,
int x,
int y,
int w,
int h),
624 const char *fmt, ... )
626 char msg[STRMAX_SHORT];
637 vsnprintf(msg,
sizeof(msg), fmt, ap);
641 add_widgets, select_call, msg );
660 int minheight,
void (*add_widgets) (
unsigned int wid,
int x,
int y,
int w,
int h),
661 void (*select_call) (
unsigned int wid,
const char* wgtname,
int x,
int y,
int w,
int h),
665 int w, h, winw, winh;
668 int list_width, list_height;
669 int text_height, text_width;
679 for (i=0; i<nitems; i++) {
684 if (list_height > 500)
685 h = (list_height*8)/10;
687 h =
MAX( 300, list_height );
689 h =
MIN( ((
double)SCREEN_H*2.)/3., h );
690 w =
MAX( list_width + 60, 500 );
692 winw = w + extrawidth;
693 winh =
MAX( h, minheight );
698 wid =
window_create(
"dlgListPanel", title, -1, -1, winw, winh );
700 window_addText( wid, 20, -40, w-40, text_height, 0,
"txtMsg",
706 add_widgets(wid, w, 0, winw, winh);
717 window_addList( wid, 20, -40-text_height-20,
718 w-40, h - (40+text_height+20) - (20+30+20),
720 dialogue_listClose );
723 window_addButton( wid, -20, 20, 120, 30,
724 "btnOK", _(
"OK"), dialogue_listClose );
725 window_addButton( wid, -20-120-20, 20, 120, 30,
726 "btnCancel", _(
"Cancel"), dialogue_listCancel );
736 return dialogue_listSelected;
760 window_addText(
choice_wid, 20, -40, w-40, h, 0,
"txtChoice",
828static int dialogue_custom_event(
unsigned int wid, SDL_Event *event )
836 if ((event->type==SDL_MOUSEBUTTONDOWN) ||
837 (
event->type==SDL_MOUSEBUTTONUP) ||
838 (event->type==SDL_MOUSEMOTION)) {
843 if ((mx < 0) || (mx >= cd->w) || (my < 0) || (my >= cd->h))
845 event->button.x = mx;
846 event->button.y = my;
849 return (*cd->event)( wid, event, cd->data );
864 int (*update) (
double dt,
void* data),
865 void (*render) (
double x,
double y,
double w,
double h,
void* data),
866 int (*event) (
unsigned int wid, SDL_Event* event,
void* data),
867 void* data,
int autofree )
872 int done, fullscreen;
873 int wx, wy, wgtx, wgty;
875 fullscreen = ((width < 0) && (height < 0));
883 wid =
window_create(
"dlgMsg", caption, -1, -1, width+40, height+60 );
896 window_addCust( wid, wgtx, wgty, width, height,
"cstCustom", 0, render, NULL, NULL, NULL, data );
898 window_custAutoFreeData( wid,
"cstCustom" );
899 window_custSetClipping( wid,
"cstCustom", 1 );
939 cd->last_w = cd->w+40;
940 cd->last_h = cd->h+60;
993 unsigned int time_ms = SDL_GetTicks();
1016 if (event.type == SDL_QUIT) {
1026 SDL_PushEvent( &event );
1029 else if (event.type == SDL_WINDOWEVENT &&
1030 event.window.event == SDL_WINDOWEVENT_RESIZED)
1039 dt = (double)(t -
time_ms) / 1000.;
1043 double delay = fps_max - dt;
1044 SDL_Delay( (
unsigned int)(delay * 1000.) );
1050 if ((*du->update)(dt, du->data)) {
1061 WARN(_(
"Dialogue counter not in sync!"));
static char * choice_result
static int toolkit_loop(int *loop_done, dialogue_update_t *du)
Creates a secondary loop until loop_done is set to 1 or the toolkit closes.
char * dialogue_runChoice(void)
Run the dialog and return the clicked string.
char * dialogue_inputRaw(const char *title, int min, int max, const char *msg)
Creates a dialogue that allows the player to write a message.
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
static void dialogue_choiceClose(unsigned int wid, const char *str)
Closes a choice dialogue.
void main_loop(int update)
Split main loop from main() for secondary loop hack in toolkit.c.
int dialogue_listPanelRaw(const char *title, char **items, int nitems, int extrawidth, int minheight, void(*add_widgets)(unsigned int wid, int x, int y, int w, int h), void(*select_call)(unsigned int wid, const char *wgtname, int x, int y, int w, int h), const char *msg)
Creates a list dialogue with OK and Cancel buttons, with a fixed message, as well as a small extra ar...
char * dialogue_input(const char *title, int min, int max, const char *fmt,...)
Creates a dialogue that allows the player to write a message.
int dialogue_listRaw(const char *title, char **items, int nitems, const char *msg)
Creates a list dialogue with OK and Cancel button.
static void dialogue_close(unsigned int wid, const char *str)
Generic window close.
static void select_call_wrapper(unsigned int wid, const char *wgtname)
used to pass appropriate information to the method that handles updating the extra information area i...
int dialogue_YesNoRaw(const char *caption, const char *msg)
Runs a dialogue with both yes and no options.
int dialogue_listPanel(const char *title, char **items, int nitems, int extrawidth, int minheight, void(*add_widgets)(unsigned int wid, int x, int y, int w, int h), void(*select_call)(unsigned int wid, const char *wgtname, int x, int y, int w, int h), const char *fmt,...)
Creates a list dialogue with OK and Cancel buttons, with a fixed message, as well as a small extra ar...
void dialogue_custom(const char *caption, int width, int height, int(*update)(double dt, void *data), void(*render)(double x, double y, double w, double h, void *data), int(*event)(unsigned int wid, SDL_Event *event, void *data), void *data, int autofree)
Opens a custom dialogue window.
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
int dialogue_list(const char *title, char **items, int nitems, const char *fmt,...)
Creates a list dialogue with OK and Cancel button with a fixed message.
void dialogue_addChoice(const char *caption, const char *msg, const char *opt)
Add a choice to the dialog.
static glFont * dialogue_getSize(const char *title, const char *msg, int *width, int *height)
Gets the size needed for the dialogue.
int dialogue_customResize(int width, int height)
Resizes a custom dialogue.
void dialogue_msgImgRaw(const char *caption, const char *msg, const char *img, int width, int height)
Opens a dialogue window with an ok button, a fixed message and an image.
void dialogue_makeChoice(const char *caption, const char *msg, int opts)
Create the choice dialog. Need to add choices with below method.
static void dialogue_inputClose(unsigned int wid, const char *str)
Closes an input dialogue.
static unsigned int choice_wid
void dialogue_msgRaw(const char *caption, const char *msg)
Opens a dialogue window with an ok button and a fixed message.
int dialogue_isOpen(void)
Checks to see if a dialogue is open.
static InputDialogue input_dialogue
static void dialogue_cancel(unsigned int wid, const char *str)
Generic window cancel.
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
int dialogue_customFullscreen(int enable)
Converts a custom dialogue to fullscreen.
void dialogue_msgImg(const char *caption, const char *img, const char *fmt,...)
Opens a dialogue window with an ok button, a message and an image.
static void dialogue_YesNoClose(unsigned int wid, const char *str)
Closes a yesno dialogue.
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
static unsigned int time_ms
void naev_quit(void)
Flags naev to quit.
void naev_resize(void)
Wrapper for gl_resize that handles non-GL reinitialization.
int naev_isQuit(void)
Get if Naev is trying to quit.
Header file with generic functions and naev-specifics.
void gl_windowToScreenPos(int *sx, int *sy, int wx, int wy)
Translates the window position to screen position.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Represents a font in memory.
Abstraction for rendering sprite sheets.