void MainLoop (void) { while (gameStates.app.nFunctionMode != FMODE_EXIT) { gameStates.app.bGameRunning = (gameStates.app.nFunctionMode == FMODE_GAME); switch (gameStates.app.nFunctionMode) { case FMODE_MENU: SetScreenMode (SCREEN_MENU); if (gameStates.app.bAutoRunMission) { if (StartNewGame (1)) gameStates.app.nFunctionMode = FMODE_GAME; gameStates.app.bAutoRunMission = 0; if (gameStates.app.nFunctionMode == FMODE_GAME) break; } if (gameData.demo.bAuto && !gameOpts->demo.bRevertFormat) { NDStartPlayback (NULL); // Randomly pick a file if (gameData.demo.nState != ND_STATE_PLAYBACK) Error ("No demo files were found for autodemo mode!"); } else { CheckJoystickCalibration (); paletteManager.ClearEffect (); //I'm not sure why we need this, but we do //SetRenderQuality (0); MainMenu (); } if (gameData.multiplayer.autoNG.bValid && (gameStates.app.nFunctionMode != FMODE_GAME)) gameStates.app.nFunctionMode = FMODE_EXIT; break; case FMODE_GAME: GrabMouse (1, 1); RunGame (); GrabMouse (0, 1); paletteManager.EnableEffect (); paletteManager.ResetEffect (); paletteManager.DisableEffect (); gameStates.app.bD1Mission = 0; if (gameData.multiplayer.autoNG.bValid) gameStates.app.nFunctionMode = FMODE_EXIT; if (gameStates.app.nFunctionMode == FMODE_MENU) { audio.StopAllChannels (); songManager.Play (SONG_TITLE, 1); } RestoreDefaultModels (); break; default: Error ("Invalid function mode %d", gameStates.app.nFunctionMode); } } }
CameraApp() : GLApp("OpenGL Example: Camera App") , controller(&camera) , shaderProgram("shaders/perspective.vs", "shaders/textured.frag") , texture1("textures/container.jpg") , texture2("textures/awesomeface.png") { Keyboard::Instance()->AddInputListener(this); glEnable(GL_DEPTH_TEST); glClearColor(0.2f, 0.3f, 0.3f, 1.0f); GLuint VBO; glGenBuffers(1, &VBO); glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); Cube cube; cube.BindBuffer(); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0); glEnableVertexAttribArray(0); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat))); glEnableVertexAttribArray(2); glBindVertexArray(0); GrabMouse(); camera.Position = glm::vec3(0.0f, 0.0f, 3.0f); controller.Speed = 5.0f; }
void axToggle::OnMouseLeftDown(const axPoint& pos) { if(_selected && IsFlag(Flags::CANT_UNSELECT_WITH_MOUSE, _flags)) { // Don't do anything. } else { // Only switch selection on toggle_on_left_down. if (IsFlag(Flags::CLICK_ON_LEFT_DOWN, _flags)) { _selected = !_selected; } if(_selected) { _currentColor = &_info.selected_clicking; } else { _currentColor = &_info.clicking; } GrabMouse(); if (IsFlag(Flags::CLICK_ON_LEFT_DOWN, _flags)) { PushEvent(Events::BUTTON_CLICK, new Msg(this, _selected, _msg)); } Update(); } }
// // I_ResumeMouse // void I_ResumeMouse (void) { if(havefocus) { GrabMouse(); SetCursorState(false); // denis - disable key repeats as they mess with the mouse in XP SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); } mousepaused = false; }
void axScrollBar::OnMouseLeftDown(const axPoint& position) { axPoint pos = position - GetAbsoluteRect().position; if(axRect(0, _sliderPos, GetRect().size.x, _sliderHeight).IsPointInside(pos)) { _currentScrollBarColor = &_info.hover; _yClickDelta = pos.y - _sliderPos; GrabMouse(); Update(); } }
RemoteInteractor WorldView::Choose (Cursor* c, boolean waitforup) { Event e; GrabMouse(c); do { Read(e); } while (e.eventType != DownEvent); if (waitforup) { do { Read(e); } while (e.eventType != UpEvent); } UngrabMouse(); return Find(e.x, e.y); }
/* Routine to let user select a window using the mouse adapted from xfree86. */ XCTRL_API Window select_window(Display *disp, int button) { Cursor cursor; XEvent event; Window target_win = None; Window root = DefaultRootWindow(disp); int buttons = 0; int dumi; unsigned int dum; cursor = XCreateFontCursor(disp, XC_crosshair); if (!GrabMouse()) { XFreeCursor(disp,cursor); return 0; } while ((target_win == None) || (buttons != 0)) { XAllowEvents(disp, SyncPointer, CurrentTime); XWindowEvent(disp, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if ((button==-1)||(event.xbutton.button==button)) { if (target_win == None) { target_win = event.xbutton.subwindow; /* window selected */ if (target_win == None) target_win = root; } } else { pass_click_to_client(disp,root,&event,ButtonPressMask,cursor); } buttons++; break; case ButtonRelease: if (buttons > 0) { buttons--; } if ((button!=-1)&&(event.xbutton.button!=button)) { pass_click_to_client(disp,root,&event,ButtonReleaseMask,cursor); } break; } } XUngrabPointer(disp, CurrentTime); if (XGetGeometry(disp,target_win,&root,&dumi,&dumi,&dum,&dum,&dum,&dum)&&target_win!=root) { target_win = XmuClientWindow(disp, target_win); } return(target_win); }
bool WindowManager::CreateSDLWindow() { if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { // Initialize everything return false; // or return that there was an error } TTF_Init(); if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) { return false; } _FSModes = SDL_ListModes(NULL, SDL_OPENGL | SDL_HWSURFACE | SDL_FULLSCREEN); if(_FSModes == (SDL_Rect**)0 || _FSModes == (SDL_Rect **)-1) return false; _CurrentFSMode=_FSModes[0]; // Point the global window variable to the new SDL surface if(_Fullscreen) { _Window=SDL_SetVideoMode(_CurrentFSMode->w, _CurrentFSMode->h, 0, SDL_HWSURFACE|SDL_OPENGL|SDL_FULLSCREEN); // and resizable, or return that there has been an error } else { SDL_Rect Mode; Mode.x = Mode.y = 0; Mode.w = 800; Mode.h = 600; _CurrentWMode = Mode; _Window=SDL_SetVideoMode(_CurrentWMode.w, _CurrentWMode.h, 0, SDL_HWSURFACE | SDL_OPENGL); } SDL_WM_SetCaption( "VoA: Variations on Asteroids", NULL ); GrabMouse(); return true; }
/** Process a button press. */ void ProcessActionPress(struct ActionType *actions, struct TrayComponentType *cp, int x, int y, int button) { const ScreenType *sp; const ActionType *ap; const int mask = 1 << button; int mwidth, mheight; int menu; menu = -1; for(ap = actions; ap; ap = ap->next) { if(ap->mask & mask) { if(ap->action && ap->action[0]) { if(strncmp(ap->action, "root:", 5) != 0) { /* Show the button being pressed. */ GrabMouse(cp->tray->window); cp->grabbed = 1; if(cp->Redraw) { (cp->Redraw)(cp); UpdateSpecificTray(cp->tray, cp); } return; } else { menu = GetRootMenuIndexFromString(&ap->action[5]); } } else { menu = 1; } break; } } if(menu < 0) { return; } GetRootMenuSize(menu, &mwidth, &mheight); sp = GetCurrentScreen(cp->screenx, cp->screeny); if(cp->tray->layout == LAYOUT_HORIZONTAL) { x = cp->screenx; if(cp->screeny + cp->height / 2 < sp->y + sp->height / 2) { y = cp->screeny + cp->height; } else { y = cp->screeny - mheight; } } else { y = cp->screeny; if(cp->screenx + cp->width / 2 < sp->x + sp->width / 2) { x = cp->screenx + cp->width; } else { x = cp->screenx - mwidth; } } cp->grabbed = 1; if(cp->Redraw) { (cp->Redraw)(cp); UpdateSpecificTray(cp->tray, cp); } ShowRootMenu(menu, x, y); cp->grabbed = 0; if(cp->Redraw) { (cp->Redraw)(cp); UpdateSpecificTray(cp->tray, cp); } }
void IN_DeactivateMouse(void) { GrabMouse(false, in_raw.integer); }
void IN_ActivateMouse(void) { GrabMouse(true, in_raw.integer); }
static void in_grab_windowed_mouse_callback(cvar_t *val, char *value, qbool *cancel) { GrabMouse((atoi(value) > 0 ? true : false), in_raw.integer); }
static void in_raw_callback(cvar_t *var, char *value, qbool *cancel) { GrabMouse(mouse_active, (atoi(value) > 0 ? true : false)); }
//Process selected keys until game unpaused. returns key that left pause (p or esc) int DoGamePause (void) { int key = 0; int bScreenChanged; char msg [1000]; char totalTime [9], xLevelTime [9]; if (gameData.app.bGamePaused) { //unpause! gameData.app.bGamePaused = 0; gameStates.app.bEnterGame = 1; #if defined (TACTILE) if (TactileStick) EnableForces(); #endif return KEY_PAUSE; } if (gameData.app.nGameMode & GM_NETWORK) { DoShowNetgameHelp(); return (KEY_PAUSE); } else if (gameData.app.nGameMode & GM_MULTI) { HUDInitMessage (TXT_MODEM_PAUSE); return (KEY_PAUSE); } PauseGame (); SetPopupScreenMode (); paletteManager.LoadEffect (); formatTime (totalTime, X2I (LOCALPLAYER.timeTotal) + LOCALPLAYER.hoursTotal * 3600); formatTime (xLevelTime, X2I (LOCALPLAYER.timeLevel) + LOCALPLAYER.hoursLevel * 3600); if (gameData.demo.nState!=ND_STATE_PLAYBACK) sprintf (msg, TXT_PAUSE_MSG1, GAMETEXT (332 + gameStates.app.nDifficultyLevel), LOCALPLAYER.hostages.nOnBoard, xLevelTime, totalTime); else sprintf (msg, TXT_PAUSE_MSG2, GAMETEXT (332 + gameStates.app.nDifficultyLevel), LOCALPLAYER.hostages.nOnBoard); if (!gameOpts->menus.nStyle) { gameStates.menus.nInMenu++; GameRenderFrame (); gameStates.menus.nInMenu--; } messageBox.Show (pszPauseMsg = msg, false); GrabMouse (0, 0); while (gameData.app.bGamePaused) { if (!(gameOpts->menus.nStyle && gameStates.app.bGameRunning)) key = KeyGetChar(); else { gameStates.menus.nInMenu++; while (!(key = KeyInKey ())) { GameRenderFrame (); paletteManager.LoadEffect (NULL); messageBox.Render (); G3_SLEEP (1); } gameStates.menus.nInMenu--; } #if DBG HandleTestKey(key); #endif bScreenChanged = HandleSystemKey (key); HandleVRKey (key); if (bScreenChanged) { GameRenderFrame (); messageBox.Render (); #if 0 show_extraViews (); if ((gameStates.render.cockpit.nType == CM_FULL_COCKPIT) || (gameStates.render.cockpit.nType == CM_STATUS_BAR)) RenderGauges(); #endif } } GrabMouse (1, 0); messageBox.Clear (); ResumeGame (); return key; }