本文整理汇总了C++中SDL_GetAppState函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetAppState函数的具体用法?C++ SDL_GetAppState怎么用?C++ SDL_GetAppState使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_GetAppState函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: native_drainevents
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;
}
示例2: IN_DeactivateMouse
/*
===============
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;
}
}
示例3: SDL_GetAppState
bool SDLWindow::hasFocus() const {
uint8 s = SDL_GetAppState();
return ((s & SDL_APPMOUSEFOCUS) != 0) &&
((s & SDL_APPINPUTFOCUS) != 0) &&
((s & SDL_APPACTIVE) != 0);
}
示例4: UNUSED
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;
}
示例5: UpdateFocus
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;
}
}
示例6: DIB_GenerateMouseMotionEvent
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, ¢er);
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);
}
}
示例7: SDL_VERSION_ATLEAST
bool MouseCursor::hasFocus() const {
#if SDL_VERSION_ATLEAST(2,0,0)
return (SDL_GetMouseFocus() == display.sdl_window);
#else
return (SDL_GetAppState() & SDL_APPMOUSEFOCUS);
#endif
}
示例8: get_display
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();
}
示例9: IN_Frame
/*
===============
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" );
}
}
示例10: AppMinimized
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...");
}
示例11: IN_Frame
/*
===============
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( );
}
示例12: MenuLoop
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);
}
}
示例13: DIB_SetGammaRamp
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 */
}
示例14: drawCursor
/**
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());
}
}
示例15: DIB_GenerateMouseMotionEvent
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, ¢er);
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);
}
}