/* Ask a new key */ static int set_player_key (MenuCommand cmd, struct MenuItem * item) { if (cmd != MNU_ENTER) return 0; intro_message ("Press a key"); intr_message.setkey = &game_settings.controller[item->parent->ID].keys[item->ID-2]; draw_intro_screen (); intro_event_loop (); return 1; }
//*********************************************************************** static LRESULT CALLBACK TermProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static bool main_timer_ran_once = false ; static uint quarter_seconds = 0 ; // static uint curr_redraw_counts = 0 ; // static uint ref_redraw_counts = 0 ; //*************************************************** // debug: log all windows messages //*************************************************** if (dbg_flags & DBG_WINMSGS) { switch (iMsg) { // list messages to be ignored case WM_CTLCOLORBTN: case WM_CTLCOLORSTATIC: case WM_CTLCOLOREDIT: case WM_CTLCOLORDLG: case WM_MOUSEMOVE: case 295: // WM_CHANGEUISTATE case WM_NCMOUSEMOVE: case WM_NCMOUSELEAVE: case WM_NCHITTEST: case WM_SETCURSOR: case WM_ERASEBKGND: case WM_TIMER: case WM_NOTIFY: case WM_COMMAND: // prints its own msgs below break; default: syslog("TOP [%s]\n", lookup_winmsg_name(iMsg)) ; break; } } switch(iMsg) { case WM_INITDIALOG: do_init_dialog(hwnd) ; // wpOrigMainProc = (WNDPROC) SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG) MainSubclassProc); return TRUE; //******************************************************************** case WM_TIMER: switch (wParam) { case IDT_TIMER_MAIN: if (!main_timer_ran_once) { main_timer_ran_once = true ; KillTimer(hwnd, main_timer_id) ; draw_intro_screen(hwnd) ; prog_init_done = true ; // main_timer_id = SetTimer(hwnd, IDT_TIMER_MAIN, 1000, (TIMERPROC) NULL) ; main_timer_id = SetTimer(hwnd, IDT_TIMER_MAIN, 244, (TIMERPROC) NULL) ; } else { if (++quarter_seconds >= 4) { quarter_seconds = 0 ; update_cursor() ; } // syslog("next_timer...redraw_in_progress=%s\n", (redraw_in_progress) ? "true" : "false") ; if (redraw_in_progress) { // syslog("redraw counts: %u vs %u\n", curr_redraw_counts, ref_redraw_counts) ; // if (ref_redraw_counts != 0 && ref_redraw_counts == curr_redraw_counts) { // syslog("redraw main screen\n") ; redraw_in_progress = false ; if (!is_intro_screen_active()) { draw_current_screen() ; show_treasures() ; } // } // ref_redraw_counts = curr_redraw_counts ; } } return TRUE; default: break; // return DefWindowProcA(hwnd, iMsg, wParam, lParam); } break; case WM_NOTIFY: return term_notify(hwnd, lParam) ; //*********************************************************************************************** // 04/16/14 - unfortunately, I cannot use WM_SIZE, nor any other message, to draw my graphics, // because some other message occurs later and over-writes my work... //*********************************************************************************************** case WM_SIZE: if (wParam == SIZE_RESTORED) { // syslog("WM_SIZE\n") ; redraw_in_progress = true ; } //******************************************************************************************** // The last operations in the dialog redraw, are subclassed WM_CTLCOLORSTATIC messages. // So, to determine when it is all done, I need to somehow recognize when these are done, // and then update our graphics objects. //******************************************************************************************** return TRUE; // this occurs during program startup case WM_ERASEBKGND: // syslog("WM_ERASEBKGND\n") ; redraw_in_progress = true ; break; case WM_COMMAND: { // create local context DWORD cmd = HIWORD (wParam) ; DWORD target = LOWORD(wParam) ; switch (cmd) { case FVIRTKEY: // keyboard accelerators: WARNING: same code as CBN_SELCHANGE !! // fall through to BM_CLICKED, which uses same targets case BN_CLICKED: switch(target) { case IDB_HELP: queryout("Terminal keyboard shortcuts") ; infoout("Alt-s = send command (i.e., print command in terminal)") ; infoout("Alt-h = show this help screen") ; infoout("Alt-c = Close this program") ; break; case IDB_CLOSE: PostMessageA(hwnd, WM_CLOSE, 0, 0); break; } //lint !e744 switch target return true; } //lint !e744 switch cmd break; } //lint !e438 !e10 end local context //******************************************************************** // application shutdown handlers //******************************************************************** case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; // default: // return false; } //lint !e744 switch(iMsg) return false; }
/* Intro screen eventloop */ static int intro_event_loop (void) { Uint8 needupdate, rval, isevent; SDL_Event Event; Sint8 command; Uint32 delay, lasttime; while (1) { if (game_settings.mbg_anim) { needupdate = 1; isevent = SDL_PollEvent (&Event); } else { needupdate = 0; isevent = 1; if (!SDL_WaitEvent (&Event)) { printf ("Error occured while waiting for an event: %s\n", SDL_GetError ()); exit (1); } } if (isevent) switch (Event.type) { case SDL_KEYDOWN: command = -1; if (intr_message.show) { intr_message.show = 0; if (intr_message.setkey) { *intr_message.setkey = Event.key.keysym.sym; intr_message.setkey = NULL; return 0; } needupdate = 1; } else { if (Event.key.keysym.sym == SDLK_F11) screenshot (); else if (Event.key.keysym.sym == SDLK_UP) command = MNU_UP; else if (Event.key.keysym.sym == SDLK_DOWN) command = MNU_DOWN; else if (Event.key.keysym.sym == SDLK_LEFT) command = MNU_LEFT; else if (Event.key.keysym.sym == SDLK_RIGHT) command = MNU_RIGHT; else if (Event.key.keysym.sym == SDLK_RETURN) { if((Event.key.keysym.mod & (KMOD_LALT|KMOD_RALT))) toggle_fullscreen(); else command = MNU_ENTER; } else if (Event.key.keysym.sym == SDLK_ESCAPE) command = MNU_BACK; } if (command >= 0) { if (command != MNU_ENTER && command != MNU_BACK) playwave (WAV_BLIP); else playwave (WAV_BLIP2); rval = menu_control (&intro_menu, command); if (rval == INTRO_RVAL_STARTGAME || rval == INTRO_RVAL_EXIT) return rval; needupdate = 1; } break; case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: joystick_button (&Event.jbutton); break; case SDL_JOYAXISMOTION: joystick_motion (&Event.jaxis, 0); break; case SDL_QUIT: exit(0); default: break; } if (!(game_settings.mbg_anim && isevent)) { lasttime = SDL_GetTicks (); if (needupdate) draw_intro_screen (); if (game_settings.mbg_anim) { delay = SDL_GetTicks () - lasttime; if (delay >= 60) delay = 0; else delay = 60 - delay; SDL_Delay (delay); } } } /* Never reached */ return 0; }
/* The intro and settings screens */ int game_menu_screen (void) { draw_intro_screen (); return intro_event_loop (); }