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];
140 vsnprintf(msg,
sizeof(msg), fmt, ap);
154 unsigned int msg_wid;
156 const char *caption = _(
"Warning");
161 msg_wid =
window_create(
"dlgAlert", caption, -1, -1, w, 110 + h );
163 window_addText( msg_wid, 20, -40, w-40, h, 0,
"txtMsg",
165 window_addButton( msg_wid, (w-50)/2, 20, 50, 30,
"btnOK", _(
"OK"),
181 const char* msg,
int* width,
int* height )
185 int i, titlelen, msglen;
200 if (msglen < (260 + i * 50) * (2 + i))
204 w =
MAX(w, titlelen+40);
210 d = ((double)w/(double)h)*(3./4.);
238 vsnprintf(msg,
sizeof(msg), fmt, ap);
259 vsnprintf(msg,
sizeof(msg), fmt, ap);
274 unsigned int msg_wid;
279 msg_wid =
window_create(
"dlgMsg", caption, -1, -1, w, 110 + h );
281 window_addText( msg_wid, 20, -40, w-40, h, 0,
"txtMsg",
283 window_addButton( msg_wid, (w-50)/2, 20, 50, 30,
"btnOK", _(
"OK"),
298void dialogue_msgImgRaw(
const char* caption,
const char *msg,
const char *img,
int width,
int height )
300 int w, h, img_width, img_height;
302 unsigned int msg_wid;
309 snprintf( buf,
sizeof(buf),
"%s%s", GFX_PATH, img );
315 img_width = (width < 0) ? gfx->
w : width;
316 img_height = (height < 0) ? gfx->
h : height;
323 msg_wid =
window_create(
"dlgMsgImg", caption, -1, -1, img_width + w, 110 + h );
327 window_addText( msg_wid, img_width+40, -40, w-40, h, 0,
"txtMsg",
331 window_addRect( msg_wid, 20, -40, img_width, img_height,
332 "rctGFX", &cGrey10, 1 );
335 window_addImage( msg_wid, 20, -40, img_width, img_height,
339 window_addButton( msg_wid, (img_width+w -50)/2, 20, 50, 30,
"btnOK", _(
"OK"),
360 vsnprintf(msg,
sizeof(msg), fmt, ap);
378 char buf[STRMAX_SHORT];
382 snprintf( buf,
sizeof(buf),
"dlgYesNo%d", ++
dlgid );
386 window_addText( wid, 20, -40, w-40, h, 0,
"txtYesNo",
389 window_addButtonKey( wid, w/2-100-10, 20, 100, 30,
"btnYes", _(
"Yes"),
391 window_addButtonKey( wid, w/2+10, 20, 100, 30,
"btnNo", _(
"No"),
411 int *loop_done, result;
414 if (strcmp(str,
"btnYes")==0)
416 else if (strcmp(str,
"btnNo")==0)
419 WARN(_(
"Unknown button clicked in YesNo dialogue!"));
426 loop_done[1] = result;
452 vsnprintf(msg,
sizeof(msg), fmt, ap);
499 while ((done >= 0) && (!input ||
500 ((
int)strlen(input) < min))) {
504 "Input must be at least %d character long!",
505 "Input must be at least %d characters long!", min),
546static int dialogue_listSelected = -1;
547static void dialogue_listCancel(
unsigned int wid,
const char *str )
549 dialogue_listSelected = -1;
552static void dialogue_listClose(
unsigned int wid,
const char *str )
554 dialogue_listSelected = toolkit_getListPos( wid,
"lstDialogue" );
580int dialogue_list(
const char* title,
char **items,
int nitems,
const char *fmt, ... )
582 char msg[STRMAX_SHORT];
590 vsnprintf(msg,
sizeof(msg), fmt, ap);
625 int minheight,
void (*add_widgets) (
unsigned int wid,
int x,
int y,
int w,
int h),
626 void (*select_call) (
unsigned int wid,
const char* wgtname,
int x,
int y,
int w,
int h),
627 const char *fmt, ... )
629 char msg[STRMAX_SHORT];
640 vsnprintf(msg,
sizeof(msg), fmt, ap);
644 add_widgets, select_call, msg );
663 int minheight,
void (*add_widgets) (
unsigned int wid,
int x,
int y,
int w,
int h),
664 void (*select_call) (
unsigned int wid,
const char* wgtname,
int x,
int y,
int w,
int h),
668 int w, h, winw, winh;
671 int list_width, list_height;
672 int text_height, text_width;
682 for (i=0; i<nitems; i++) {
687 if (list_height > 500)
688 h = (list_height*8)/10;
690 h =
MAX( 300, list_height );
692 h =
MIN( ((
double)SCREEN_H*2.)/3., h );
693 w =
MAX( list_width + 60, 500 );
695 winw = w + extrawidth;
696 winh =
MAX( h, minheight );
701 wid =
window_create(
"dlgListPanel", title, -1, -1, winw, winh );
703 window_addText( wid, 20, -40, w-40, text_height, 0,
"txtMsg",
709 add_widgets(wid, w, 0, winw, winh);
720 window_addList( wid, 20, -40-text_height-20,
721 w-40, h - (40+text_height+20) - (20+30+20),
723 dialogue_listClose );
726 window_addButton( wid, -20, 20, 120, 30,
727 "btnOK", _(
"OK"), dialogue_listClose );
728 window_addButton( wid, -20-120-20, 20, 120, 30,
729 "btnCancel", _(
"Cancel"), dialogue_listCancel );
739 return dialogue_listSelected;
763 window_addText(
choice_wid, 20, -40, w-40, h, 0,
"txtChoice",
831static int dialogue_custom_event(
unsigned int wid, SDL_Event *event )
839 if ((event->type==SDL_MOUSEBUTTONDOWN) ||
840 (event->type==SDL_MOUSEBUTTONUP) ||
841 (event->type==SDL_MOUSEMOTION)) {
846 if ((mx < 0) || (mx >= cd->w) || (my < 0) || (my >= cd->h))
848 event->button.x = mx;
849 event->button.y = my;
852 return (*cd->event)( wid, event, cd->data );
868 int (*update) (
double dt,
void* data),
869 void (*render) (
double x,
double y,
double w,
double h,
void* data),
870 int (*event) (
unsigned int wid, SDL_Event* event,
void* data),
871 void* data,
int autofree,
int dynamic )
876 int done, fullscreen;
877 int wx, wy, wgtx, wgty;
879 fullscreen = ((width < 0) && (height < 0));
887 wid =
window_create(
"dlgMsg", caption, -1, -1, width+40, height+60 );
899 window_addCust( wid, wgtx, wgty, width, height,
"cstCustom", 0, render, NULL, NULL, NULL, data );
901 window_custSetDynamic( wid,
"cstCustom", 1 );
903 window_custAutoFreeData( wid,
"cstCustom" );
904 window_custSetClipping( wid,
"cstCustom", 1 );
944 cd->last_w = cd->w+40;
945 cd->last_h = cd->h+60;
998 Uint64
time_ms = SDL_GetTicks64();
1021 if (event.type == SDL_QUIT) {
1022 if (menu_askQuit()) {
1031 SDL_PushEvent( &event );
1034 else if (event.type == SDL_WINDOWEVENT &&
1035 event.window.event == SDL_WINDOWEVENT_RESIZED)
1043 t = SDL_GetTicks64();
1044 dt = (double)(t -
time_ms) / 1000.;
1048 double delay = fps_max - dt;
1049 SDL_Delay( (
unsigned int)(delay * 1000.) );
1055 if ((*du->update)(dt, du->data)) {
1066 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.
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.
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, int dynamic)
Opens a custom dialogue window.
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_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.
void dialogue_alertRaw(const char *msg)
Displays an alert popup with only an ok button and a message.
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 main_loop(int nested)
Split main loop from main() for secondary loop hack in toolkit.c.
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.
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.