本文整理汇总了C++中SDL_VideoDevice类的典型用法代码示例。如果您正苦于以下问题:C++ SDL_VideoDevice类的具体用法?C++ SDL_VideoDevice怎么用?C++ SDL_VideoDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_VideoDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_WarpMouse
void SDL_WarpMouse (Uint16 x, Uint16 y)
{
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if ( !video || !SDL_PublicSurface ) {
SDL_SetError("A video mode must be set before warping mouse");
return;
}
/* If we have an offset video mode, offset the mouse coordinates */
if (this->screen->pitch == 0) {
x += this->screen->offset / this->screen->format->BytesPerPixel;
y += this->screen->offset;
} else {
x += (this->screen->offset % this->screen->pitch) /
this->screen->format->BytesPerPixel;
y += (this->screen->offset / this->screen->pitch);
}
/* This generates a mouse motion event */
if ( video->WarpWMCursor ) {
video->WarpWMCursor(this, x, y);
} else {
SDL_PrivateMouseMotion(0, 0, x, y);
}
}
示例2: SDL_FreeCursor
void SDL_FreeCursor (SDL_Cursor *cursor)
{
if ( cursor ) {
if ( cursor == SDL_cursor ) {
SDL_SetCursor(SDL_defcursor);
}
if ( cursor != SDL_defcursor ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if ( cursor->data ) {
SDL_free(cursor->data);
}
if ( cursor->save[0] ) {
SDL_free(cursor->save[0]);
}
if ( video && cursor->wm_cursor ) {
if ( video->FreeWMCursor ) {
video->FreeWMCursor(this, cursor->wm_cursor);
}
}
SDL_free(cursor);
}
}
}
示例3: SDL_ShowCursor
int SDL_ShowCursor (int toggle)
{
int showing;
showing = (SDL_cursorstate & CURSOR_VISIBLE);
if ( toggle >= 0 ) {
SDL_LockCursor();
if ( toggle ) {
SDL_cursorstate |= CURSOR_VISIBLE;
} else {
SDL_cursorstate &= ~CURSOR_VISIBLE;
}
SDL_UnlockCursor();
if ( (SDL_cursorstate & CURSOR_VISIBLE) != showing ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
SDL_SetCursor(NULL);
if ( video && video->CheckMouseMode ) {
video->CheckMouseMode(this);
}
}
} else {
/* Query current state */ ;
}
return(showing ? 1 : 0);
}
示例4:
SDL_Overlay *SDL_CreateYUVOverlay(int w, int h, Uint32 format,
SDL_Surface *display)
{
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
const char *yuv_hwaccel;
SDL_Overlay *overlay;
if ( (display->flags & SDL_OPENGL) == SDL_OPENGL ) {
SDL_SetError("YUV overlays are not supported in OpenGL mode");
return NULL;
}
/* Display directly on video surface, if possible */
if ( SDL_getenv("SDL_VIDEO_YUV_DIRECT") ) {
if ( (display == SDL_PublicSurface) &&
((SDL_VideoSurface->format->BytesPerPixel == 2) ||
(SDL_VideoSurface->format->BytesPerPixel == 4)) ) {
display = SDL_VideoSurface;
}
}
overlay = NULL;
yuv_hwaccel = SDL_getenv("SDL_VIDEO_YUV_HWACCEL");
if ( ((display == SDL_VideoSurface) && video->CreateYUVOverlay) &&
(!yuv_hwaccel || (SDL_atoi(yuv_hwaccel) > 0)) ) {
overlay = video->CreateYUVOverlay(this, w, h, format, display);
}
/* If hardware YUV overlay failed ... */
if ( overlay == NULL ) {
overlay = SDL_CreateYUV_SW(this, w, h, format, display);
}
return overlay;
}
示例5: SDL_SetGamma
int SDL_SetGamma(float red, float green, float blue)
{
int succeeded;
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
succeeded = -1;
#ifdef USE_MATH_H
/* Prefer using SetGammaRamp(), as it's more flexible */
{
Uint16 ramp[3][256];
CalculateGammaRamp(red, ramp[0]);
CalculateGammaRamp(green, ramp[1]);
CalculateGammaRamp(blue, ramp[2]);
succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]);
}
#else
SDL_SetError("Gamma correction not supported");
#endif
if ( (succeeded < 0) && video->SetGamma ) {
SDL_ClearError();
succeeded = video->SetGamma(this, red, green, blue);
}
return succeeded;
}
示例6: SDL_SetCursor
/* SDL_SetCursor(NULL) can be used to force the cursor redraw,
if this is desired for any reason. This is used when setting
the video mode and when the SDL window gains the mouse focus.
*/
void SDL_SetCursor (SDL_Cursor *cursor)
{
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
/* Make sure that the video subsystem has been initialized */
if ( ! video ) {
return;
}
/* Prevent the event thread from moving the mouse */
SDL_LockCursor();
/* Set the new cursor */
if ( cursor && (cursor != SDL_cursor) ) {
/* Erase the current mouse position */
if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
SDL_EraseCursor(SDL_VideoSurface);
} else if ( video->MoveWMCursor ) {
/* If the video driver is moving the cursor directly,
it needs to hide the old cursor before (possibly)
showing the new one. (But don't erase NULL cursor)
*/
if ( SDL_cursor ) {
video->ShowWMCursor(this, NULL);
}
}
SDL_cursor = cursor;
}
/* Draw the new mouse cursor */
if ( SDL_cursor && (SDL_cursorstate&CURSOR_VISIBLE) ) {
/* Use window manager cursor if possible */
if ( SDL_cursor->wm_cursor &&
video->ShowWMCursor(this, SDL_cursor->wm_cursor) )
SDL_cursorstate &= ~CURSOR_USINGSW;
else {
SDL_cursorstate |= CURSOR_USINGSW;
if ( video->ShowWMCursor ) {
video->ShowWMCursor(this, NULL);
}
{ int x, y;
SDL_GetMouseState(&x, &y);
SDL_cursor->area.x = (x - SDL_cursor->hot_x);
SDL_cursor->area.y = (y - SDL_cursor->hot_y);
}
SDL_DrawCursor(SDL_VideoSurface);
}
} else {
/* Erase window manager mouse (cursor not visible) */
if ( SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW) ) {
SDL_EraseCursor(SDL_VideoSurface);
} else {
if ( video ) {
video->ShowWMCursor(this, NULL);
}
}
}
SDL_UnlockCursor();
}
示例7: SDL_SetAlpha
/* This function sets the alpha channel of a surface */
int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
{
Uint32 oldflags = surface->flags;
Uint32 oldalpha = surface->format->alpha;
/* Sanity check the flag as it gets passed in */
if ( flag & SDL_SRCALPHA ) {
if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
} else {
flag = SDL_SRCALPHA;
}
} else {
flag = 0;
}
/* Optimize away operations that don't change anything */
if ( (flag == (surface->flags & (SDL_SRCALPHA|SDL_RLEACCELOK))) &&
(!flag || value == oldalpha) ) {
return(0);
}
if(!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
SDL_UnRLESurface(surface, 1);
if ( flag ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
surface->flags |= SDL_SRCALPHA;
surface->format->alpha = value;
if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
if ( (video->SetHWAlpha == NULL) ||
(video->SetHWAlpha(this, surface, value) < 0) ) {
surface->flags &= ~SDL_HWACCEL;
}
}
if ( flag & SDL_RLEACCELOK ) {
surface->flags |= SDL_RLEACCELOK;
} else {
surface->flags &= ~SDL_RLEACCELOK;
}
} else {
surface->flags &= ~SDL_SRCALPHA;
surface->format->alpha = SDL_ALPHA_OPAQUE;
}
/*
* The representation for software surfaces is independent of
* per-surface alpha, so no need to invalidate the blit mapping
* if just the alpha value was changed. (If either is 255, we still
* need to invalidate.)
*/
if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
|| oldflags != surface->flags
|| (((oldalpha + 1) ^ (value + 1)) & 0x100))
SDL_InvalidateMap(surface->map);
return(0);
}
示例8: SDL_CreateCursor
/* Software cursor drawing support */
SDL_Cursor * SDL_CreateCursor (Uint8 *data, Uint8 *mask,
int w, int h, int hot_x, int hot_y)
{
SDL_VideoDevice *video = current_video;
int savelen;
int i;
SDL_Cursor *cursor;
/* Make sure the width is a multiple of 8 */
w = ((w+7)&~7);
/* Sanity check the hot spot */
if ( (hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h) ) {
SDL_SetError("Cursor hot spot doesn't lie within cursor");
return(NULL);
}
/* Allocate memory for the cursor */
cursor = (SDL_Cursor *)SDL_malloc(sizeof *cursor);
if ( cursor == NULL ) {
SDL_OutOfMemory();
return(NULL);
}
savelen = (w*4)*h;
cursor->area.x = 0;
cursor->area.y = 0;
cursor->area.w = w;
cursor->area.h = h;
cursor->hot_x = hot_x;
cursor->hot_y = hot_y;
cursor->data = (Uint8 *)SDL_malloc((w/8)*h*2);
cursor->mask = cursor->data+((w/8)*h);
cursor->save[0] = (Uint8 *)SDL_malloc(savelen*2);
cursor->save[1] = cursor->save[0] + savelen;
cursor->wm_cursor = NULL;
if ( ! cursor->data || ! cursor->save[0] ) {
SDL_FreeCursor(cursor);
SDL_OutOfMemory();
return(NULL);
}
for ( i=((w/8)*h)-1; i>=0; --i ) {
cursor->data[i] = data[i];
cursor->mask[i] = mask[i] | data[i];
}
SDL_memset(cursor->save[0], 0, savelen*2);
/* If the window manager gives us a good cursor, we're done! */
if ( video->CreateWMCursor ) {
cursor->wm_cursor = video->CreateWMCursor(video, data, mask,
w, h, hot_x, hot_y);
} else {
cursor->wm_cursor = NULL;
}
return(cursor);
}
示例9: SDL_GobbleEvents
static int SDLCALL SDL_GobbleEvents(void *unused)
{
event_thread = SDL_ThreadID();
#ifdef __OS2__
#ifdef USE_DOSSETPRIORITY
/* Increase thread priority, so it will process events in time for sure! */
DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
#endif
#endif
while ( SDL_EventQ.active ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
/* Get events from the video subsystem */
if ( video ) {
video->PumpEvents(this);
}
/* Queue pending key-repeat events */
SDL_CheckKeyRepeat();
#if !SDL_JOYSTICK_DISABLED
/* Check for joystick state change */
if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
SDL_JoystickUpdate();
}
#endif
/* Give up the CPU for the rest of our timeslice */
SDL_EventLock.safe = 1;
if ( SDL_timer_running ) {
SDL_ThreadedTimerCheck();
}
SDL_Delay(1);
/* Check for event locking.
On the P of the lock mutex, if the lock is held, this thread
will wait until the lock is released before continuing. The
safe flag will be set, meaning that the other thread can go
about it's business. The safe flag is reset before the V,
so as soon as the mutex is free, other threads can see that
it's not safe to interfere with the event thread.
*/
SDL_mutexP(SDL_EventLock.lock);
SDL_EventLock.safe = 0;
SDL_mutexV(SDL_EventLock.lock);
}
SDL_SetTimerThreaded(0);
event_thread = 0;
return(0);
}
示例10: SDL_SetGammaRamp
int SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue)
{
int succeeded;
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
SDL_Surface *screen = SDL_PublicSurface;
/* Verify the screen parameter */
if ( !screen ) {
SDL_SetError("No video mode has been set");
return -1;
}
/* Lazily allocate the gamma tables */
if ( ! video->gamma ) {
SDL_GetGammaRamp(0, 0, 0);
}
/* Fill the gamma table with the new values */
if ( red ) {
SDL_memcpy(&video->gamma[0*256], red, 256*sizeof(*video->gamma));
}
if ( green ) {
SDL_memcpy(&video->gamma[1*256], green, 256*sizeof(*video->gamma));
}
if ( blue ) {
SDL_memcpy(&video->gamma[2*256], blue, 256*sizeof(*video->gamma));
}
/* Gamma correction always possible on split palettes */
if ( (screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) {
SDL_Palette *pal = screen->format->palette;
/* If physical palette has been set independently, use it */
if(video->physpal)
pal = video->physpal;
SDL_SetPalette(screen, SDL_PHYSPAL,
pal->colors, 0, pal->ncolors);
return 0;
}
/* Try to set the gamma ramp in the driver */
succeeded = -1;
if ( video->SetGammaRamp ) {
succeeded = video->SetGammaRamp(this, video->gamma);
} else {
SDL_SetError("Gamma ramp manipulation not supported");
}
return succeeded;
}
示例11: SDL_SetColorKey
/*
* Set the color key in a blittable surface
*/
int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
{
/* Sanity check the flag as it gets passed in */
if ( flag & SDL_SRCCOLORKEY ) {
if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
} else {
flag = SDL_SRCCOLORKEY;
}
} else {
flag = 0;
}
/* Optimize away operations that don't change anything */
if ( (flag == (surface->flags & (SDL_SRCCOLORKEY|SDL_RLEACCELOK))) &&
(key == surface->format->colorkey) ) {
return(0);
}
/* UnRLE surfaces before we change the colorkey */
if ( surface->flags & SDL_RLEACCEL ) {
SDL_UnRLESurface(surface, 1);
}
if ( flag ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
surface->flags |= SDL_SRCCOLORKEY;
surface->format->colorkey = key;
if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
if ( (video->SetHWColorKey == NULL) ||
(video->SetHWColorKey(this, surface, key) < 0) ) {
surface->flags &= ~SDL_HWACCEL;
}
}
if ( flag & SDL_RLEACCELOK ) {
surface->flags |= SDL_RLEACCELOK;
} else {
surface->flags &= ~SDL_RLEACCELOK;
}
} else {
surface->flags &= ~(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
surface->format->colorkey = 0;
}
SDL_InvalidateMap(surface->map);
return(0);
}
示例12: SDL_MoveCursor
void SDL_MoveCursor(int x, int y)
{
SDL_VideoDevice *video = current_video;
/* Erase and update the current mouse position */
if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) {
/* Erase and redraw mouse cursor in new position */
SDL_LockCursor();
SDL_EraseCursor(SDL_VideoSurface);
SDL_cursor->area.x = (x - SDL_cursor->hot_x);
SDL_cursor->area.y = (y - SDL_cursor->hot_y);
SDL_DrawCursor(SDL_VideoSurface);
SDL_UnlockCursor();
} else if ( video->MoveWMCursor ) {
video->MoveWMCursor(video, x, y);
}
}
示例13: SDL_GobbleEvents
static int SDLCALL SDL_GobbleEvents(void *unused)
{
event_thread = SDL_ThreadID();
#ifdef __OS2__
#ifdef USE_DOSSETPRIORITY
DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
#endif
#endif
while ( SDL_EventQ.active ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
if ( video ) {
video->PumpEvents(this);
}
SDL_CheckKeyRepeat();
#if !SDL_JOYSTICK_DISABLED
if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
SDL_JoystickUpdate();
}
#endif
SDL_EventLock.safe = 1;
if ( SDL_timer_running ) {
SDL_ThreadedTimerCheck();
}
SDL_Delay(1);
SDL_mutexP(SDL_EventLock.lock);
SDL_EventLock.safe = 0;
SDL_mutexV(SDL_EventLock.lock);
}
SDL_SetTimerThreaded(0);
event_thread = 0;
return(0);
}
示例14: SDL_SetGamma
int SDL_SetGamma(float red, float green, float blue)
{
int succeeded;
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
succeeded = -1;
/* Prefer using SetGammaRamp(), as it's more flexible */
{
Uint16 ramp[3][256];
CalculateGammaRamp(red, ramp[0]);
CalculateGammaRamp(green, ramp[1]);
CalculateGammaRamp(blue, ramp[2]);
succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]);
}
if ( (succeeded < 0) && video->SetGamma ) {
SDL_ClearError();
succeeded = video->SetGamma(this, red, green, blue);
}
return succeeded;
}
示例15: SDL_PumpEvents
/* Run the system dependent event loops */
void SDL_PumpEvents(void)
{
if ( !SDL_EventThread ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
/* Get events from the video subsystem */
if ( video ) {
video->PumpEvents(this);
}
/* Queue pending key-repeat events */
SDL_CheckKeyRepeat();
#if !SDL_JOYSTICK_DISABLED
/* Check for joystick state change */
if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
SDL_JoystickUpdate();
}
#endif
}
}