42typedef struct dialogue_update_s {
44 int ( *update )( double,
void * );
48 int ( *event )(
unsigned int, SDL_Event *,
void * );
57static int dialogue_custom_event(
unsigned int wid, SDL_Event *event );
73static void dialogue_listClose(
unsigned int wid,
const char *str );
74static void dialogue_listCancel(
unsigned int wid,
const char *str );
81typedef struct InputDialogue_ {
132 char msg[STRMAX_SHORT];
138 vsnprintf( msg,
sizeof( msg ), fmt, ap );
152 unsigned int msg_wid;
154 const char *caption = _(
"Warning" );
159 msg_wid =
window_create(
"dlgAlert", caption, -1, -1, w, 110 + h );
161 window_addText( msg_wid, 20, -40, w - 40, h, 0,
"txtMsg", font, NULL, msg );
162 window_addButton( msg_wid, ( w - 50 ) / 2, 20, 50, 30,
"btnOK", _(
"OK" ),
182 int i, titlelen, msglen;
196 for ( i = 0; i < 11; i++ )
197 if ( msglen < ( 260 + i * 50 ) * ( 2 + i ) )
201 w =
MAX( w, titlelen + 40 );
207 d = ( (double)w / (double)h ) * ( 3. / 4. );
208 if (
FABS(
d ) > 0.3 ) {
235 vsnprintf( msg,
sizeof( msg ), fmt, ap );
257 vsnprintf( msg,
sizeof( msg ), fmt, ap );
272 unsigned int msg_wid;
277 msg_wid =
window_create(
"dlgMsg", caption, -1, -1, w, 110 + h );
279 window_addText( msg_wid, 20, -40, w - 40, h, 0,
"txtMsg", font, NULL, msg );
280 window_addButton( msg_wid, ( w - 50 ) / 2, 20, 50, 30,
"btnOK", _(
"OK" ),
297 int width,
int height )
299 int w, h, img_width, img_height;
301 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;
318 if ( h < img_width ) {
324 window_create(
"dlgMsgImg", caption, -1, -1, img_width + w, 110 + h );
328 window_addText( msg_wid, img_width + 40, -40, w - 40, h, 0,
"txtMsg", font,
332 window_addRect( msg_wid, 20, -40, img_width, img_height,
"rctGFX", &cGrey10,
336 window_addImage( msg_wid, 20, -40, img_width, img_height,
"ImgGFX", gfx, 0 );
339 window_addButton( msg_wid, ( img_width + w - 50 ) / 2, 20, 50, 30,
"btnOK",
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", font, NULL, msg );
388 window_addButtonKey( wid, w / 2 - 100 - 10, 20, 100, 30,
"btnYes",
390 window_addButtonKey( wid, w / 2 + 10, 20, 100, 30,
"btnNo", _(
"No" ),
410 int *loop_done, result;
413 if ( strcmp( str,
"btnYes" ) == 0 )
415 else if ( strcmp( str,
"btnNo" ) == 0 )
418 WARN( _(
"Unknown button clicked in YesNo dialogue!" ) );
425 loop_done[1] = result;
453 vsnprintf( msg,
sizeof( msg ), fmt, ap );
487 window_addText(
input_dialogue.input_wid, 20, -30, w, h, 0,
"txtInput", font,
490 window_addInput(
input_dialogue.input_wid, 20, 20 + 30 + 10, w, 30,
491 "inpInput", max, 1, NULL );
497 window_addButton(
input_dialogue.input_wid, -20, 20, 80, 30,
"btnClose",
503 while ( ( done >= 0 ) &&
505 ( (
int)strlen( input ) < min ) ) ) {
509 "Input must be at least %d characters long!",
525 strdup( window_getInput(
input_dialogue.input_wid,
"inpInput" ) );
529 if ( input != NULL ) {
552static int dialogue_listSelected = -1;
553static void dialogue_listCancel(
unsigned int wid,
const char *str )
555 dialogue_listSelected = -1;
558static void dialogue_listClose(
unsigned int wid,
const char *str )
560 dialogue_listSelected = toolkit_getListPos( wid,
"lstDialogue" );
588int dialogue_list(
const char *title,
char **items,
int nitems,
const char *fmt,
591 char msg[STRMAX_SHORT];
600 vsnprintf( msg,
sizeof( msg ), fmt, ap );
640 const char *title,
char **items,
int nitems,
int extrawidth,
int minheight,
641 void ( *add_widgets )(
unsigned int wid,
int x,
int y,
int w,
int h ),
642 void ( *select_call )(
unsigned int wid,
const char *wgtname,
int x,
int y,
644 const char *fmt, ... )
646 char msg[STRMAX_SHORT];
657 vsnprintf( msg,
sizeof( msg ), fmt, ap );
661 add_widgets, select_call, msg );
682 const char *title,
char **items,
int nitems,
int extrawidth,
int minheight,
683 void ( *add_widgets )(
unsigned int wid,
int x,
int y,
int w,
int h ),
684 void ( *select_call )(
unsigned int wid,
const char *wgtname,
int x,
int y,
689 int w, h, winw, winh;
692 int list_width, list_height;
693 int text_height, text_width;
704 for ( i = 0; i < nitems; i++ ) {
709 if ( list_height > 500 )
710 h = ( list_height * 8 ) / 10;
712 h =
MAX( 300, list_height );
714 h =
MIN( ( (
double)SCREEN_H * 2. ) / 3., h );
715 w =
MAX( list_width + 60, 500 );
717 winw = w + extrawidth;
718 winh =
MAX( h, minheight );
723 wid =
window_create(
"dlgListPanel", title, -1, -1, winw, winh );
725 window_addText( wid, 20, -40, w - 40, text_height, 0,
"txtMsg", font, NULL,
731 add_widgets( wid, w, 0, winw, winh );
742 window_addList( wid, 20, -40 - text_height - 20, w - 40,
743 h - ( 40 + text_height + 20 ) - ( 20 + 30 + 20 ),
745 dialogue_listClose );
748 window_addButton( wid, -20, 20, 120, 30,
"btnOK", _(
"OK" ),
749 dialogue_listClose );
750 window_addButton( wid, -20 - 120 - 20, 20, 120, 30,
"btnCancel",
751 _(
"Cancel" ), dialogue_listCancel );
761 return dialogue_listSelected;
786 window_addText(
choice_wid, 20, -40, w - 40, h, 0,
"txtChoice", font, NULL,
853static int dialogue_custom_event(
unsigned int wid, SDL_Event *event )
861 if ( ( event->type == SDL_MOUSEBUTTONDOWN ) ||
862 ( event->type == SDL_MOUSEBUTTONUP ) ||
863 ( event->type == SDL_MOUSEMOTION ) ) {
868 if ( ( mx < 0 ) || ( mx >= cd->w ) || ( my < 0 ) || ( my >= cd->h ) )
870 event->button.x = mx;
871 event->button.y = my;
874 return ( *cd->event )( wid, event, cd->data );
891 const char *wdwname,
const char *caption,
int width,
int height,
892 int ( *update )(
double dt,
void *data ),
893 void ( *render )(
double x,
double y,
double w,
double h,
void *data ),
894 int ( *event )(
unsigned int wid, SDL_Event *event,
void *data ),
void *data,
895 int dynamic,
void ( *freefunc )(
void *data ) )
900 int done, fullscreen;
901 int wx, wy, wgtx, wgty;
903 fullscreen = ( ( width < 0 ) && ( height < 0 ) );
910 wid =
window_create( wdwname, caption, -1, -1, width + 40, height + 60 );
921 window_addCust( wid, wgtx, wgty, width, height,
"cstCustom", 0, render, NULL,
924 window_custSetDynamic( wid,
"cstCustom", 1 );
925 if ( freefunc != NULL )
926 window_custFreeDataFunc( wid,
"cstCustom", freefunc );
927 window_custSetClipping( wid,
"cstCustom", 1 );
967 cd->last_w = cd->w + 40;
968 cd->last_h = cd->h + 60;
1021 Uint64
last_t = SDL_GetPerformanceCounter();
1022 const double fps_max =
1023 ( conf.fps_max > 0 ) ? 1. / (
double)conf.fps_max :
fps_min;
1044 while ( !
naev_isQuit() && SDL_PollEvent( &event ) ) {
1045 if ( event.type == SDL_QUIT ) {
1057 }
else if ( event.type == SDL_WINDOWEVENT &&
1058 event.window.event == SDL_WINDOWEVENT_RESIZED )
1066 t = SDL_GetPerformanceCounter();
1067 dt = (double)( t -
last_t ) / (double)SDL_GetPerformanceFrequency();
1070 if ( dt < fps_max ) {
1071 double delay = fps_max - dt;
1072 SDL_Delay( (
unsigned int)( delay * 1000. ) );
1078 if ( ( *du->update )( dt, du->data ) ) {
1089 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 dialogue_custom(const char *wdwname, 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 dynamic, void(*freefunc)(void *data))
Opens a custom dialogue window.
int dialogue_customFullscreen(unsigned int wid, int enable)
Converts a custom dialogue to fullscreen.
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...
int dialogue_customResize(unsigned int wid, int width, int height)
Resizes a custom dialogue.
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.
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.
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.