LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_SETCURSOR) { if (LOWORD(lParam) == HTCLIENT && !MouseShouldBeGrabbed()) { SetCursor(LoadCursor(NULL, IDC_ARROW)); return true; } } else if (msg == WM_SYSCOMMAND) { if ((wParam & 0xfff0) == SC_MAXIMIZE) { ToggleFullScreen(); return true; } else if ((wParam & 0xfff0) == SC_KEYMENU) return false; } else if (msg == WM_SYSKEYDOWN && wParam == VK_RETURN && !(lParam & 0x40000000)) { ToggleFullScreen(); return true; } else if (msg == WM_DEVICECHANGE) I_InitGamepad(); return CallWindowProc(oldProc, hwnd, msg, wParam, lParam); }
/*---------------------------------------------------------------------------*/ MainWindow::MainWindow( QWidget* pParent ): QMainWindow( pParent ) { CreateMenu( ); GLWidget* pGLWidget = new GLWidget( this ); connect( pGLWidget, SIGNAL( ToggleFullScreen( ) ), this, SLOT( ToggleFullScreen( ) ) ); setCentralWidget( pGLWidget ); resize( pGLWidget->width( ), pGLWidget->height( ) + menuBar( )->height( ) ); setWindowTitle( tr( "Color cube example" ) ); // 设置窗口标题 }
/** * Toggle fullscreen using the variable that is passed to us * @param fullscreen if true we want fullscreen on, otherwise it is off */ void GameEngine::ToggleFullScreen(bool fullscreen) { if( fullscreen ) { m_bFullscreen = false; ToggleFullScreen(); } else { m_bFullscreen = true; ToggleFullScreen(); } }
void VogueWindow::Create() { /* Initialize the window library */ if (!glfwInit()) { exit(EXIT_FAILURE); } /* Initialize any rendering params */ int samples = 8; glfwWindowHint(GLFW_SAMPLES, samples); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glGetIntegerv(GL_SAMPLES_ARB, &samples); /* Initialize the joysticks object */ memset(m_joysticks, 0, sizeof(m_joysticks)); /* Create a windowed mode window and it's OpenGL context */ m_pWindow = glfwCreateWindow(m_windowWidth, m_windowHeight, "Vogue", NULL, NULL); if (!m_pWindow) { glfwTerminate(); exit(EXIT_FAILURE); } /* Initialize this window object */ InitializeWindowContext(m_pWindow); if (m_pVogueSettings->m_fullscreen) { ToggleFullScreen(true); } }
void HandleKeyPressEvent(SDL_keysym * keysym) { switch(keysym -> sym) // which key have we got { case SDLK_F1 : // if it is F1 ToggleFullScreen(); // toggle between fullscreen and windowed mode break; case SDLK_ESCAPE: // if it is ESCAPE Quit(0); // quit after cleaning up case SDLK_UP : // If we hit the UP arrow Key case SDLK_w : upPressed = true; // make upPressed true break; case SDLK_DOWN : // If we hit the Down arrow Key case SDLK_s : downPressed = true; // make downPressed true break; default: // any other key break; // nothing to do } }
bool Renderer::SetFullScreen(bool fs) { if (fs == _scrFullScreen) return false; return ToggleFullScreen(); }
void HandleKeyPressEvent(SDL_keysym * keysym) { switch(keysym -> sym) // which key have we got { case SDLK_F1 : // if it is F1 ToggleFullScreen(); // toggle between fullscreen and windowed mode break; case SDLK_ESCAPE: // if it is ESCAPE Quit(0); // quit after cleaning up case SDLK_UP : // If we hit the UP arrow Key g_Camera.MoveCamera(kSpeed); // Move Camera by a forward positive speed RenderScene(); // Redraw the scene to reflect changes break; case SDLK_DOWN : // If we hit the Down arrow Key g_Camera.MoveCamera(-kSpeed); // Move Camera backward by a negative speed RenderScene(); // Redraw the scene to reflect changes break; default: // any other key break; // nothing to do } }
void VLCWindowsManager::OnMouseEvent( UINT uMouseMsg ) { switch( uMouseMsg ) { case WM_LBUTTONDBLCLK: ToggleFullScreen(); break; } }
void HandleKeyPressEvent(SDL_keysym * keysym) { switch(keysym -> sym) // which key have we got { case SDLK_F1 : // if it is F1 ToggleFullScreen(); // toggle between fullscreen and windowed mode break; case SDLK_ESCAPE: // if it is ESCAPE Quit(0); // quit after cleaning up } }
void HandleKeyPressEvent(SDL_keysym * keysym) { switch(keysym -> sym) // which key have we got { case SDLK_F5 : // if it is F1 ToggleFullScreen(); // toggle between fullscreen and windowed mode break; case SDLK_ESCAPE: // if it is ESCAPE Quit(0); // quit after cleaning up case SDLK_UP : // if we hit the UP key g_vPosition.y += 0.01f; // move the sphere up break; case SDLK_DOWN : // if we hit the DOWN key g_vPosition.y -= 0.01f; // move the sphere down case SDLK_LEFT : // If we hit the LEFT arrow Key g_vPosition.x -= 0.01f; // move the sphere left along its plane break; case SDLK_RIGHT : // If we hit the RIGHT arrow key g_vPosition.x += 0.01f; // move the sphere right along its plane break; case SDLK_F3 : // if we hit the F3 key g_vPosition.z -= 0.01f; // move the sphere in front of the poly break; case SDLK_F4 : // if we hit the F4 key g_vPosition.z += 0.01f; // move the sphere in front of the poly break; case SDLK_F1 : // check if we hit F1 g_rotateY -= 2; // Rotate the Camera Left break; case SDLK_F2 : // check if we hit F2 g_rotateY += 2; // Rotate the camera right default: // any other key break; // nothing to do } }
void App::KeyboardCB(unsigned char key, int x, int y) { if (!m_pGame->HandleKeyboardDown(key, x, y)) { switch (key) { case 27: // escape key exit(0); break; case 13: // enter key if (glutGetModifiers() == GLUT_ACTIVE_ALT) { ToggleFullScreen(); } break; } } }
void ProcessUserInput() { Keyboard &keyboard = Keyboard::instance(); if (keyboard.keyPressed(Keyboard::KEY_ESCAPE)) PostMessage(g_hWnd, WM_CLOSE, 0, 0); if (keyboard.keyDown(Keyboard::KEY_LALT) || keyboard.keyDown(Keyboard::KEY_RALT)) { if (keyboard.keyPressed(Keyboard::KEY_ENTER)) ToggleFullScreen(); } if (keyboard.keyPressed(Keyboard::KEY_H)) g_displayHelp = !g_displayHelp; if (keyboard.keyPressed(Keyboard::KEY_ADD) || keyboard.keyPressed(Keyboard::KEY_NUMPAD_ADD)) { g_camera.setRotationSpeed(g_camera.getRotationSpeed() + 0.01f); if (g_camera.getRotationSpeed() > 1.0f) g_camera.setRotationSpeed(1.0f); } if (keyboard.keyPressed(Keyboard::KEY_SUBTRACT) || keyboard.keyPressed(Keyboard::KEY_NUMPAD_SUBTRACT)) { g_camera.setRotationSpeed(g_camera.getRotationSpeed() - 0.01f); if (g_camera.getRotationSpeed() <= 0.0f) g_camera.setRotationSpeed(0.01f); } if (keyboard.keyPressed(Keyboard::KEY_V)) EnableVerticalSync(!g_enableVerticalSync); if (keyboard.keyPressed(Keyboard::KEY_SPACE)) GenerateTerrain(); if (keyboard.keyPressed(Keyboard::KEY_M)) Mouse::instance().smoothMouse(!Mouse::instance().mouseSmoothingIsEnabled()); if (keyboard.keyPressed(Keyboard::KEY_T)) g_disableColorMaps = !g_disableColorMaps; }
/*---------------------------------------------------------------------------*/ void MainWindow::CreateMenu( void ) { // 创建菜单 QMenu* pOption = new QMenu( tr( "Option" ), this ); QMenu* pAbout = new QMenu( tr( "About" ), this ); pOption->addAction( QIcon( ":/Icons/fullscreenIcon.png" ), tr( "Toggle full screen" ), this, SLOT( ToggleFullScreen( ) ), QKeySequence::FullScreen ); pAbout->addAction( QIcon( ":/Icons/aboutIcon.png" ), tr( "About..." ), this, SLOT( About( ) ), tr( "F1" ) ); pAbout->addAction( QIcon( ":/Icons/qtIcon.png" ), tr( "About Qt..." ), qApp, SLOT( aboutQt( ) ), tr( "F2" ) ); // 在菜单栏中添加菜单 menuBar( )->addMenu( pOption ); menuBar( )->addMenu( pAbout ); }
GUI_Status View::SystemFilter( const SDL_Event &event ) { GUI_Status rc; // <Alt><Return> toggles fullscreen if ( (event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_RETURN) && (event.key.keysym.mod & KMOD_ALT) != 0) { ToggleFullScreen(); rc = GUI_NONE; } else rc = GUI_OK; #ifdef ANDROID if ( event.type == SDL_VIDEOEXPOSE ) { extern int SDL_ANDROID_sWindowWidth; extern int SDL_ANDROID_sWindowHeight; SetVideoMode(SDL_ANDROID_sWindowWidth, SDL_ANDROID_sWindowHeight, 16, SDL_HWSURFACE); Refresh(); //rc = GUI_NONE; } #endif return rc; }
/** * This function cleans up all of the resources that we create in init and * also cleans up all of our states */ void GameEngine::Cleanup() { logger.Log("Attempting to cleanup all of the things in GameEngine"); while( ! states.empty() ) { logger.Log("Calling Cleanup function for " + states.back()->m_sName); states.back()->Cleanup(); states.pop_back(); } if( m_bFullscreen ) { ToggleFullScreen(); } SDL_DestroyRenderer(m_cRenderer); SDL_DestroyWindow(m_cWindow); IMG_Quit(); SDL_Quit(); TTF_Quit(); }
/** ** Handle keys in command mode. ** ** @param key Key scancode. ** ** @return True, if key is handled; otherwise false. */ static bool CommandKey(int key) { const char *ptr = strchr(UiGroupKeys.c_str(), key); // FIXME: don't handle unicode well. Should work on all latin keyboard. if (ptr) { key = '0' + ptr - UiGroupKeys.c_str(); if (key > '9') { key = SDLK_BACKQUOTE; } } switch (key) { // Return enters chat/input mode. case SDLK_RETURN: case SDLK_KP_ENTER: // RETURN UiBeginInput(); return true; // Unselect everything case SDLK_CARET: case SDLK_BACKQUOTE: UiUnselectAll(); break; // Group selection case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': CommandKey_Group(key - '0'); break; case SDLK_F2: case SDLK_F3: case SDLK_F4: // Set/Goto place CommandKey_MapPosition(key - SDLK_F2); break; case SDLK_SPACE: // center on last action CenterOnMessage(); break; case SDLK_EQUALS: // plus is shift-equals. case SDLK_KP_PLUS: UiIncreaseGameSpeed(); break; case SDLK_MINUS: // - Slower case SDLK_KP_MINUS: UiDecreaseGameSpeed(); break; case SDLK_KP_MULTIPLY: UiSetDefaultGameSpeed(); break; case 'b': // ALT+B, CTRL+B Toggle big map if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } UiToggleBigMap(); break; case 'c': // ALT+C, CTRL+C C center on units UiCenterOnSelected(); break; case 'f': // ALT+F, CTRL+F toggle fullscreen if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } ToggleFullScreen(); SavePreferences(); break; case 'g': // ALT+G, CTRL+G grab mouse pointer if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } UiToggleGrabMouse(); break; case 'i': if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } // FALL THROUGH case SDLK_PERIOD: // ., ALT+I, CTRL+I: Find idle worker UiFindIdleWorker(); break; case 'm': // CTRL+M Turn music on / off if (KeyModifiers & ModifierControl) { UiToggleMusic(); SavePreferences(); break; } break; case 'p': // CTRL+P, ALT+P Toggle pause if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } // FALL THROUGH (CTRL+P, ALT+P) case SDLK_PAUSE: UiTogglePause(); break; case 's': // CTRL+S - Turn sound on / off if (KeyModifiers & ModifierControl) { UiToggleSound(); SavePreferences(); break; } break; case 't': // ALT+T, CTRL+T Track unit if (!(KeyModifiers & (ModifierAlt | ModifierControl))) { break; } UiTrackUnit(); break; case 'v': // ALT+V, CTRL+V: Viewport if (KeyModifiers & ModifierControl) { CycleViewportMode(-1); } else if (KeyModifiers & ModifierAlt) { CycleViewportMode(1); } break; case 'e': // CTRL+E Turn messages on / off if (KeyModifiers & ModifierControl) { ToggleShowMessages(); } #ifdef DEBUG else if (KeyModifiers & ModifierAlt) { ToggleShowBuilListMessages(); } #endif break; case SDLK_TAB: // TAB toggles minimap. // FIXME: more... // FIXME: shift+TAB if (KeyModifiers & ModifierAlt) { break; } UiToggleTerrain(); break; case SDLK_UP: case SDLK_KP8: KeyScrollState |= ScrollUp; break; case SDLK_DOWN: case SDLK_KP2: KeyScrollState |= ScrollDown; break; case SDLK_LEFT: case SDLK_KP4: KeyScrollState |= ScrollLeft; break; case SDLK_RIGHT: case SDLK_KP6: KeyScrollState |= ScrollRight; break; default: if (HandleCommandKey(key)) { break; } return false; } return true; }
void HandleKeyPress(SDL_keysym *whatkey) { int igetscreen; float myspeed=speed; switch(whatkey->sym) { case SDLK_F1: ToggleFullScreen(); break; case SDLK_F2: if(MouseOn==true) { MouseOn=false; } else { MouseOn=true; } break; case SDLK_F9: if(togglez==true) togglez=false; else togglez=true; case SDLK_F10: igetscreen=Screenshot(MainWindow,"screenshot.bmp"); break; case SDLK_ESCAPE: SDL_Quit(); exit(0); break; case SDLK_UP: upPressed=true; break; case SDLK_DOWN: downPressed=true; break; case SDLK_LEFT: leftPressed=true; if( whatkey->mod & KMOD_CTRL) { leftPressed =false; ctrl_leftPressed=true; } if( whatkey->mod & KMOD_SHIFT){ leftPressed =false; shift_leftPressed=true; } break; case SDLK_RIGHT: rightPressed=true; if( whatkey->mod & KMOD_CTRL) { rightPressed =false; ctrl_rightPressed=true; } if( whatkey->mod & KMOD_SHIFT){ rightPressed =false; shift_rightPressed=true; } default: break; case SDLK_p: p_Pressed=true; break; case SDLK_F12: iplot++; break; } }
static void PollEvent() { poll_mouse(); bool mouse_action = false; /* Mouse buttons */ static int prev_button_state; if (prev_button_state != mouse_b) { uint diff = prev_button_state ^ mouse_b; while (diff != 0) { uint button = FindFirstBit(diff); ClrBit(diff, button); if (HasBit(mouse_b, button)) { /* Pressed mouse button */ if (_rightclick_emulate && (key_shifts & KB_CTRL_FLAG)) { button = RIGHT_BUTTON; ClrBit(diff, RIGHT_BUTTON); } switch (button) { case LEFT_BUTTON: _left_button_down = true; break; case RIGHT_BUTTON: _right_button_down = true; _right_button_clicked = true; break; default: /* ignore rest */ break; } } else { /* Released mouse button */ if (_rightclick_emulate) { _right_button_down = false; _left_button_down = false; _left_button_clicked = false; } else if (button == LEFT_BUTTON) { _left_button_down = false; _left_button_clicked = false; } else if (button == RIGHT_BUTTON) { _right_button_down = false; } } } prev_button_state = mouse_b; mouse_action = true; } /* Mouse movement */ int dx = mouse_x - _cursor.pos.x; int dy = mouse_y - _cursor.pos.y; if (dx != 0 || dy != 0) { if (_cursor.fix_at) { _cursor.delta.x = dx; _cursor.delta.y = dy; position_mouse(_cursor.pos.x, _cursor.pos.y); } else { _cursor.delta.x = dx; _cursor.delta.y = dy; _cursor.pos.x = mouse_x; _cursor.pos.y = mouse_y; _cursor.dirty = true; } mouse_action = true; } static int prev_mouse_z = 0; if (prev_mouse_z != mouse_z) { _cursor.wheel = (prev_mouse_z - mouse_z) < 0 ? -1 : 1; prev_mouse_z = mouse_z; mouse_action = true; } if (mouse_action) HandleMouseEvents(); poll_keyboard(); if ((key_shifts & KB_ALT_FLAG) && (key[KEY_ENTER] || key[KEY_F])) { ToggleFullScreen(!_fullscreen); } else if (keypressed()) { WChar character; uint keycode = ConvertAllegroKeyIntoMy(&character); HandleKeypress(keycode, character); } }
/***************************************************************************** * Manage: handle omapfb events ***************************************************************************** * This function should be called regularly by video output thread. *****************************************************************************/ static int Manage( vout_thread_t *p_vout ) { XEvent xevent; while( XPending( p_vout->p_sys->p_display ) ) { XNextEvent( p_vout->p_sys->p_display, &xevent ); if( xevent.type == ButtonPress && ((XButtonEvent *)&xevent)->button == Button1 ) { /* detect double-clicks */ if( ( ((XButtonEvent *)&xevent)->time - p_vout->p_sys->i_time_button_last_pressed ) < 300 ) { p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; } p_vout->p_sys->i_time_button_last_pressed = ((XButtonEvent *)&xevent)->time; } else if( xevent.type == KeyPress ) { KeySym x_key_symbol; vlc_value_t val; x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display, xevent.xkey.keycode, 0 ); switch( x_key_symbol ) { case XK_Return: val.i_int = ACTIONID_PLAY_PAUSE; break; case XK_Escape: val.i_int = ACTIONID_QUIT; break; case XK_Down: val.i_int = ACTIONID_JUMP_BACKWARD_MEDIUM; break; case XK_Up: val.i_int = ACTIONID_JUMP_FORWARD_MEDIUM; break; case XK_Right: val.i_int = ACTIONID_JUMP_FORWARD_SHORT; break; case XK_Left: val.i_int = ACTIONID_JUMP_BACKWARD_SHORT; break; case XK_F6: val.i_int = ACTIONID_TOGGLE_FULLSCREEN; break; case XK_F7: val.i_int = ACTIONID_VOL_UP; break; case XK_F8: val.i_int = ACTIONID_VOL_DOWN; break; } var_SetInteger( p_vout->p_libvlc, "key-action", val.i_int ); } else if( ( xevent.type == VisibilityNotify && xevent.xvisibility.state == VisibilityUnobscured ) || xevent.type == FocusIn ) { p_vout->p_sys->b_video_enabled = true; p_vout->p_sys->p_output_picture->p->p_pixels = p_vout->p_sys->p_center; XSetInputFocus( p_vout->p_sys->p_display, p_vout->p_sys->window, RevertToParent, CurrentTime ); } else if( ( xevent.type == VisibilityNotify && xevent.xvisibility.state != VisibilityUnobscured ) || xevent.type == FocusOut || xevent.type == UnmapNotify ) { UpdateScreen( p_vout, 0, 0, p_vout->p_sys->fb_vinfo.xres, p_vout->p_sys->fb_vinfo.yres, p_vout->p_sys->fb_vinfo.xres, p_vout->p_sys->fb_vinfo.yres, OMAPFB_COLOR_RGB565 ); p_vout->p_sys->b_video_enabled = false; p_vout->p_sys->p_output_picture->p->p_pixels = p_vout->p_sys->p_null; } } if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE ) { /* Update the object variable and trigger callback */ var_SetBool( p_vout, "fullscreen", !p_vout->b_fullscreen ); if( p_vout->p_sys->b_embed ) ToggleFullScreen( p_vout ); p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE; } if( p_vout->i_changes & VOUT_SIZE_CHANGE ) { FreePicture( p_vout, p_vout->p_sys->p_output_picture ); if( Init( p_vout ) ) { msg_Err( p_vout, "cannot reinit framebuffer screen" ); return VLC_EGENERIC; } } #ifdef HAVE_OSSO if ( p_vout->p_sys->p_octx != NULL ) { if ( p_vout->p_sys->i_backlight_on_counter == i_backlight_on_interval ) { if ( osso_display_blanking_pause( p_vout->p_sys->p_octx ) != OSSO_OK ) { msg_Err( p_vout, "Could not disable backlight blanking" ); } else { msg_Dbg( p_vout, "Backlight blanking disabled" ); } p_vout->p_sys->i_backlight_on_counter = 0; } else { p_vout->p_sys->i_backlight_on_counter ++; } } #endif return VLC_SUCCESS; }
LRESULT CALLBACK WndMainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { // Resize the video when the window changes case WM_MOVE: case WM_SIZE: if ((hWnd == ghApp) && (!g_bAudioOnly)) MoveVideoWindow(); break; // Enforce a minimum size case WM_GETMINMAXINFO: { LPMINMAXINFO lpmm = (LPMINMAXINFO) lParam; lpmm->ptMinTrackSize.x = MINIMUM_VIDEO_WIDTH; lpmm->ptMinTrackSize.y = MINIMUM_VIDEO_HEIGHT; } break; case WM_KEYDOWN: switch(toupper((int) wParam)) { // Frame stepping case VK_SPACE: case '1': StepOneFrame(); break; // Frame stepping (multiple frames) case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': StepFrames((int) wParam - '0'); break; case 'P': PauseClip(); break; case 'S': StopClip(); break; case 'M': ToggleMute(); break; case 'F': case VK_RETURN: ToggleFullScreen(); break; case 'H': InitVideoWindow(1,2); CheckSizeMenu(wParam); break; case 'N': InitVideoWindow(1,1); CheckSizeMenu(wParam); break; case 'D': InitVideoWindow(2,1); CheckSizeMenu(wParam); break; case 'T': InitVideoWindow(3,4); CheckSizeMenu(wParam); break; case VK_ESCAPE: if (g_bFullscreen) ToggleFullScreen(); else CloseClip(); break; case VK_F12: case 'Q': case 'X': CloseClip(); break; } break; case WM_COMMAND: switch(wParam) { // Menus case ID_FILE_OPENCLIP: // If we have ANY file open, close it and shut down DirectShow if (g_psCurrent != Init) CloseClip(); // Open the new clip OpenClip(); break; case ID_FILE_EXIT: CloseClip(); PostQuitMessage(0); break; case ID_FILE_PAUSE: PauseClip(); break; case ID_FILE_STOP: StopClip(); break; case ID_FILE_CLOSE: CloseClip(); break; case ID_FILE_MUTE: ToggleMute(); break; case ID_FILE_FULLSCREEN: ToggleFullScreen(); break; case ID_HELP_ABOUT: DialogBox(ghInst, MAKEINTRESOURCE(IDD_ABOUTBOX), ghApp, (DLGPROC) AboutDlgProc); break; case ID_FILE_SIZE_HALF: InitVideoWindow(1,2); CheckSizeMenu(wParam); break; case ID_FILE_SIZE_NORMAL: InitVideoWindow(1,1); CheckSizeMenu(wParam); break; case ID_FILE_SIZE_DOUBLE: InitVideoWindow(2,1); CheckSizeMenu(wParam); break; case ID_FILE_SIZE_THREEQUARTER: InitVideoWindow(3,4); CheckSizeMenu(wParam); break; case ID_SINGLE_STEP: StepOneFrame(); break; } // Menus break; case WM_GRAPHNOTIFY: HandleGraphEvent(); break; case WM_CLOSE: SendMessage(ghApp, WM_COMMAND, ID_FILE_EXIT, 0); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } // Window msgs handling // Pass this message to the video window for notification of system changes if (pVW) pVW->NotifyOwnerMessage((LONG_PTR) hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam); }
/** * This function initializes the game engine * @param title The title for the games window * @param width the width of our game screen * @param height the height of our game screen * @param fullscreen true for fullscreen window * @return 0 if everything was successful */ int GameEngine::Init(const char* title, int width = 640, int height = 640, bool fullscreen = false) { _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); m_iWindowH = 0; m_iWindowW = 0; m_iScreenWidth = width; m_iScreenHeight = height; logger.Init(LOGFILE, "GameEngine" , LOG_LEVEL); m_bFullscreen = false; if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { logger.LogError( std::string("SDL_Init: ") + SDL_GetError() ); return 1; } else { logger.Log("SDL_Init: SDL_Init_Everything work OK"); } m_cWindow = nullptr; m_cWindow = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN); if( m_cWindow == nullptr ) { logger.LogError( std::string("SDL_CreateWindow: ") + SDL_GetError() ); return 2; } else { logger.Log("SDL_CreateWindow was successful"); } m_cRenderer = nullptr; m_cRenderer = SDL_CreateRenderer(m_cWindow, -1, SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED); if( m_cRenderer == nullptr ) { logger.LogError( std::string("SDL_CreateRenderer: ") + SDL_GetError() ); return 3; } else { logger.Log("SDL_CreateRenderer was successful"); } int img_flags = IMG_INIT_JPG|IMG_INIT_PNG; if ((IMG_Init(img_flags) != img_flags)) { logger.LogError("IMG_Init failed to init jpeg with error " + std::string(SDL_GetError()) ); return 4; } else { logger.Log("IMG_Init was successful!"); } if (TTF_Init() == -1) { logger.LogError("TTF_Init Failed with error: " + std::string(TTF_GetError()) ); return 5; } else { logger.Log("TTF_Init was successful!"); } // Setup full screen if we need to ToggleFullScreen(fullscreen); // Clear the Screen to black and present it ClearScreen(); SDL_ShowCursor(1); m_bRunning = true; return 0; }
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { //====================================================================================== case WM_KEYDOWN: { keys[wParam] = TRUE; // If So, Mark It As TRUE return 0; // Jump Back } break; case WM_KEYUP: // Has A Key Been Released? { keys[wParam] = FALSE; // If So, Mark It As FALSE return 0; // Jump Back } break; //====================================================================================== case WM_ACTIVATE: switch (wParam) { default: break; case WA_ACTIVE: case WA_CLICKACTIVE: g_hasFocus = true; break; case WA_INACTIVE: if (g_isFullScreen) ShowWindow(hWnd, SW_MINIMIZE); g_hasFocus = false; break; } break; case WM_CHAR: switch (static_cast<int>(wParam)) { case VK_ESCAPE: PostMessage(hWnd, WM_CLOSE, 0, 0); break; default: break; } break; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_SIZE: g_windowWidth = static_cast<int>(LOWORD(lParam)); g_windowHeight = static_cast<int>(HIWORD(lParam)); break; case WM_SYSKEYDOWN: if (wParam == VK_RETURN) ToggleFullScreen(); break; default: ProcessMouseInput(hWnd, msg, wParam, lParam); break; } return DefWindowProc(hWnd, msg, wParam, lParam); }
void GraphicsWindow::MenuView(int id) { switch(id) { case MNU_ZOOM_IN: SS.GW.scale *= 1.2; SS.ScheduleShowTW(); break; case MNU_ZOOM_OUT: SS.GW.scale /= 1.2; SS.ScheduleShowTW(); break; case MNU_ZOOM_TO_FIT: SS.GW.ZoomToFit(/*includingInvisibles=*/false, /*useSelection=*/true); SS.ScheduleShowTW(); break; case MNU_SHOW_GRID: SS.GW.showSnapGrid = !SS.GW.showSnapGrid; if(SS.GW.showSnapGrid && !SS.GW.LockedInWorkplane()) { Message("No workplane is active, so the grid will not " "appear."); } SS.GW.EnsureValidActives(); InvalidateGraphics(); break; case MNU_PERSPECTIVE_PROJ: SS.usePerspectiveProj = !SS.usePerspectiveProj; if(SS.cameraTangent < 1e-6) { Error("The perspective factor is set to zero, so the view will " "always be a parallel projection.\n\n" "For a perspective projection, modify the perspective " "factor in the configuration screen. A value around 0.3 " "is typical."); } SS.GW.EnsureValidActives(); InvalidateGraphics(); break; case MNU_ONTO_WORKPLANE: if(SS.GW.LockedInWorkplane()) { SS.GW.AnimateOntoWorkplane(); SS.GW.ClearSuper(); SS.ScheduleShowTW(); break; } // if not in 2d mode fall through and use ORTHO logic case MNU_NEAREST_ORTHO: case MNU_NEAREST_ISO: { static const Vector ortho[3] = { Vector::From(1, 0, 0), Vector::From(0, 1, 0), Vector::From(0, 0, 1) }; double sqrt2 = sqrt(2.0), sqrt6 = sqrt(6.0); Quaternion quat0 = Quaternion::From(SS.GW.projRight, SS.GW.projUp); Quaternion quatf = quat0; double dmin = 1e10; // There are 24 possible views; 3*2*2*2 int i, j, negi, negj; for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { if(i == j) continue; for(negi = 0; negi < 2; negi++) { for(negj = 0; negj < 2; negj++) { Vector ou = ortho[i], ov = ortho[j]; if(negi) ou = ou.ScaledBy(-1); if(negj) ov = ov.ScaledBy(-1); Vector on = ou.Cross(ov); Vector u, v; if(id == MNU_NEAREST_ORTHO || id == MNU_ONTO_WORKPLANE) { u = ou; v = ov; } else { u = ou.ScaledBy(1/sqrt2).Plus( on.ScaledBy(-1/sqrt2)); v = ou.ScaledBy(-1/sqrt6).Plus( ov.ScaledBy(2/sqrt6).Plus( on.ScaledBy(-1/sqrt6))); } Quaternion quatt = Quaternion::From(u, v); double d = min( (quatt.Minus(quat0)).Magnitude(), (quatt.Plus(quat0)).Magnitude()); if(d < dmin) { dmin = d; quatf = quatt; } } } } } SS.GW.AnimateOnto(quatf, SS.GW.offset); break; } case MNU_CENTER_VIEW: SS.GW.GroupSelection(); if(SS.GW.gs.n == 1 && SS.GW.gs.points == 1) { Quaternion quat0; // Offset is the selected point, quaternion is same as before Vector pt = SK.GetEntity(SS.GW.gs.point[0])->PointGetNum(); quat0 = Quaternion::From(SS.GW.projRight, SS.GW.projUp); SS.GW.AnimateOnto(quat0, pt.ScaledBy(-1)); SS.GW.ClearSelection(); } else { Error("Select a point; this point will become the center " "of the view on screen."); } break; case MNU_SHOW_MENU_BAR: ToggleMenuBar(); SS.GW.EnsureValidActives(); InvalidateGraphics(); break; case MNU_SHOW_TOOLBAR: SS.showToolbar = !SS.showToolbar; SS.GW.EnsureValidActives(); InvalidateGraphics(); break; case MNU_SHOW_TEXT_WND: SS.GW.showTextWindow = !SS.GW.showTextWindow; SS.GW.EnsureValidActives(); break; case MNU_UNITS_INCHES: SS.viewUnits = SolveSpaceUI::UNIT_INCHES; SS.ScheduleShowTW(); SS.GW.EnsureValidActives(); break; case MNU_UNITS_MM: SS.viewUnits = SolveSpaceUI::UNIT_MM; SS.ScheduleShowTW(); SS.GW.EnsureValidActives(); break; case MNU_FULL_SCREEN: ToggleFullScreen(); SS.GW.EnsureValidActives(); break; default: oops(); } InvalidateGraphics(); }
int ENGINEAPI EngineMain(TSTR *lp, int c) { int exitcode=0; dwIconID = IDI_GAME; //ugh. //CoInitializeEx(NULL, 0); if(InitBase(TEXT("Game"))) { DWORD newWidth, newHeight, newFreq; BOOL bUseFullscreen = AppConfig->GetInt(TEXT("Display"), TEXT("Fullscreen")); if(!bUseFullscreen) { DisplayMode currentMode; OSGetDisplaySettings(¤tMode); if(currentMode.dwBitsPerPixel != 32) ErrOut(TEXT("Your display settings must be set to 32bit mode.")); } SS->SetEffectsVol(AppConfig->GetFloat(TEXT("Sound"), TEXT("EffectsVolume"), 1.0f)); MM->SetVolume(AppConfig->GetFloat(TEXT("Sound"), TEXT("MusicVolume"), 1.0f)); List<DisplayMode> DisplayModes; zero(&DisplayModes, 8); OSEnumDisplayModes(DisplayModes); newWidth = AppConfig->GetInt(TEXT("Display"), TEXT("Width")); newHeight = AppConfig->GetInt(TEXT("Display"), TEXT("Height")); newFreq = AppConfig->GetInt(TEXT("Display"), TEXT("Frequency")); BOOL bFoundDisplayMode = FALSE; DisplayMode mode; for(int i=0; i<DisplayModes.Num(); i++) { if( (DisplayModes[i].dwHeight == newHeight) && (DisplayModes[i].dwWidth == newWidth) ) { if(DisplayModes[i].dwFrequency == newFreq) { bFoundDisplayMode = TRUE; mcpy(&mode, &DisplayModes[i], sizeof(DisplayMode)); break; } } } mode.dwBitsPerPixel = 32; if(!bFoundDisplayMode) { mode.dwFrequency = 60; mode.dwWidth = 640; mode.dwHeight = 480; Log(TEXT("Monitor does not support %dx%d resolution or doesn't support %d frequency"), newHeight, newWidth, newFreq); } SetResolution(mode, TRUE); if(bUseFullscreen) ToggleFullScreen(); DisplayModes.Clear(); float gamma = AppConfig->GetFloat(TEXT("Display"), TEXT("Gamma"), 1.0f); float brightness = AppConfig->GetFloat(TEXT("Display"), TEXT("Brightness"), 1.0f); float contrast = AppConfig->GetFloat(TEXT("Display"), TEXT("Contrast"), 1.0f); AdjustDisplayColors(gamma, brightness, contrast); GS->ClearColorBuffer(); GameModule *module = (GameModule*)CreateFactoryObject(TEXT("MainGameModule")); if(!module) OSMessageBox(TEXT("Could not load the class 'MainGameModule'.")); else { if(module->ModuleStartup(lp, c)) { //loop exitcode = BaseLoop(); module->ModuleExit(); } DestroyObject(module); } TerminateBase(); } //CoUninitialize(); return 0; }
/***************************************************************************** * VideoWindow::Zoom *****************************************************************************/ void VideoWindow::Zoom(BPoint origin, float width, float height ) { ToggleFullScreen(); }
int main(int argc, char *args[]) { #if _WIN32 // NOTE(nathan): Set the windows schedular granularity to 1ms // so that our SDL_Delay() and be more granular // SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); // NOTE(nathan): This seems to give a more consistant result than above timeBeginPeriod(1); #if _DEBUG HWND console = GetConsoleWindow(); if(console != 0) MoveWindow(console, -900, 100, 700, 800, TRUE); #endif #endif SDL_Init(SDL_INIT_EVERYTHING); // NOTE(nathan): This also initializes the window_with and window_height WindowData window_data = { }; window_data.target_width = 1920; window_data.target_height = 1080; FixViewport(1280, 720, &window_data); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4); SDL_Window *window = SDL_CreateWindow( "Banana", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_data.width, window_data.height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); // ToggleFullScreen(window); SDL_ShowCursor(SDL_DISABLE); // OutputSystemInfo(); SDL_GLContext glContext = SDL_GL_CreateContext(window); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) Error("glewInit"); // Goes stuttery if we turn on vsync SDL_GL_SetSwapInterval((int)window_data.vsync); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); bool running = true; SDL_Event e; uint32 gameUpdateHz = 60; float32 targetSecondsPerFrame = 1.0f / (float32)gameUpdateHz; perfCountFreq = SDL_GetPerformanceFrequency(); uint64 lastCounter = GetWallClock(); GameMemory game_memory = { 0 }; game_memory.size = Megabytes(64); game_memory.memory = SDL_malloc(game_memory.size); EditorMemory editor_memory = { 0 }; editor_memory.size = Megabytes(64); editor_memory.memory = SDL_malloc(editor_memory.size); RenderContext render_context = {}; render_context.diffuse = CreateShader("assets/shaders/diffuse.vert", "assets/shaders/diffuse.frag"); InitializeContext(&render_context); VoxelRenderContext voxel_render_context = {}; voxel_render_context.diffuse = CreateShader("assets/shaders/voxels.vert", "assets/shaders/voxels.frag"); InitializeVoxelContext(&voxel_render_context); InputData input = { }; input.window = window; UIContext ui_context = { 0 }; ui_context.input = &input; ui_context.render_context = &render_context; Mode mode = MODE_GAME; bool game_paused = false; while (running) { while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) running = false; if (e.type == SDL_WINDOWEVENT) { if (e.window.event == SDL_WINDOWEVENT_RESIZED) { FixViewport((int)e.window.data1, (int)e.window.data2, &window_data); } } if (e.type == SDL_KEYDOWN) { SDL_Scancode key = e.key.keysym.scancode; input.keyboard_state[key] = true; if (key == SDL_SCANCODE_ESCAPE) running = false; if (key == SDL_SCANCODE_F12) window_data.vsync = !window_data.vsync; if (key == SDL_SCANCODE_F11) ToggleFullScreen(window, &window_data); if (key == SDL_SCANCODE_F10) { if (mode == MODE_GAME) { game_paused = true; mode = MODE_EDITOR; } else { mode = MODE_GAME; game_paused = false; } } } if (e.type == SDL_KEYUP) { SDL_Scancode key = e.key.keysym.scancode; input.keyboard_state[key] = false; } if (e.type == SDL_MOUSEMOTION) { input.mouse_pos.x = (((float)window_data.target_width / (float)window_data.vp_width) * ((float)e.motion.x - window_data.vp_x)); input.mouse_pos.y = (((float)window_data.target_height / (float)window_data.vp_height) * ((float)e.motion.y - window_data.vp_y)); } if (e.type == SDL_MOUSEBUTTONDOWN) { if (e.button.button == SDL_BUTTON_LEFT) input.mb_left = true; if (e.button.button == SDL_BUTTON_RIGHT) input.mb_right = true; if (e.button.button == SDL_BUTTON_MIDDLE) input.mb_middle = true; } if (e.type == SDL_MOUSEBUTTONUP) { if (e.button.button == SDL_BUTTON_LEFT) input.mb_left = false; if (e.button.button == SDL_BUTTON_RIGHT) input.mb_right = false; if (e.button.button == SDL_BUTTON_MIDDLE) input.mb_middle = false; } } float32 delta = 1.0f / (float32)gameUpdateHz; GameUpdateAndRender(&game_memory, &input, &render_context, &voxel_render_context, &window_data, game_paused, delta); uint64 workCounter = GetWallClock(); float32 workSecondsElapsed = GetSecondsElapsed(lastCounter, workCounter); // Dont include this in frametime if (mode == MODE_EDITOR) EditorUpdateAndRender(&editor_memory, &input, &render_context, &ui_context, delta); float32 secondsElapsedForFrame = workSecondsElapsed; if (secondsElapsedForFrame < targetSecondsPerFrame) { uint32 sleepMS = (uint32)((1000.0f * (targetSecondsPerFrame - secondsElapsedForFrame)) - 1); if (sleepMS > 0) SDL_Delay(sleepMS); while (secondsElapsedForFrame < targetSecondsPerFrame) { secondsElapsedForFrame = GetSecondsElapsed(lastCounter, GetWallClock()); } } else { // Error("Missed Frame Rate"); } uint64 endCounter = GetWallClock(); float64 msPerFrame = 1000.0f * GetSecondsElapsed(lastCounter, endCounter); lastCounter = endCounter; // Debug Render BeginRenderer(&render_context); std::string s = "FRAMETIME " + std::to_string(msPerFrame) + " VSYNC " + std::to_string(window_data.vsync); RenderString(&render_context, 40.0f, 40.0f, s.c_str(), 0.0f); EndRenderer(); SDL_GL_SwapWindow(window); input.prev_keyboard_state = input.keyboard_state; input.mb_left_prev = input.mb_left; input.mb_right_prev = input.mb_right; input.mb_middle_prev = input.mb_middle; } UnloadContext(&render_context); UnloadVoxelContext(&voxel_render_context); SDL_free(game_memory.memory); SDL_GL_DeleteContext(glContext); SDL_DestroyWindow(window); SDL_Quit(); return(0); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { #if defined _DEBUG _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); #endif MSG msg = {0}; WNDCLASSEX wcl = {0}; wcl.cbSize = sizeof(wcl); wcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wcl.lpfnWndProc = WindowProc; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hInstance = g_hInstance = hInstance; wcl.hIcon = LoadIcon(0, IDI_APPLICATION); wcl.hCursor = LoadCursor(0, IDC_ARROW); wcl.hbrBackground = 0; wcl.lpszMenuName = 0; wcl.lpszClassName = "GLWindowClass"; wcl.hIconSm = 0; if (!RegisterClassEx(&wcl)) return 0; g_hWnd = CreateAppWindow(wcl, 0); if (g_hWnd) { InitGL(); ToggleFullScreen(); glDisable(GL_MULTISAMPLE_ARB); ShowWindow(g_hWnd, nShowCmd); UpdateWindow(g_hWnd); while (true) { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.message == WM_QUIT) break; if (keys[VK_ESCAPE]) { msg.message = WM_QUIT ; } if (g_hasFocus) { RenderGL(); SwapBuffers(g_hDC); ProcessKeyboard(); } else { WaitMessage(); } } Cleanup(); UnregisterClass(wcl.lpszClassName, hInstance); } return static_cast<int>(msg.wParam); }
int VideoDriver_SDL::PollEvent() { SDL_Event ev; if (!SDL_CALL SDL_PollEvent(&ev)) return -2; switch (ev.type) { case SDL_MOUSEMOTION: if (_cursor.fix_at) { int dx = ev.motion.x - _cursor.pos.x; int dy = ev.motion.y - _cursor.pos.y; if (dx != 0 || dy != 0) { _cursor.delta.x = dx; _cursor.delta.y = dy; SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); } } else { _cursor.delta.x = ev.motion.x - _cursor.pos.x; _cursor.delta.y = ev.motion.y - _cursor.pos.y; _cursor.pos.x = ev.motion.x; _cursor.pos.y = ev.motion.y; _cursor.dirty = true; } HandleMouseEvents(); break; case SDL_MOUSEBUTTONDOWN: if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) { ev.button.button = SDL_BUTTON_RIGHT; } switch (ev.button.button) { case SDL_BUTTON_LEFT: _left_button_down = true; break; case SDL_BUTTON_RIGHT: _right_button_down = true; _right_button_clicked = true; break; case SDL_BUTTON_WHEELUP: _cursor.wheel--; break; case SDL_BUTTON_WHEELDOWN: _cursor.wheel++; break; default: break; } HandleMouseEvents(); break; case SDL_MOUSEBUTTONUP: if (_rightclick_emulate) { _right_button_down = false; _left_button_down = false; _left_button_clicked = false; } else if (ev.button.button == SDL_BUTTON_LEFT) { _left_button_down = false; _left_button_clicked = false; } else if (ev.button.button == SDL_BUTTON_RIGHT) { _right_button_down = false; } HandleMouseEvents(); break; case SDL_ACTIVEEVENT: if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break; if (ev.active.gain) { // mouse entered the window, enable cursor _cursor.in_window = true; } else { UndrawMouseCursor(); // mouse left the window, undraw cursor _cursor.in_window = false; } break; case SDL_QUIT: HandleExitGameRequest(); break; case SDL_KEYDOWN: // Toggle full-screen on ALT + ENTER/F if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { ToggleFullScreen(!_fullscreen); } else { HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym)); } break; case SDL_VIDEORESIZE: { int w = max(ev.resize.w, 64); int h = max(ev.resize.h, 64); CreateMainSurface(w, h); break; } case SDL_VIDEOEXPOSE: { /* Force a redraw of the entire screen. Note * that SDL 1.2 seems to do this automatically * in most cases, but 1.3 / 2.0 does not. */ _num_dirty_rects = MAX_DIRTY_RECTS + 1; break; } } return -1; }
//----------------------------------------------------------------------------- LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_ACTIVATE: switch (wParam) { default: break; case WA_ACTIVE: case WA_CLICKACTIVE: g_hasFocus = true; break; case WA_INACTIVE: if (g_isFullScreen) ShowWindow(hWnd, SW_MINIMIZE); g_hasFocus = false; break; } break; case WM_ERASEBKGND: if (IsWindowEnabled(hWnd)) { wglMakeCurrent(g_hDC, g_hRC); CGE_Render(); // do not draw in WM_PAINT (inspired in CastleWindow) SwapBuffers(g_hDC); } return TRUE; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: CGE_MouseDown(GET_X_LPARAM(lParam), g_windowHeight-1-GET_Y_LPARAM(lParam), msg==WM_LBUTTONDOWN, 0); SetCapture(hWnd); break; case WM_MOUSEMOVE: CGE_Motion(GET_X_LPARAM(lParam), g_windowHeight-1-GET_Y_LPARAM(lParam), 0); break; case WM_LBUTTONUP: case WM_RBUTTONUP: CGE_MouseUp(GET_X_LPARAM(lParam), g_windowHeight-1-GET_Y_LPARAM(lParam), msg==WM_LBUTTONUP, 0, true); if (GetCapture()==hWnd) ReleaseCapture(); break; case WM_MOUSEWHEEL: CGE_MouseWheel(GET_WHEEL_DELTA_WPARAM(wParam), true); break; case WM_CHAR: switch (wParam) { case VK_ESCAPE: PostMessage(hWnd, WM_CLOSE, 0, 0); break; case 's': CGE_SaveScreenshotToFile("screenshot.jpg"); break; case 'f': CGE_SetNavigationType(ecgenavFly); break; case 'e': { int nVal = CGE_GetVariableInt(ecgevarEffectSSAO); if (nVal < 0) nVal = 0; CGE_SetVariableInt(ecgevarEffectSSAO, 1-nVal); } break; case 'h': { int nVal = CGE_GetVariableInt(ecgevarWalkHeadBobbing); if (nVal < 0) nVal = 0; CGE_SetVariableInt(ecgevarWalkHeadBobbing, 1-nVal); } break; default: break; } break; case WM_KEYDOWN: switch (wParam) { case VK_PRIOR: // PageUp - move to previous viewpoint if (g_nViewpointCount > 0) { if (g_nCurrentViewpoint > 0) g_nCurrentViewpoint--; else g_nCurrentViewpoint = g_nViewpointCount-1; CGE_MoveToViewpoint(g_nCurrentViewpoint, true); } break; case VK_NEXT: // PageDown - move to next viewpoint if (g_nViewpointCount > 0) { if (g_nCurrentViewpoint < g_nViewpointCount-1) g_nCurrentViewpoint++; else g_nCurrentViewpoint = 0; CGE_MoveToViewpoint(g_nCurrentViewpoint, true); } break; default: break; } break; case WM_DESTROY: Cleanup(); PostQuitMessage(0); return 0; case WM_SIZE: g_windowWidth = LOWORD(lParam); g_windowHeight = HIWORD(lParam); CGE_Resize(g_windowWidth, g_windowHeight); break; case WM_SYSKEYDOWN: if (wParam == VK_RETURN) // Alt + Enter ToggleFullScreen(); break; default: break; } return DefWindowProc(hWnd, msg, wParam, lParam); }