void update_game(float dt) { if (is_key_down('a')) camera.moveLeft(dt); else if (is_key_down('d')) camera.moveRight(dt); if (is_key_down('w')) camera.moveForward(dt); else if (is_key_down('s')) camera.moveBackward(dt); if (is_key_down(SDLK_LCTRL)) camera.moveDown(dt); else if (is_key_down(SDLK_SPACE)) camera.moveUp(dt); if (is_mouse_down(MouseButtonLeft)) { vec2i m = get_mouse_pos(); float dx = (m.x - window_width / 2) / (float)window_width; float dy = (m.y - window_height / 2) / (float)window_height; float speed = 5.0f; camera.rotateHorizontal(speed * sqrt(abs(dx)) * dx * dt); camera.rotateVertical(speed * sqrt(abs(dy)) * dy * dt); } mat_view = camera.getViewMatrix(); float t = get_elapsed_time(); mat_projection = perspective(PI / 4.0f, window_width / float(window_height), 0.2f, 20.0f); //mat_view = translate(0.0f, -0.7f, -2.0f) * rotateX(-0.13f) * rotateY(t); }
int WndForm::ShowModal() { assert_none_locked(); #define OPENCLOSESUPPRESSTIME 500 #ifndef USE_GDI ContainerWindow *root = GetRootOwner(); WindowReference old_focus_reference = root->GetFocusedWindowReference(); #else HWND oldFocusHwnd; #endif /* USE_GDI */ PeriodClock enter_clock; if (IsEmbedded() && !IsAltair()) enter_clock.Update(); show_on_top(); modal_result = 0; #ifdef USE_GDI oldFocusHwnd = ::GetFocus(); if (oldFocusHwnd != NULL) ::SendMessage(oldFocusHwnd, WM_CANCELMODE, 0, 0); #endif /* USE_GDI */ set_focus(); if (default_focus) default_focus->set_focus(); else FocusFirstControl(); bool hastimed = false; WndForm::time_any_open_close.Update(); // when current dlg opens or child closes main_window.AddDialog(this); #ifndef USE_GDI main_window.refresh(); #endif #ifdef ANDROID EventLoop loop(*event_queue, main_window); Event event; #elif defined(ENABLE_SDL) EventLoop loop(main_window); SDL_Event event; #else DialogEventLoop loop(*this); MSG event; #endif while ((modal_result == 0 || force) && loop.Get(event)) { #if defined(ENABLE_SDL) && !defined(ANDROID) if (event.type == SDL_QUIT) { modal_result = mrCancel; continue; } #endif if (!main_window.FilterEvent(event, this)) { if (modeless && is_mouse_down(event)) break; else continue; } // hack to stop exiting immediately if (IsEmbedded() && !IsAltair() && !hastimed && IsUserInput(event)) { if (!enter_clock.Check(200)) /* ignore user input in the first 200ms */ continue; else hastimed = true; } if (IsEmbedded() && is_mouse_up(event) && !time_any_open_close.Check(OPENCLOSESUPPRESSTIME)) /* prevents child click from being repeat-handled by parent if buttons overlap */ continue; if (key_down_notify_callback != NULL && is_key_down(event) && #ifdef USE_GDI identify_descendant(event.hwnd) && #endif !check_special_key(this, event) && key_down_notify_callback(*this, get_key_code(event))) continue; #if defined(ENABLE_SDL) && !defined(ANDROID) if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_TAB) { /* the Tab key moves the keyboard focus */ const Uint8 *keystate = ::SDL_GetKeyState(NULL); event.key.keysym.sym = keystate[SDLK_LSHIFT] || keystate[SDLK_RSHIFT] ? SDLK_UP : SDLK_DOWN; } #endif if (is_key_down(event) && #ifdef USE_GDI identify_descendant(event.hwnd) && #endif (get_key_code(event) == VK_UP || get_key_code(event) == VK_DOWN)) { /* VK_UP and VK_DOWN move the focus only within the current control group - but we want it to behave like Shift-Tab and Tab */ if (!check_key(this, event)) { /* this window doesn't handle VK_UP/VK_DOWN */ if (get_key_code(event) == VK_DOWN) FocusNextControl(); else FocusPreviousControl(); continue; } } #ifndef USE_GDI if (is_key_down(event) && get_key_code(event) == VK_ESCAPE) { modal_result = mrCancel; continue; } #endif /* map VK_ESCAPE to mrOK on Altair, because the Escape key is expected to be the one that saves and closes a dialog */ if (IsAltair() && is_key_down(event) && get_key_code(event) == VK_ESCAPE) { modal_result = mrOK; continue; } loop.Dispatch(event); } // End Modal Loop main_window.RemoveDialog(this); // static. this is current open/close or child open/close WndForm::time_any_open_close.Update(); #ifdef USE_GDI SetFocus(oldFocusHwnd); #else if (old_focus_reference.Defined()) { Window *old_focus = old_focus_reference.Get(*root); if (old_focus != NULL) old_focus->set_focus(); } #endif /* !USE_GDI */ return modal_result; }