Ejemplo n.º 1
0
static int native_drainevents (SADisplay *display, VisEventQueue *eventqueue)
{
        SDLNative *native = SDL_NATIVE (display->native);
        SDL_Event event;

        /* Visible or not */
        if (((SDL_GetAppState () & SDL_APPACTIVE) == 0) && (native->active == TRUE)) {
                native->active = FALSE;
                visual_event_queue_add_visibility (eventqueue, FALSE);
        } else if (((SDL_GetAppState () & SDL_APPACTIVE) != 0) && (native->active == FALSE)) {
                native->active = TRUE;
                visual_event_queue_add_visibility (eventqueue, TRUE);
        }

        /* Events */
        while (SDL_PollEvent (&event)) {

                switch (event.type) {
                        case SDL_KEYUP:
                                visual_event_queue_add_keyboard (eventqueue, event.key.keysym.sym, event.key.keysym.mod,
                                                                 VISUAL_KEY_UP);
                                break;

                        case SDL_KEYDOWN:
                                visual_event_queue_add_keyboard (eventqueue, event.key.keysym.sym, event.key.keysym.mod,
                                                                 VISUAL_KEY_DOWN);
                                break;

                        case SDL_VIDEORESIZE:
                                visual_event_queue_add_resize (eventqueue, display->screen, event.resize.w, event.resize.h);

                                native_create (display, display->screen->depth, NULL, event.resize.w, event.resize.h, native->resizable);
                                break;

                        case SDL_MOUSEMOTION:
                                visual_event_queue_add_mousemotion (eventqueue, event.motion.x, event.motion.y);
                                break;

                        case SDL_MOUSEBUTTONDOWN:
                                visual_event_queue_add_mousebutton (eventqueue, event.button.button, VISUAL_MOUSE_DOWN,
                                                                    event.button.x, event.button.y);
                                break;

                        case SDL_MOUSEBUTTONUP:
                                visual_event_queue_add_mousebutton (eventqueue, event.button.button, VISUAL_MOUSE_UP,
                                                                    event.button.x, event.button.y);
                                break;

                        case SDL_QUIT:
                                visual_event_queue_add_quit (eventqueue, FALSE);
                                break;

                        default:
                                break;
                }
        }

        return 0;
}
Ejemplo n.º 2
0
/*
===============
IN_DeactivateMouse
===============
*/
void IN_DeactivateMouse( void )
{
	if( !SDL_WasInit( SDL_INIT_VIDEO ) )
		return;

	// Always show the cursor when the mouse is disabled,
	// but not when fullscreen
	if( !r_fullscreen->integer )
	{
		if( ( Key_GetCatcher( ) == KEYCATCH_UI ) &&
				( SDL_GetAppState( ) & (SDL_APPMOUSEFOCUS|SDL_APPINPUTFOCUS) ) == (SDL_APPMOUSEFOCUS|SDL_APPINPUTFOCUS) )
			SDL_ShowCursor( 0 );
		else
			SDL_ShowCursor( 1 );
	}

	if( !mouseAvailable )
		return;

#ifdef MACOS_X_ACCELERATION_HACK
	if (mouseActive) // mac os x mouse accel hack
	{
		if(originalMouseSpeed != -1.0)
		{
			io_connect_t mouseDev = IN_GetIOHandle();
			if(mouseDev != 0)
			{
				Com_Printf("restoring mouse acceleration to: %f\n", originalMouseSpeed);
				if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess)
					Com_Printf("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
				IOServiceClose(mouseDev);
			}
			else
				Com_Printf("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n");
		}
	}
#endif

	if( mouseActive )
	{
		IN_GobbleMotionEvents( );

		SDL_WM_GrabInput( SDL_GRAB_OFF );

		// Don't warp the mouse unless the cursor is within the window
		if( SDL_GetAppState( ) & SDL_APPMOUSEFOCUS )
		{
			int x, y;
			x = glConfig.vidWidth / 2, y = glConfig.vidHeight / 2;
			SDL_WarpMouse( x, y );
		}

		mouseActive = qfalse;
	}
}
Ejemplo n.º 3
0
bool SDLWindow::hasFocus() const {
    uint8 s = SDL_GetAppState();
    
    return ((s & SDL_APPMOUSEFOCUS) != 0) &&
           ((s & SDL_APPINPUTFOCUS) != 0) &&
           ((s & SDL_APPACTIVE) != 0);
}
Ejemplo n.º 4
0
//
// SDLVideoDriver::FinishUpdate
//
// Push the newest frame to the display.
//
void SDLVideoDriver::FinishUpdate(void)
{
   // haleyjd 10/08/05: from Chocolate DOOM:
   UpdateGrab();

   // Don't update the screen if the window isn't visible.
   // Not doing this breaks under Windows when we alt-tab away 
   // while fullscreen.   
   if(!(SDL_GetAppState() & SDL_APPACTIVE))
      return;

   if(setpalette)
   {
      if(!crossbitdepth)
         SDL_SetPalette(sdlscreen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);

      if(primary_surface)
         SDL_SetPalette(primary_surface, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);

      setpalette = false;
   }

   // haleyjd 11/12/09: blit *after* palette set improves behavior.
   if(primary_surface)
      SDL_BlitSurface(primary_surface, NULL, sdlscreen, NULL);

   // haleyjd 11/12/09: ALWAYS update. Causes problems with some video surface
   // types otherwise.
   SDL_Flip(sdlscreen);
}
Ejemplo n.º 5
0
BOOL System::Update(f32 dt)
{
	UNUSED(dt);

	u8 state = SDL_GetAppState();
	if ((state & SDL_APPACTIVE) != SDL_APPACTIVE || (state & SDL_APPINPUTFOCUS) != SDL_APPINPUTFOCUS)
	{
		if (!this->bSleeping)
		{
			this->bSleeping = TRUE;

			EventSystem ev;
			this->SendEventSleep(&ev);
		}
	}
	else
	{
		if (this->bSleeping)
		{
			this->bSleeping = FALSE;

			EventSystem ev;
			this->SendEventSleep(&ev);
		}
	}

	//this->WaitForRetrace(this->iFrameRate);
	return TRUE;
}
Ejemplo n.º 6
0
static void UpdateFocus(void)
{
	static bool curfocus = false;

	SDL_PumpEvents();

	Uint8 state = SDL_GetAppState();

	// We should have input (keyboard) focus and be visible (not minimized)
	havefocus = (state & SDL_APPINPUTFOCUS) && (state & SDL_APPACTIVE);

	// [CG] Handle focus changes, this is all necessary to avoid repeat events.
	// [AM] This fixes the tab key sticking when alt-tabbing away from the
	//      program, but does not seem to solve the problem of tab being 'dead'
	//      for one keypress after switching back.
	if (curfocus != havefocus)
	{
		if (havefocus)
		{
			SDL_Event event;
			while (SDL_PollEvent(&event))
			{
				// Do nothing
			}
		}

		curfocus = havefocus;
	}
}
Ejemplo n.º 7
0
static void DIB_GenerateMouseMotionEvent(_THIS)
{
	extern int mouse_relative;
	extern int posted;

	POINT mouse;
	GetCursorPos( &mouse );

	if ( mouse_relative ) {
		POINT center;
		center.x = (SDL_VideoSurface->w/2);
		center.y = (SDL_VideoSurface->h/2);
		ClientToScreen(SDL_Window, &center);

		mouse.x -= (Sint16)center.x;
		mouse.y -= (Sint16)center.y;
		if ( mouse.x || mouse.y ) {
			SetCursorPos(center.x, center.y);
			posted = SDL_PrivateMouseMotion(0, 1, mouse.x, mouse.y);
		}
	} else if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
		ScreenToClient(SDL_Window, &mouse);
#ifdef SDL_VIDEO_DRIVER_GAPI
       if (SDL_VideoSurface && this->hidden->gapiInfo)
			GapiTransform(this->hidden->gapiInfo->coordinateTransform, this->hidden->gapiInfo->hiresFix, &mouse.x, &mouse.y);
#endif
		posted = SDL_PrivateMouseMotion(0, 0, mouse.x, mouse.y);
	}
}
Ejemplo n.º 8
0
bool MouseCursor::hasFocus() const {
#if SDL_VERSION_ATLEAST(2,0,0)
    return (SDL_GetMouseFocus() == display.sdl_window);
#else
    return (SDL_GetAppState() & SDL_APPMOUSEFOCUS);
#endif
}
Ejemplo n.º 9
0
void controller_base::play_slice(bool is_delay_enabled)
{
	display& gui = get_display();

	CKey key;
	events::pump();
	events::raise_process_event();
	events::raise_draw_event();

	slice_before_scroll();

	int mousex, mousey;
	Uint8 mouse_flags = SDL_GetMouseState(&mousex, &mousey);
	bool was_scrolling = scrolling_;
	scrolling_ = handle_scroll(key, mousex, mousey, mouse_flags);

	get_display().draw();

	// be nice when window is not visible
	// NOTE should be handled by display instead, to only disable drawing
	if (is_delay_enabled && (SDL_GetAppState(gui.video().getWindow()) & SDL_APPACTIVE) == 0) {
		get_display().delay(200);
	}

	if (!scrolling_ && was_scrolling) {
#if (defined(__APPLE__) && TARGET_OS_IPHONE) || defined(ANDROID)
	
#else
		// scrolling ended, update the cursor and the brightened hex
		get_mouse_handler_base().mouse_update(browse_);
#endif
	}
	slice_end();
}
Ejemplo n.º 10
0
/*
===============
IN_Frame
===============
*/
void IN_Frame( void )
{
	qboolean loading;

	IN_JoyMove( );
	IN_ProcessEvents( );

	// If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading
	loading = ( clc.state != CA_DISCONNECTED && clc.state != CA_ACTIVE );

	if( !Cvar_VariableIntegerValue("r_fullscreen") && ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) )
	{
		// Console is down in windowed mode
		IN_DeactivateMouse( );
	}
	else if( !Cvar_VariableIntegerValue("r_fullscreen") && loading )
	{
		// Loading in windowed mode
		IN_DeactivateMouse( );
	}
	else if( !( SDL_GetAppState() & SDL_APPINPUTFOCUS ) )
	{
		// Window not got focus
		IN_DeactivateMouse( );
	}
	else
		IN_ActivateMouse( );

	/* in case we had to delay actual restart of video system... */
	if ( (vidRestartTime != 0) && (vidRestartTime < Sys_Milliseconds()) )
	{
		vidRestartTime = 0;
		Cbuf_AddText( "vid_restart\n" );
	}
}
Ejemplo n.º 11
0
void AppMinimized(void)
{
    stat("Game minimized or lost focus--pausing...");

#ifdef _SDL_MIXER
    Mix_Pause(-1);
    Mix_PauseMusic();
#else
    SDL_PauseAudio(1);
#endif

    for(;;)
    {
        if ((SDL_GetAppState() & VISFLAGS) == VISFLAGS)
        {
            break;
        }

        input_poll();
        SDL_Delay(20);
    }
#ifdef _SDL_MIXER
    Mix_Resume(-1);
    Mix_ResumeMusic();
#else
    SDL_PauseAudio(0);
#endif
    stat("Focus regained, resuming play...");
}
Ejemplo n.º 12
0
/*
===============
IN_Frame
===============
*/
void IN_Frame( void )
{
	qboolean loading;

	IN_JoyMove( );
	IN_ProcessEvents( );

	// If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading
	loading = !!( cls.state != CA_DISCONNECTED && cls.state != CA_ACTIVE );

	if( !r_fullscreen->integer && ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) )
	{
		// Console is down in windowed mode
		IN_DeactivateMouse( );
	}
	else if( !r_fullscreen->integer && loading )
	{
		// Loading in windowed mode
		IN_DeactivateMouse( );
	}
	else if( !( SDL_GetAppState() & SDL_APPINPUTFOCUS ) )
	{
		// Window not got focus
		IN_DeactivateMouse( );
	}
	else
		IN_ActivateMouse( );
}
Ejemplo n.º 13
0
void MenuLoop(MenuSystem *menu)
{
	assert(menu->numExitTypes > 0);
	for (;; SDL_Delay(10))
	{
		MusicSetPlaying(&gSoundDevice, SDL_GetAppState() & SDL_APPINPUTFOCUS);
		// Input
		InputPoll(menu->inputDevices, SDL_GetTicks());
		// Update
		if (menu->current->type == MENU_TYPE_KEYS &&
			menu->current->u.normal.changeKeyMenu != NULL)
		{
			MenuProcessChangeKey(menu->current);
		}
		else
		{
			int cmd = GetMenuCmd(gPlayerDatas);
			MenuProcessCmd(menu, cmd);
		}
		if (MenuIsExit(menu))
		{
			break;
		}
		// Draw
		GraphicsBlitBkg(menu->graphics);
		ShowControls();
		MenuDisplay(menu);
		BlitFlip(menu->graphics, &gConfig.Graphics);
	}
}
Ejemplo n.º 14
0
int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
{
#ifdef NO_GAMMA_SUPPORT
	SDL_SetError("SDL compiled without gamma ramp support");
	return -1;
#else
	HDC hdc;
	BOOL succeeded;

	/* Set the ramp for the display */
	if ( ! gamma_saved ) {
		gamma_saved = (WORD *)malloc(3*256*sizeof(*gamma_saved));
		if ( ! gamma_saved ) {
			SDL_OutOfMemory();
			return -1;
		}
		hdc = GetDC(SDL_Window);
		GetDeviceGammaRamp(hdc, gamma_saved);
		ReleaseDC(SDL_Window, hdc);
	}
	if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
		hdc = GetDC(SDL_Window);
		succeeded = SetDeviceGammaRamp(hdc, ramp);
		ReleaseDC(SDL_Window, hdc);
	} else {
		succeeded = TRUE;
	}
	return succeeded ? 0 : -1;
#endif /* !NO_GAMMA_SUPPORT */
}
Ejemplo n.º 15
0
/**
    This function draws the cursor to the screen. The coordinate is read from
    the two global variables drawnMouseX and drawnMouseY.
*/
void drawCursor() {
    if(!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
        return;
    }



	SDL_Surface* surface = pGFXManager->getUIGraphic(cursorFrame);

    SDL_Rect dest = { drawnMouseX, drawnMouseY, surface->w, surface->h };

	//reposition image so pointing on right spot

	if (cursorFrame == UI_CursorRight) {
		dest.x -= dest.w/2;
	} else if (cursorFrame == UI_CursorDown) {
		dest.y -= dest.h/2;
	}

	if ((cursorFrame == UI_CursorAttack_Zoomlevel0) || (cursorFrame == UI_CursorMove_Zoomlevel0)) {
		dest.x -= dest.w/2;
		dest.y -= dest.h/2;
	}

	if(SDL_BlitSurface(surface, NULL, screen, &dest) != 0) {
        fprintf(stderr,"drawCursor(): %s\n", SDL_GetError());
	}
}
Ejemplo n.º 16
0
static void DIB_GenerateMouseMotionEvent(void)
{
	extern int mouse_relative;
	extern int posted;

	POINT mouse;
	GetCursorPos( &mouse );

	if ( mouse_relative ) {
		POINT center;
		center.x = (SDL_VideoSurface->w/2);
		center.y = (SDL_VideoSurface->h/2);
		ClientToScreen(SDL_Window, &center);

		mouse.x -= (Sint16)center.x;
		mouse.y -= (Sint16)center.y;
		if ( mouse.x || mouse.y ) {
			SetCursorPos(center.x, center.y);
			posted = SDL_PrivateMouseMotion(0, 1, mouse.x, mouse.y);
		}
	} else if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
		ScreenToClient(SDL_Window, &mouse);
#ifdef _WIN32_WCE
		if (SDL_VideoSurface)
			GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &mouse.x, &mouse.y);
#endif
		posted = SDL_PrivateMouseMotion(0, 0, mouse.x, mouse.y);
	}
}
Ejemplo n.º 17
0
void
IN_Frame(void)
{
	qbool loading;

	IN_JoyMove( );
	IN_ProcessEvents( );

	/* If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading */
	loading = !!(clc.state != CA_DISCONNECTED && clc.state != CA_ACTIVE);

	if(!cvargeti("r_fullscreen") && (Key_GetCatcher( ) & KEYCATCH_CONSOLE)){
		/* Console is down in windowed mode */
		IN_DeactivateMouse( );
	}else if(!cvargeti("r_fullscreen") && loading){
		/* Loading in windowed mode */
		IN_DeactivateMouse( );
	}else if(!(SDL_GetAppState() & SDL_APPINPUTFOCUS)){
		/* Window not got focus */
		IN_DeactivateMouse( );
	}else
		IN_ActivateMouse( );

	/* in case we had to delay actual restart of video system... */
	if((vidRestartTime != 0) && (vidRestartTime < sysmillisecs())){
		vidRestartTime = 0;
		cbufaddstr("vid_restart");
	}
}
Ejemplo n.º 18
0
static PyObject*
key_get_focused (PyObject* self)
{
    VIDEO_INIT_CHECK ();

    return PyInt_FromLong ((SDL_GetAppState () & SDL_APPINPUTFOCUS) != 0);
}
Ejemplo n.º 19
0
/*
===============
IN_Frame
===============
*/
void IN_Frame( void )
{
	qboolean loading;

	//FIXME test, checking mouse grab
	if (in_checkForStolenMouseFocus->integer  &&  mouseActive  &&  !(SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
		Com_Printf("^3external application stole mouse focus\n");
	}

	IN_JoyMove( );

	// If not DISCONNECTED (main menu) or ACTIVE (in game), we're loading
	loading = ( cls.state != CA_DISCONNECTED && cls.state != CA_ACTIVE );

	if( !r_fullscreen->integer && ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) )
	{
		// Console is down in windowed mode
		IN_DeactivateMouse( );
	}
	else if( !r_fullscreen->integer && loading )
	{
		// Loading in windowed mode
		IN_DeactivateMouse( );
	}
	else if( !( SDL_GetAppState() & SDL_APPINPUTFOCUS ) )
	{
		// Window not got focus
		//Com_Printf("^3window lost focus\n");
		IN_DeactivateMouse( );
	}
	else {
		if (in_nograb->integer) {
			IN_DeactivateMouse();
		} else {
			IN_ActivateMouse( );
		}
	}

	IN_ProcessEvents( );

	// in case we had to delay actual restart of video system...
	if ( (vidRestartTime != 0) && (vidRestartTime < Sys_Milliseconds()) )
	{
		vidRestartTime = 0;
		Cbuf_AddText( "vid_restart\n" );
	}
}
Ejemplo n.º 20
0
static int do_messages(_THIS, short *message)
{
	int quit, posted;

	quit=0;
	switch (message[0]) {
		case WM_CLOSED:
		case AP_TERM:    
			posted = SDL_PrivateQuit();
			quit=1;
			break;
		case WM_MOVED:
			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
			break;
		case WM_TOPPED:
			wind_set(message[3],WF_TOP,message[4],0,0,0);
			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
			break;
		case WM_REDRAW:
			GEM_wind_redraw(this, message[3],&message[4]);
			break;
		case WM_ICONIFY:
		case WM_ALLICONIFY:
			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
			/* If we're active, make ourselves inactive */
			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
				/* Send an internal deactivate event */
				SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
			}
			/* Update window title */
			if (GEM_refresh_name && GEM_icon_name) {
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
				GEM_refresh_name = SDL_FALSE;
			}
			break;
		case WM_UNICONIFY:
			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
			/* If we're not active, make ourselves active */
			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
				/* Send an internal activate event */
				SDL_PrivateAppActive(1, SDL_APPACTIVE);
			}
			if (GEM_refresh_name && GEM_title_name) {
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
				GEM_refresh_name = SDL_FALSE;
			}
Ejemplo n.º 21
0
void Input::pollMouse(float secondsSinceLast)
{
	int mouseX, mouseY;
	mMouseState = SDL_GetMouseState(&mouseX, &mouseY);

	//has the mouse moved?
	Uint8 appState = SDL_GetAppState();
	if (appState & SDL_APPMOUSEFOCUS) {
		//Wait with grabbing the mouse until the app has input focus.
		if (mMouseGrabbingRequested && (appState & SDL_APPINPUTFOCUS)) {
			setMouseGrab(true);
		}
		if (mMousePosition.xPixelPosition != mouseX || mMousePosition.yPixelPosition != mouseY) {

			//we'll calculate the mouse movement difference and send the values to those
			//listening to the MouseMoved event
			float diffX, diffY;
			diffX = (mMousePosition.xPixelPosition - mouseX) / mScreenWidth;
			diffY = (mMousePosition.yPixelPosition - mouseY) / mScreenHeight;
			MouseMotion motion;
			motion.xPosition = mouseX;
			motion.yPosition = mouseY;
			motion.xRelativeMovement = diffX;
			motion.yRelativeMovement = diffY;
			motion.xRelativeMovementInPixels = mMousePosition.xPixelPosition - mouseX;
			motion.yRelativeMovementInPixels = mMousePosition.yPixelPosition - mouseY;
			motion.timeSinceLastMovement = secondsSinceLast;

			EventMouseMoved.emit(motion, mCurrentInputMode);

			bool freezeMouse = false;
			//if we're in gui mode, we'll just send the mouse movement on to CEGUI
			if (mCurrentInputMode == IM_GUI) {

				for (IInputAdapterStore::const_iterator I = mAdapters.begin(); I != mAdapters.end();) {
					IInputAdapter* adapter = *I;
					++I;
					if (!(adapter)->injectMouseMove(motion, freezeMouse))
						break;
				}

			} else {
				freezeMouse = true;
			}

			if (freezeMouse) {
				SDL_WarpMouse(mMousePosition.xPixelPosition, mMousePosition.yPixelPosition);
			} else {
				mMousePosition.xPixelPosition = mouseX;
				mMousePosition.yPixelPosition = mouseY;
				mMousePosition.xRelativePosition = mouseX / mScreenWidth;
				mMousePosition.yRelativePosition = mouseY / mScreenHeight;
			}

		}
	}

}
Ejemplo n.º 22
0
bool sdlwrap_window_has_focus(void)
{
#if SDL_MODERN
   Uint32 flags = SDL_GetWindowFlags(g_window);
   flags &= SDL_WINDOW_INPUT_FOCUS;
   return flags == SDL_WINDOW_INPUT_FOCUS;
#else
   return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
#endif
}
Ejemplo n.º 23
0
static void UpdateFocus(void)
{
    Uint8 state;

    state = SDL_GetAppState();

    // We should have input (keyboard) focus and be visible
    // (not minimized)
    havefocus = (state & SDL_APPINPUTFOCUS) && (state & SDL_APPACTIVE);
}
Ejemplo n.º 24
0
/*
 * @brief
 */
static void Cl_DrawCursor(void) {

	if (cls.key_state.dest != KEY_UI && cls.mouse_state.grabbed)
		return;

	if (!(SDL_GetAppState() & SDL_APPMOUSEFOCUS))
		return;

	R_DrawCursor(cls.mouse_state.x, cls.mouse_state.y);
}
Ejemplo n.º 25
0
bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags, double x_axis, double y_axis)
{
	bool mouse_in_window = (SDL_GetAppState() & SDL_APPMOUSEFOCUS) != 0
		|| preferences::get("scroll_when_mouse_outside", true);
	bool keyboard_focus = have_keyboard_focus();
	int scroll_speed = preferences::scroll_speed();
	int dx = 0, dy = 0;
	int scroll_threshold = (preferences::mouse_scroll_enabled())
		? preferences::mouse_scroll_threshold() : 0;
	BOOST_FOREACH(const theme::menu& m, get_display().get_theme().menus()) {
		if (point_in_rect(mousex, mousey, m.get_location())) {
			scroll_threshold = 0;
		}
	}
	if ((key[SDLK_UP] && keyboard_focus) ||
	    (mousey < scroll_threshold && mouse_in_window))
	{
		dy -= scroll_speed;
	}
	if ((key[SDLK_DOWN] && keyboard_focus) ||
	    (mousey > get_display().h() - scroll_threshold && mouse_in_window))
	{
		dy += scroll_speed;
	}
	if ((key[SDLK_LEFT] && keyboard_focus) ||
	    (mousex < scroll_threshold && mouse_in_window))
	{
		dx -= scroll_speed;
	}
	if ((key[SDLK_RIGHT] && keyboard_focus) ||
	    (mousex > get_display().w() - scroll_threshold && mouse_in_window))
	{
		dx += scroll_speed;
	}
	if ((mouse_flags & SDL_BUTTON_MMASK) != 0 && preferences::middle_click_scrolls()) {
		const SDL_Rect& rect = get_display().map_outside_area();
		if (point_in_rect(mousex, mousey,rect)) {
			// relative distance from the center to the border
			// NOTE: the view is a rectangle, so can be more sensible in one direction
			// but seems intuitive to use and it's useful since you must
			// more often scroll in the direction where the view is shorter
			const double xdisp = ((1.0*mousex / rect.w) - 0.5);
			const double ydisp = ((1.0*mousey / rect.h) - 0.5);
			// 4.0 give twice the normal speed when mouse is at border (xdisp=0.5)
			int speed = 4 * scroll_speed;
			dx += round_double(xdisp * speed);
			dy += round_double(ydisp * speed);
		}
	}

	dx += round_double( x_axis * scroll_speed);
	dy += round_double( y_axis * scroll_speed);

	return get_display().scroll(dx, dy);
}
//
// I_FinishUpdate
//
void I_FinishUpdate (void)
{
    static int	lasttic;
    int		tics;
    int		i;
    // UNUSED static unsigned char *bigscreen=0;

    if (!initialized)
        return;

    if (noblit)
        return;
    
    UpdateGrab();

    // Don't update the screen if the window isn't visible.
    // Not doing this breaks under Windows when we alt-tab away 
    // while fullscreen.

    if (!(SDL_GetAppState() & SDL_APPACTIVE))
        return;

    // draws little dots on the bottom of the screen
    if (devparm)
    {

	i = I_GetTime();
	tics = i - lasttic;
	lasttic = i;
	if (tics > 20) tics = 20;

	for (i=0 ; i<tics*2 ; i+=4)
	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff;
	for ( ; i<20*4 ; i+=4)
	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
    
    }

    // draw to screen

    BlitArea(0, 0, SCREENWIDTH, SCREENHEIGHT);
    
    // If we have a palette to set, the act of setting the palette
    // updates the screen

    if (palette_to_set)
    {
        SDL_SetColors(screen, palette, 0, 256);
        palette_to_set = false;
    }
    else
    {
        SDL_Flip(screen);
    }
}
Ejemplo n.º 27
0
void es_getAppState(sdl_data *sd, int len,char *buff)
{
   int sendlen;
   char *bp, *start;
   Uint8 state;

   bp = start = sdl_get_temp_buff(sd, 1);
   state = SDL_GetAppState();
   put8(bp, state);
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}
Ejemplo n.º 28
0
int display_update_root_handler (window_info *win)
{
	if (SDL_GetAppState () & SDL_APPACTIVE)
	{	
		draw_console_pic (cons_text);
		draw_update_interface (win->len_x, win->len_y);
		CHECK_GL_ERRORS();
	}
	
	draw_delay = 20;
	return 1;
}
Ejemplo n.º 29
0
/*
===============
IN_Init
===============
*/
void IN_Init( void )
{
	int appState;

	if ( !SDL_WasInit( SDL_INIT_VIDEO ) )
	{
		Com_Error( ERR_FATAL, "IN_Init called before SDL_Init( SDL_INIT_VIDEO )\n" );
		return;
	}

	Com_DPrintf( "\n------- Input Initialization -------\n" );

	in_keyboardDebug = Cvar_Get( "in_keyboardDebug", "0", CVAR_ARCHIVE );

	// mouse variables
	in_mouse = Cvar_Get( "in_mouse", "1", CVAR_ARCHIVE );
	in_nograb = Cvar_Get( "in_nograb", "0", CVAR_ARCHIVE );

	in_joystick = Cvar_Get( "in_joystick", "0", CVAR_ARCHIVE | CVAR_LATCH );
	in_joystickDebug = Cvar_Get( "in_joystickDebug", "0", CVAR_TEMP );
	in_joystickThreshold = Cvar_Get( "in_joystickThreshold", "0.15", CVAR_ARCHIVE );

#ifdef MACOS_X_ACCELERATION_HACK
	in_disablemacosxmouseaccel = Cvar_Get( "in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE );
#endif

	in_xbox360Controller = Cvar_Get( "in_xbox360Controller", "1", CVAR_TEMP );
	in_xbox360ControllerAvailable = Cvar_Get( "in_xbox360ControllerAvailable", "0", CVAR_ROM );
	in_xbox360ControllerDebug = Cvar_Get( "in_xbox360ControllerDebug", "0", CVAR_TEMP );

	SDL_EnableUNICODE( 1 );
	SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
	keyRepeatEnabled = qtrue;

	if ( in_mouse->value )
	{
		mouseAvailable = qtrue;
		IN_ActivateMouse();
	}
	else
	{
		IN_DeactivateMouse();
		mouseAvailable = qfalse;
	}

	appState = SDL_GetAppState();
	Cvar_SetValue( "com_unfocused", !( appState & SDL_APPINPUTFOCUS ) );
	Cvar_SetValue( "com_minimized", !( appState & SDL_APPACTIVE ) );

	IN_InitJoystick();
	Com_DPrintf( "------------------------------------\n" );
}
Ejemplo n.º 30
0
/* Check to see if we need to enter or leave mouse relative mode */
void X11_CheckMouseModeNoLock(_THIS)
{
	const Uint8 full_focus = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
	char *env_override;
	int enable_relative = 1;

	/* Allow the user to override the relative mouse mode.
	   They almost never want to do this, as it seriously affects
	   applications that rely on continuous relative mouse motion.
	*/
	env_override = SDL_getenv("SDL_MOUSE_RELATIVE");
	if ( env_override ) {
		enable_relative = atoi(env_override);
	}

	/* If the mouse is hidden and input is grabbed, we use relative mode */
	if ( enable_relative &&
	     !(SDL_cursorstate & CURSOR_VISIBLE) &&
	     (this->input_grab != SDL_GRAB_OFF) &&
             (SDL_GetAppState() & full_focus) == full_focus ) {
		if ( ! mouse_relative ) {
			X11_EnableDGAMouse(this);
			if ( ! (using_dga & DGA_MOUSE) ) {
				char *xmouse_accel;

				SDL_GetMouseState(&mouse_last.x, &mouse_last.y);
				/* Use as raw mouse mickeys as possible */
				XGetPointerControl(SDL_Display,
						&mouse_accel.numerator, 
						&mouse_accel.denominator,
						&mouse_accel.threshold);
				xmouse_accel=SDL_getenv("SDL_VIDEO_X11_MOUSEACCEL");
				if ( xmouse_accel ) {
					SetMouseAccel(this, xmouse_accel);
				}
			}
			mouse_relative = 1;
		}
	} else {
		if ( mouse_relative ) {
			if ( using_dga & DGA_MOUSE ) {
				X11_DisableDGAMouse(this);
			} else {
				XChangePointerControl(SDL_Display, True, True,
						mouse_accel.numerator, 
						mouse_accel.denominator,
						mouse_accel.threshold);
			}
			mouse_relative = 0;
		}
	}
}