bool exaUpdate() { if (!isinit) return 1; SDL_Event event; _Clearkeys(); if (typerepeats) _UpdateTypedKeys(); _ProcessMouse(); while (SDL_PollEvent (&event) ) { switch (event.type) { case SDL_ACTIVEEVENT: if (event.active.gain == 0) { iconified = true; SDL_WM_GrabInput (SDL_GRAB_OFF); } else { iconified = false; SDL_WM_GrabInput (SDL_GRAB_ON); } break; case SDL_VIDEORESIZE: break; case SDL_QUIT: return false; //return 1 means the app shouldn't work anymore!!! case SDL_KEYDOWN: _Keydown (& event.key.keysym); //process key events break; case SDL_KEYUP: _Keyup (& event.key.keysym); break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_WHEELUP) wheelup = true; if (event.button.button == SDL_BUTTON_WHEELDOWN) wheeldown = true; break; default: break; } } return true; }
/** * Handles mouse up events */ void WindowLocations::mouseUp(SDL_MouseButtonEvent button) { if (button.x > 824 && this->scrollMode == false) { //Clicking sidebar. Find out if a component was hit. UIComponent *component = findComponent(button.x, button.y); //'Next player' button if (component == butNext) { if (playerInTurn >= gameEngine.getPlayerCount()) this->startGame(); else this->nextPlayer(); } //'Back to main menu' button else if (component == butQuit) { this->close(0); } } else { //Clicking game area //Convert to world coordinates Coordinates* coords = this->graphics.getWorldCoordinates(button.x, button.y); Player *player; Ai *ai = NULL; player = gameEngine.getPlayer(playerInTurn); if (player) ai = player->getAI(); //If AI is in turn, disable controls if (ai) player = NULL; //Set location if (player && this->dragDistance < 5) { if (player->setLocation(coords->getX(), coords->getY()) == 0) { this->sounds.playSound(SOUND_CLICK); nextPlayer(); } else { this->sounds.playSound(SOUND_TICK); } } delete coords; } //Deactivate scroll mode if (this->scrollMode) { SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); this->scrollMode = false; } }
/* * Keyboard initialisation. Called by the client. */ void IN_KeyboardInit(Key_Event_fp_t fp) { Key_Event_fp = fp; /* SDL stuff. Moved here from IN_BackendInit because * this must be done after video is initialized. */ SDL_EnableUNICODE(0); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); have_grab = (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON); }
void ZGameWindow_Programmable::Hide() { GameEnv->GuiManager.RemoveFrame(MainWindow); SDL_ShowCursor(SDL_DISABLE); #ifdef GOTOZERO_ZERO SDL_WarpMouse(0,0); #endif SDL_WM_GrabInput(SDL_GRAB_ON); GameEnv->Game_Events->SetEnableMouseEvents(); Flag_Shown = false; }
/** * Starts up SDL with all the subsystems and SDL_mixer for audio processing, * creates the display screen and sets up the cursor. * @param title Title of the game window. */ Game::Game(const std::string &title) : _screen(0), _cursor(0), _lang(0), _res(0), _save(0), _rules(0), _quit(false), _init(false), _mouseActive(true), _timeUntilNextFrame(0) { Options::reload = false; Options::mute = false; // Initialize SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) { throw Exception(SDL_GetError()); } Log(LOG_INFO) << "SDL initialized successfully."; // Initialize SDL_mixer if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { Log(LOG_ERROR) << SDL_GetError(); Log(LOG_WARNING) << "No sound device detected, audio disabled."; Options::mute = true; } else { initAudio(); } // trap the mouse inside the window SDL_WM_GrabInput(Options::captureMouse); // Set the window icon CrossPlatform::setWindowIcon(103, "openxcom.png"); // Set the window caption SDL_WM_SetCaption(title.c_str(), 0); SDL_EnableUNICODE(1); // Create display _screen = new Screen(); // Create cursor _cursor = new Cursor(9, 13); // Create invisible hardware cursor to workaround bug with absolute positioning pointing devices SDL_ShowCursor(SDL_ENABLE); Uint8 cursor = 0; SDL_SetCursor(SDL_CreateCursor(&cursor, &cursor, 1,1,0,0)); // Create fps counter _fpsCounter = new FpsCounter(15, 5, 0, 0); // Create blank language _lang = new Language(); _timeOfLastFrame = 0; }
static void sdl_grab_start(void) { if (guest_cursor) { SDL_SetCursor(guest_sprite); SDL_WarpMouse(guest_x, guest_y); } else sdl_hide_cursor(); SDL_WM_GrabInput(SDL_GRAB_ON); gui_grab = 1; sdl_update_caption(); }
/* =========== IN_DeactivateMouse =========== */ void IN_DeactivateMouse (void) { if (!mouseinitialized) return; if (mouseactivatetoggle) { mouseactivatetoggle = false; mouseactive = false; SDL_WM_GrabInput (SDL_GRAB_OFF); } }
void SetupInput() { for (int port=0;port<4;port++) { kcode[port]=0xFFFF; rt[port]=0; lt[port]=0; } // Open joystick device int numjoys = SDL_NumJoysticks(); printf("Number of Joysticks found = %i\n", numjoys); if (numjoys > 0) JoySDL = SDL_JoystickOpen(0); printf("Joystick openned\n"); if(JoySDL) { int AxisCount,ButtonCount; const char* Name; AxisCount = 0; ButtonCount = 0; // Name[0] = '\0'; AxisCount = SDL_JoystickNumAxes(JoySDL); ButtonCount = SDL_JoystickNumButtons(JoySDL); Name = SDL_JoystickName(0); printf("SDK: Found '%s' joystick with %d axis and %d buttons\n",Name,AxisCount,ButtonCount); if (strcmp(Name,"Microsoft X-Box 360 pad")==0) { JMapBtn=JMapBtn_360; JMapAxis=JMapAxis_360; printf("Using Xbox 360 map\n"); } } else printf("SDK: No Joystick Found\n"); #ifdef TARGET_PANDORA float v; int j; for (int i=0; i<128; i++) { v=((float)i)/127.0f; v=(v+v*v)/2.0f; j=(int)(v*127.0f); if (j>127) j=127; JSensitivity[128-i]=-j; JSensitivity[128+i]=j; } #endif SDL_ShowCursor( 0 ); if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON) printf("SDK: Error while grabbing mouse\n"); }
void vid_mouse_button (SDL_MouseButtonEvent *event) { SDL_Event dummy_event; int32 cx; int32 cy; SIM_MOUSE_EVENT ev; t_bool state; if (!vid_mouse_captured) { if ((event->state == SDL_PRESSED) && (event->button == SDL_BUTTON_LEFT)) { /* left click and cursor not captured? */ sim_debug (SIM_VID_DBG_KEY, vid_dev, "vid_mouse_button() - Cursor Captured\n"); SDL_WM_GrabInput (SDL_GRAB_ON); /* lock cursor to window */ SDL_ShowCursor (SDL_DISABLE); /* hide cursor */ cx = vid_width / 2; cy = vid_height / 2; SDL_WarpMouse (cx, cy); /* move cursor to centre of window */ SDL_PumpEvents (); while (SDL_PeepEvents (&dummy_event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK)) {}; vid_mouse_captured = TRUE; } return; } if (!sim_is_running) return; if (SDL_SemWait (vid_mouse_events.sem) == 0) { sim_debug (SIM_VID_DBG_MOUSE, vid_dev, "Mouse Button Event: State: %d, Button: %d, (%d,%d)\n", event->state, event->button, event->x, event->y); if (vid_mouse_events.count < MAX_EVENTS) { state = (event->state == SDL_PRESSED) ? TRUE : FALSE; ev.x_rel = 0; ev.y_rel = 0; switch (event->button) { case SDL_BUTTON_LEFT: vid_mouse_events.b1_state = state; break; case SDL_BUTTON_MIDDLE: vid_mouse_events.b2_state = state; break; case SDL_BUTTON_RIGHT: vid_mouse_events.b3_state = state; break; } ev.b1_state = vid_mouse_events.b1_state; ev.b2_state = vid_mouse_events.b2_state; ev.b3_state = vid_mouse_events.b3_state; vid_mouse_events.events[vid_mouse_events.tail++] = ev; vid_mouse_events.count++; if (vid_mouse_events.tail == MAX_EVENTS) vid_mouse_events.tail = 0; } SDL_SemPost (vid_mouse_events.sem); } }
void WINDOW_SDL::ShowMouseCursor(bool value) { if (value) { SDL_ShowCursor(SDL_ENABLE); #if SDL_VERSION_ATLEAST(2,0,0) SDL_SetWindowGrab(window, SDL_FALSE); #else SDL_WM_GrabInput(SDL_GRAB_OFF); #endif } else { SDL_ShowCursor(SDL_DISABLE); #if SDL_VERSION_ATLEAST(2,0,0) SDL_SetWindowGrab(window, SDL_TRUE); #else SDL_WM_GrabInput(SDL_GRAB_ON); #endif } }
void init() { heightfield hf; heightfieldinfo hfi; skybox sb; object3d plan = create_plan_xy(100, 100, 1, 1); material mat = material_create(NULL, 0, &color_red, 0, 0); matrix4 tmp; vector3 cam_pos = {0,50,0}; vector3 cam_up = {0,1,0}; vector3 cam_look = {0,50,-1}; viewport vp = viewport_create(0, 0, display_width(screen), display_height(screen)); /* Camera */ camfps = camera_create(60, ZFAR, ZNEAR, &cam_pos, &cam_look, &cam_up, vp); /* Heightfied creation */ hf = heightfield_create_from_file("data/height.png", 1000, 1000, 100); heightfield_set_textures_from_file(hf, "data/land.jpg", "data/detail.jpg"); heightfield_set_detail_scale(hf, 50, 50); matrix4_to_rot_x(tmp, -90); heightfield_set_world_matrix(hf, tmp); /* Heightfield infos*/ hfi = heightfieldinfo_create("data/land.jpg", hf, camfps, screen, 250, 250); /* Skybox */ sb = skybox_create(camfps, "data/left.jpg", "data/right.jpg", "data/front.jpg", "data/back.jpg", "data/top.jpg", "data/bottom.jpg", 10); /* Test plane */ object3d_set_material(plan, mat); /* Populate the scene */ scn = scene_create(); scene_set_camera(scn, camfps); scene_set_display(scn, screen); scene_add_object(scn, sb, (void *)skybox_to_opengl, NULL); scene_add_object(scn, hf, (void *)heightfield_to_opengl, NULL); scene_add_object(scn, plan, (void *)object3d_to_opengl, NULL); scene_add_object2d(scn, hfi, (void *)heightfieldinfo_to_opengl, NULL); fontgl_init(); font = fontgl_create("data/vera.ttf", 800, 600, 16); fontgl_set_color(font, 1,0,0); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); SDL_WarpMouse(CENTERX,CENTERY); SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(SDL_DISABLE); }
static void install_grabs(void) { SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(0); // This is a bug in the current SDL/macosx...have to toggle it a few // times to get the cursor to hide. #if defined(MACOS_X) SDL_ShowCursor(1); SDL_ShowCursor(0); #endif }
//---------------------------------------------------------------------------- void Video::grabAndWarpMouse() { SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); SDL_WarpMouse( _width/2, _height/2); SDL_Event event; while( SDL_PollEvent( &event)) { //remove any queued up events due to warping, etc. ; } }
static void GrabInput(bool grab, bool hide_cursor, bool set_state) { #if defined(ID_DEDICATED) return; #else if (set_state) grabbed = grab; if (hide_cursor) SDL_ShowCursor(SDL_DISABLE); else SDL_ShowCursor(SDL_ENABLE); if (in_nograb.GetBool()) grab = false; if (grab) SDL_WM_GrabInput(SDL_GRAB_ON); else SDL_WM_GrabInput(SDL_GRAB_OFF); #endif }
/* ============== Sys_ErrorDialog Display an error message ============== */ void Sys_ErrorDialog( const char *error ) { char buffer[ 1024 ]; unsigned int size; int f; const char *homepath = Cvar_VariableString( "fs_homepath" ); const char *gamedir = Cvar_VariableString( "fs_game" ); const char *fileName = "crashlog.txt"; char *ospath = FS_BuildOSPath( homepath, gamedir, fileName ); Sys_Print( va( "%s\n", error ) ); #if !defined(DEDICATED) && !defined(BUILD_TTY_CLIENT) // We may have grabbed input devices. Need to release. if ( SDL_WasInit( SDL_INIT_VIDEO ) ) { SDL_WM_GrabInput( SDL_GRAB_OFF ); } Sys_Dialog( DT_ERROR, va( "%s. See \"%s\" for details.", error, ospath ), "Error" ); #endif // Make sure the write path for the crashlog exists... if ( !Sys_Mkdir( ospath ) ) { Com_Printf( "ERROR: couldn't create path '%s' for crash log.\n", ospath ); return; } // We might be crashing because we maxed out the Quake MAX_FILE_HANDLES, // which will come through here, so we don't want to recurse forever by // calling FS_FOpenFileWrite()...use the Unix system APIs instead. f = open( ospath, O_CREAT | O_TRUNC | O_WRONLY, 0640 ); if ( f == -1 ) { Com_Printf( "ERROR: couldn't open %s\n", fileName ); return; } // We're crashing, so we don't care much if write() or close() fails. while ( ( size = CON_LogRead( buffer, sizeof( buffer ) ) ) > 0 ) { if ( write( f, buffer, size ) != size ) { Com_Printf( "ERROR: couldn't fully write to %s\n", fileName ); break; } } close( f ); }
// // I_UpdateInputGrabbing // // Determines if SDL should grab the mouse based on the game window having // focus and the status of the menu and console. // static void I_UpdateInputGrabbing() { #ifndef GCONSOLE bool can_grab = false; bool grabbed = SDL_WM_GrabInput(SDL_GRAB_QUERY); if (!window_focused) can_grab = false; else if (vid_fullscreen) can_grab = true; else if (nomouse) can_grab = false; else if (configuring_controls) can_grab = true; else if (menuactive || ConsoleState == c_down || paused) can_grab = false; else if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) && !demoplayback) can_grab = true; // force I_ResumeMouse or I_PauseMouse if toggling between fullscreen/windowed static float prev_vid_fullscreen = vid_fullscreen; if (vid_fullscreen != prev_vid_fullscreen) grabbed = !can_grab; prev_vid_fullscreen = vid_fullscreen; // check if the window focus changed (or menu/console status changed) if (can_grab && !grabbed) { SDL_WM_GrabInput(SDL_GRAB_ON); I_ResumeMouse(); I_FlushInput(); } else if (grabbed && !can_grab) { SDL_WM_GrabInput(SDL_GRAB_OFF); I_PauseMouse(); } #endif }
void I_ShutdownGraphics(void) { if (initialized) { SDL_SetCursor(cursors[1]); SDL_ShowCursor(1); SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_QuitSubSystem(SDL_INIT_VIDEO); initialized = false; } }
void ZGameWindow_Programmable::Hide() { GameEnv->GuiManager.RemoveFrame(MainWindow); SDL_ShowCursor(SDL_DISABLE); #ifdef SDL1 SDL_WM_GrabInput(SDL_GRAB_ON); #else SDL_SetRelativeMouseMode(SDL_TRUE); #endif GameEnv->Mouse_relative = true; GameEnv->Game_Events->SetEnableMouseEvents(); Flag_Shown = false; }
void input_grab( bool enable ) { #if defined(TARGET_GP2X) || defined(TARGET_DINGUX) || defined(ANDROID) enable = true; #endif input_grab_enabled = enable || fullscreen_enabled; SDL_ShowCursor(input_grab_enabled ? SDL_DISABLE : SDL_ENABLE); #ifdef NDEBUG SDL_WM_GrabInput(input_grab_enabled ? SDL_GRAB_ON : SDL_GRAB_OFF); #endif }
static void set_mouse_mode(int mode) { switch (mode) { case MOUSE_POINTER: DEBUG(2, "input_sdl: set_mouse_mode(MOUSE_POINTER)\n"); mouse_mode = MOUSE_POINTER; DEBUG(2, "input_sdl: releasing input\n"); SDL_ShowCursor(SDL_ENABLE); SDL_WM_GrabInput(SDL_GRAB_OFF); break; case MOUSE_MOVE: DEBUG(2, "input_sdl: set_mouse_mode(MOUSE_MOVE)\n"); mouse_mode = MOUSE_MOVE; DEBUG(2, "input_sdl: grabbing input\n"); SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); break; default: ERROR("invalid mouse mode %d\n", mode); } }
/** Replacement for the default failure hook on Linux. */ static bool SDL_handleErrorCheck_( const char* expression, const std::string& message, const char* filename, int lineNumber, bool& ignoreAlways, bool useGuiPrompt) { SDL_ShowCursor(SDL_ENABLE); SDL_WM_GrabInput(SDL_GRAB_OFF); return _internal::_handleErrorCheck_(expression, message, filename, lineNumber, ignoreAlways, useGuiPrompt); }
static void sdl_grab_start(void) { if (guest_cursor) { SDL_SetCursor(guest_sprite); SDL_WarpMouse(guest_x, guest_y); } else sdl_hide_cursor(); SDL_WM_GrabInput(SDL_GRAB_ON); /* dummy read to avoid moving the mouse */ SDL_GetRelativeMouseState(NULL, NULL); gui_grab = 1; sdl_update_caption(); }
// // I_ShutdownInput // void STACK_ARGS I_ShutdownInput (void) { //SDL_SetCursor(cursors[1]); SDL_ShowCursor(1); SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); #ifdef WIN32 // denis - in fullscreen, prevent exit on accidental windows key press // [Russell] - Disabled because it screws with the mouse //UnhookWindowsHookEx(g_hKeyboardHook); #endif }
int vid_init(void) { int r = SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE); int width = arg_intval("-width", 800); int height = arg_intval("-height", 600); int fullscreen = arg_intval("-fullscreen", 0); int bpp = arg_intval("-bpp", 32); int flags = SDL_OPENGL|(fullscreen?SDL_FULLSCREEN:0); if (r < 0) return FALSE; vid_width = width; vid_height = height; vid_anisotropy = arg_intval("-anisotropy", 1); if (vid_anisotropy < 1) vid_anisotropy = 1; if (bpp == 32 || bpp == 24) { 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_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); } else { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); } if (!SDL_SetVideoMode(width, height, bpp, flags)) if (!SDL_SetVideoMode(width, height, bpp, flags&(~SDL_FULLSCREEN))) return FALSE; if (!load_extensions()) return FALSE; SDL_WM_SetCaption(GAME_TITLE, GAME_TITLE); SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(0); SDL_EnableUNICODE(SDL_ENABLE); wh_ratio = (float)width/(float)height; hw_ratio = (float)height/(float)width; pixelw = 2.0/(float)width; pixelh = 2.0/(float)height; return TRUE; }
// // UpdateGrab (From chocolate-doom) // static void UpdateGrab(void) { bool grab; grab = MouseShouldBeGrabbed(); if (grab && !mousegrabbed) { if(screen) SDL_WarpMouse(screen->width/ 2, screen->height / 2); SetCursorState(false); SDL_WM_GrabInput(SDL_GRAB_ON); flushmouse = true; } else if (!grab && mousegrabbed) { SetCursorState(true); SDL_WM_GrabInput(SDL_GRAB_OFF); } mousegrabbed = grab; }
// // GrabMouse // static void GrabMouse (void) { if(nomouse) return; if(screen) { SDL_WarpMouse(screen->width/ 2, screen->height / 2); } SDL_WM_GrabInput(SDL_GRAB_ON); mousegrabbed = true; flushmouse = true; }
void Framework::togglePause(bool pause, bool external) { PacketType t; if ((((external)&&(pause))||((!external)&&(paused == 0)))&&(state != CONNECTING)) { paused = SDL_GetTicks() - lasttime; SDL_ShowCursor(1); SDL_WM_GrabInput(SDL_GRAB_OFF); output.togglePaused(true); t = PAUSE_REQUEST; } else { lasttime = SDL_GetTicks() + paused; paused = 0; if (state != CONNECTING) { SDL_ShowCursor(0); SDL_WM_GrabInput(SDL_GRAB_ON); } output.togglePaused(false); t = RESUME_REQUEST; } if (!external) sendSimplePacket(t); }
void fs_ml_grab_input(int grab, int immediate) { //printf("fs_ml_grab_input %d %d\n", grab, immediate); if (immediate) { #ifndef HAVE_GLES SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF); #endif fs_ml_show_cursor(!grab, 1); } else { post_video_event(grab ? FS_ML_VIDEO_EVENT_GRAB_INPUT : FS_ML_VIDEO_EVENT_UNGRAB_INPUT); } g_grab_input = grab ? 1 : 0; }
void cleanup() { recorder::stop(); cleanupserver(); SDL_ShowCursor(1); SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_SetGamma(1, 1, 1); freeocta(worldroot); extern void clear_command(); clear_command(); extern void clear_console(); clear_console(); extern void clear_mdls(); clear_mdls(); extern void clear_sound(); clear_sound(); SDL_Quit(); }
void Framework::togglePause(bool pause, bool external) { Buffer sbuf; if ((((external)&&(pause))||((!external)&&(paused == 0)))&&(state != CONNECTING)) { paused = SDL_GetTicks() - lasttime; SDL_ShowCursor(1); SDL_WM_GrabInput(SDL_GRAB_OFF); output.togglePaused(true); sbuf.setType(PAUSE_REQUEST); } else { lasttime = SDL_GetTicks() + paused; paused = 0; if (state != CONNECTING) { SDL_ShowCursor(0); SDL_WM_GrabInput(SDL_GRAB_ON); } output.togglePaused(false); sbuf.setType(RESUME_REQUEST); } if (!external) for (int i = 0; i < peer.size(); i++) sendPacket(&peer[i], sbuf.getData(), sbuf.getSize()); }