// The dialog handler borrows heavily from the newmenu_handler static int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) { int rval = 0; if (event->type == EVENT_WINDOW_CLOSED || event->type == EVENT_WINDOW_ACTIVATED || event->type == EVENT_WINDOW_DEACTIVATED) return 0; if (dlg->callback) if ((*dlg->callback)(dlg, event, dlg->userdata)) return 1; // event handled if (!window_exists(wind)) return 1; switch (event->type) { case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: case EVENT_MOUSE_MOVED: /*return*/ ui_dialog_do_gadgets(dlg, event); if (!window_exists(wind)) return 1; rval = mouse_in_window(dlg->wind); break; case EVENT_KEY_COMMAND: case EVENT_KEY_RELEASE: rval = ui_dialog_do_gadgets(dlg, event); break; case EVENT_IDLE: timer_delay2(50); rval = ui_dialog_do_gadgets(dlg, event); break; case EVENT_WINDOW_DRAW: { d_event event2 = { EVENT_UI_DIALOG_DRAW }; ui_dialog_draw(dlg); rval = ui_dialog_do_gadgets(dlg, event); window_send_event(wind, &event2); break; } case EVENT_WINDOW_CLOSE: ui_gadget_delete_all(dlg); selected_gadget = NULL; d_free( dlg ); break; default: break; } return rval; }
/** * @brief Closes the main menu. */ void menu_main_close (void) { if (window_exists("Main Menu")) window_destroy( window_get("Main Menu") ); menu_Close(MENU_MAIN); }
// Process the first event in queue, sending to the appropriate handler // This is the new object-oriented system // Uses the old system for now, but this may change void event_process(void) { d_event event; window *wind = window_get_front(); timer_update(); event_poll(); // send input events first // Doing this prevents problems when a draw event can create a newmenu, // such as some network menus when they report a problem if (window_get_front() != wind) return; event.type = EVENT_WINDOW_DRAW; // then draw all visible windows wind = window_get_first(); while (wind != NULL) { window *prev = window_get_prev(wind); if (window_is_visible(wind)) window_send_event(wind, &event); if (!window_exists(wind)) { if (!prev) // well there isn't a previous window ... break; // ... just bail out - we've done everything for this frame we can. wind = window_get_next(prev); // the current window seemed to be closed. so take the next one from the previous which should be able to point to the one after the current closed } else wind = window_get_next(wind); } gr_flip(); }
int GetKeyCode(char * text) { UI_DIALOG * dlg; window *wind; key_dialog k; text = text; dlg = ui_create_dialog( 200, 200, 400, 200, DF_DIALOG | DF_MODAL, (int (*)(UI_DIALOG *, d_event *, void *))key_dialog_handler, &k ); k.DoneButton = ui_add_gadget_button( dlg, 170, 165, 60, 25, "Ok", NULL ); strcpy(k.text, ""); ui_gadget_calc_keys(dlg); //key_flush(); dlg->keyboard_focus_gadget = (UI_GADGET *)k.DoneButton; wind = ui_dialog_get_window(dlg); while (window_exists(wind)) event_process(); return 0; }
/** * @brief Opens the console. */ void cli_open (void) { unsigned int wid; /* Lazy loading. */ if (cli_state == NULL) if (cli_init()) return; /* Must not be already open. */ if (window_exists( "Lua Console" )) return; /* Create the window. */ wid = window_create( "Lua Console", -1, -1, cli_width, cli_height ); /* Window settings. */ window_setAccept( wid, cli_input ); window_setCancel( wid, window_close ); window_handleKeys( wid, cli_keyhandler ); /* Input box. */ window_addInput( wid, 20, 20, cli_width-60-BUTTON_WIDTH, BUTTON_HEIGHT, "inpInput", LINE_LENGTH, 1 ); /* Buttons. */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Custom console widget. */ window_addCust( wid, 20, -40, cli_width-40, cli_height-80-BUTTON_HEIGHT, "cstConsole", 0, cli_render, NULL ); }
/** * @brief Closes the main menu. */ void menu_main_close (void) { if (window_exists("Main Menu")) window_destroy( window_get("Main Menu") ); else WARN( _("Main menu does not exist.") ); menu_Close(MENU_MAIN); pause_game(); }
/** * @brief Opens the console. */ void cli_open (void) { unsigned int wid; /* Lazy loading. */ if (cli_state == NULL) if (cli_init()) return; /* Make sure main menu isn't open. */ if (menu_isOpen(MENU_MAIN)) return; /* Must not be already open. */ if (window_exists( "Lua Console" )) return; /* Put a friendly message at first. */ if (cli_firstOpen) { char buf[256]; cli_addMessage( "" ); cli_addMessage( "\egWelcome to the Lua console!" ); nsnprintf( buf, sizeof(buf), "\eg "APPNAME" v%s", naev_version(0) ); cli_addMessage( buf ); cli_addMessage( "" ); cli_firstOpen = 0; } /* Create the window. */ wid = window_create( "Lua Console", -1, -1, CLI_WIDTH, CLI_HEIGHT ); /* Window settings. */ window_setAccept( wid, cli_input ); window_setCancel( wid, window_close ); window_handleKeys( wid, cli_keyhandler ); /* Input box. */ window_addInput( wid, 20, 20, CLI_WIDTH-60-BUTTON_WIDTH, BUTTON_HEIGHT, "inpInput", LINE_LENGTH, 1, cli_font ); /* Buttons. */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Custom console widget. */ window_addCust( wid, 20, -40, CLI_WIDTH-40, CLI_HEIGHT-80-BUTTON_HEIGHT, "cstConsole", 0, cli_render, NULL, NULL ); /* Cache current height in case the window is resized. */ cli_height = CLI_HEIGHT; }
/* * Look for XMesaBuffers whose X window has been destroyed. * Deallocate any such XMesaBuffers. */ void XMesaGarbageCollect( XMesaDisplay* dpy ) { XMesaBuffer b, next; for (b=XMesaBufferList; b; b=next) { next = b->Next; if (b->display && b->display == dpy && b->frontxrb->drawable && b->type == WINDOW) { XSync(b->display, False); if (!window_exists( b->display, b->frontxrb->drawable )) { /* found a dead window, free the ancillary info */ XMesaDestroyBuffer( b ); } } } }
void event_send(d_event *event) { window *wind; int handled = 0; for (wind = window_get_front(); wind != NULL && !handled; wind = window_get_prev(wind)) if (window_is_visible(wind)) { handled = window_send_event(wind, event); if (!window_exists(wind)) // break away if necessary: window_send_event() could have closed wind by now break; if (window_is_modal(wind)) break; } if (!handled) call_default_handler(event); }
void kmatrix_view(int network) { kmatrix_screen *km; window *wind; int i = 0; MALLOC(km, kmatrix_screen, 1); if (!km) return; gr_init_bitmap_data(&km->background); if (pcx_read_bitmap(STARS_BACKGROUND, &km->background, BM_LINEAR, gr_palette) != PCX_ERROR_NONE) { d_free(km); return; } gr_palette_load(gr_palette); km->network = network; km->end_time = -1; km->playing = 0; set_screen_mode( SCREEN_MENU ); game_flush_inputs(); for (i=0;i<MAX_PLAYERS;i++) digi_kill_sound_linked_to_object (Players[i].objnum); wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))kmatrix_handler, km); if (!wind) { d_free(km); return; } while (window_exists(wind)) event_process(); gr_free_bitmap_data(&km->background); d_free(km); }
/** * @brief Checks to see if comm is open. * * @return 1 if comm is open. */ int comm_isOpen (void) { return window_exists( "Communication Channel" ); }
/** * @brief Checks to see if the map is open. * * @return 0 if map is closed, non-zero if it's open. */ int map_isOpen (void) { return window_exists(MAP_WDWNAME); }
int ui_get_filename( char * filename, const char * filespec, const char * message ) { char InputText[PATH_MAX]; char *p; int i; file_browser *b; UI_DIALOG *dlg; window *wind; int rval = 0; MALLOC(b, file_browser, 1); if (!b) return 0; if ((p = strrchr(filename, '/'))) { *p++ = 0; strcpy(b->view_dir, filename); strcpy(InputText, p); } else { strcpy(b->view_dir, ""); strcpy(InputText, filename); } b->filename_list = file_getfilelist(&b->num_files, filespec, b->view_dir); if (!b->filename_list) { d_free(b); return 0; } b->directory_list = file_getdirlist(&b->num_dirs, b->view_dir); if (!b->directory_list) { PHYSFS_freeList(b->filename_list); d_free(b); return 0; } //ui_messagebox( -2,-2, 1,"DEBUG:0", "Ok" ); for (i=0; i<35; i++) b->spaces[i] = ' '; b->spaces[34] = 0; dlg = ui_create_dialog( 200, 100, 400, 370, static_cast<dialog_flags>(DF_DIALOG | DF_MODAL), (int (*)(UI_DIALOG *, d_event *, void *))browser_handler, b ); b->user_file = ui_add_gadget_inputbox( dlg, 60, 30, PATH_MAX, 40, InputText ); b->listbox1 = ui_add_gadget_listbox(dlg, 20, 110, 125, 200, b->num_files, b->filename_list); b->listbox2 = ui_add_gadget_listbox(dlg, 210, 110, 100, 200, b->num_dirs, b->directory_list); b->button1 = ui_add_gadget_button( dlg, 20, 330, 60, 25, "Ok", NULL ); b->button2 = ui_add_gadget_button( dlg, 100, 330, 60, 25, "Cancel", NULL ); b->help_button = ui_add_gadget_button( dlg, 180, 330, 60, 25, "Help", NULL ); dlg->keyboard_focus_gadget = (UI_GADGET *)b->user_file; b->button1->hotkey = KEY_CTRLED + KEY_ENTER; b->button2->hotkey = KEY_ESC; b->help_button->hotkey = KEY_F1; b->listbox1->hotkey = KEY_ALTED + KEY_F; b->listbox2->hotkey = KEY_ALTED + KEY_D; b->user_file->hotkey = KEY_ALTED + KEY_A; ui_gadget_calc_keys(dlg); b->filename = filename; b->filespec = filespec; b->message = message; wind = ui_dialog_get_window(dlg); while (window_exists(wind)) event_process(); //key_flush(); if (b->filename_list) PHYSFS_freeList(b->filename_list); if (b->directory_list) PHYSFS_freeList(b->directory_list); rval = b->filename_list != NULL; d_free(b); return rval; }
//if filename passed is NULL, show normal credits void credits_show(char *credits_filename) { credits *cr; window *wind; int i; int pcx_error; char * tempp; char filename[32]; ubyte backdrop_palette[768]; MALLOC(cr, credits, 1); if (!cr) return; cr->have_bin_file = 0; cr->buffer_line = 0; cr->first_line_offset = 0; cr->extra_inc = 0; cr->done = 0; cr->row = 0; // Clear out all tex buffer lines. for (i=0; i<NUM_LINES; i++ ) cr->buffer[i][0] = 0; sprintf(filename, "%s", CREDITS_FILE); cr->have_bin_file = 0; if (credits_filename) { strcpy(filename,credits_filename); cr->have_bin_file = 1; } cr->file = PHYSFSX_openReadBuffered( filename ); if (cr->file == NULL) { char nfile[32]; if (credits_filename) { d_free(cr); return; //ok to not find special filename } tempp = strchr(filename, '.'); *tempp = '\0'; sprintf(nfile, "%s.txb", filename); cr->file = PHYSFSX_openReadBuffered(nfile); if (cr->file == NULL) Error("Missing CREDITS.TEX and CREDITS.TXB file\n"); cr->have_bin_file = 1; } set_screen_mode(SCREEN_MENU); gr_use_palette_table( "credits.256" ); cr->backdrop.bm_data=NULL; pcx_error = pcx_read_bitmap(STARS_BACKGROUND,&cr->backdrop, BM_LINEAR,backdrop_palette); if (pcx_error != PCX_ERROR_NONE) { PHYSFS_close(cr->file); d_free(cr); return; } songs_play_song( SONG_CREDITS, 1 ); gr_remap_bitmap_good( &cr->backdrop,backdrop_palette, -1, -1 ); gr_set_current_canvas(NULL); show_fullscr(&cr->backdrop); gr_palette_load( gr_palette ); key_flush(); wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))credits_handler, cr); if (!wind) { d_event event = { EVENT_WINDOW_CLOSE }; credits_handler(NULL, &event, cr); return; } while (window_exists(wind)) event_process(); }