本文整理汇总了C++中SDL_UpdateRects函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_UpdateRects函数的具体用法?C++ SDL_UpdateRects怎么用?C++ SDL_UpdateRects使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_UpdateRects函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Statusbar_Update
/**
* Update statusbar information (leds etc) if/when needed.
*
* May not be called when screen is locked (SDL limitation).
*/
void Statusbar_Update(SDL_Surface *surf)
{
Uint32 color, currentticks;
SDL_Rect rect;
int i;
if (!(StatusbarHeight && ConfigureParams.Screen.bShowStatusbar)) {
/* not enabled (anymore), show overlay led instead? */
if (ConfigureParams.Screen.bShowDriveLed) {
Statusbar_OverlayDraw(surf);
}
return;
}
assert(surf);
/* Statusbar_Init() not called before this? */
assert(surf->h == ScreenHeight + StatusbarHeight);
rect = LedRect;
currentticks = SDL_GetTicks();
for (i = 0; i < NUM_DEVICE_LEDS; i++) {
if (Led[i].expire && Led[i].expire < currentticks) {
Led[i].state = false;
}
if (Led[i].state == Led[i].oldstate) {
continue;
}
Led[i].oldstate = Led[i].state;
if (Led[i].state) {
color = LedColorOn;
} else {
color = LedColorOff;
}
rect.x = Led[i].offset;
SDL_FillRect(surf, &rect, color);
SDL_UpdateRects(surf, 1, &rect);
DEBUGPRINT(("LED[%d] = %s\n", i, Led[i].state?"ON":"OFF"));
}
Statusbar_ShowMessage(surf, currentticks);
/* Draw dsp LED */
if (bOldDspLed) {
color = DspColorOn;
} else {
color = DspColorOff;
}
SDL_FillRect(surf, &DspLedRect, color);
SDL_UpdateRects(surf, 1, &DspLedRect);
DEBUGPRINT(("DSP LED = ON\n"));
/* Draw scr2 LED */
if (bOldSystemLed) {
color = SysColorOn;
} else {
color = SysColorOff;
}
SDL_FillRect(surf, &SystemLedRect, color);
SDL_UpdateRects(surf, 1, &SystemLedRect);
DEBUGPRINT(("SCR2 LED = ON\n"));
}
示例2: black_sdl_flip
void
black_sdl_flip(game_manager * manager)
{
/* Dirty_rects holds the new image locations and erase_rects holds the previous frames
* locations. Both should be updated and then dirty_rects should be copied over to erase_rects,
* dirty_rects should then be erased.
*/
SDL_Surface *screen = manager->sdl_driver->screen;
if(!manager->sdl_driver->full_screen_update)
{
SDL_UpdateRects(screen, manager->sdl_driver->dirty_rects_i, manager->sdl_driver->dirty_rects);
SDL_UpdateRects(screen, manager->sdl_driver->erase_rects_i, manager->sdl_driver->erase_rects);
erase_rects(manager);
manager->sdl_driver->dirty_rects_i = 0;
} else {
SDL_Flip(screen);
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
manager->sdl_driver->full_screen_update = 0;
}
}
示例3: SDL_LockSurface
void SystemStub_SDL::updateScreen(uint8 shakeOffset) {
//SDL_Flip(_screen);
const int mul = _scalers[_scaler].factor;
if (shakeOffset == 0) {
for (int i = 0; i < _numBlitRects; ++i) {
SDL_Rect *br = &_blitRects[i];
int16 dx = br->x * mul;
int16 dy = br->y * mul;
SDL_LockSurface(_sclscreen);
uint16 *dst = (uint16 *)_sclscreen->pixels + dy * _sclscreen->pitch / 2 + dx;
const uint16 *src = (uint16 *)_offscreen + (br->y + 1) * _screenW + (br->x + 1);
(*_scalers[_scaler].proc)(dst, _sclscreen->pitch, src, _screenW, br->w, br->h);
SDL_UnlockSurface(_sclscreen);
br->x *= mul;
br->y *= mul;
br->w *= mul;
br->h *= mul;
SDL_BlitSurface(_sclscreen, br, _screen, br);
}
SDL_UpdateRects(_screen, _numBlitRects, _blitRects);
} else {
SDL_LockSurface(_sclscreen);
uint16 w = _screenW;
uint16 h = _screenH - shakeOffset;
uint16 *dst = (uint16 *)_sclscreen->pixels;
const uint16 *src = (uint16 *)_offscreen + _screenW + 1;
(*_scalers[_scaler].proc)(dst, _sclscreen->pitch, src, _screenW, w, h);
SDL_UnlockSurface(_sclscreen);
SDL_Rect bsr, bdr;
bdr.x = 0;
bdr.y = 0;
bdr.w = _screenW * mul;
bdr.h = shakeOffset * mul;
SDL_FillRect(_screen, &bdr, _pal[_overscanColor]);
bsr.x = 0;
bsr.y = 0;
bsr.w = _screenW * mul;
bsr.h = (_screenH - shakeOffset) * mul;
bdr.x = 0;
bdr.y = shakeOffset * mul;
bdr.w = bsr.w;
bdr.h = bsr.h;
SDL_BlitSurface(_sclscreen, &bsr, _screen, &bdr);
bdr.x = 0;
bdr.y = 0;
bdr.w = _screenW * mul;
bdr.h = _screenH * mul;
SDL_UpdateRects(_screen, 1, &bdr);
}
_numBlitRects = 0;
}
示例4: if
void screen_c::flipDirty(void)
{
SDL_Rect rects[10*13];
int numrects = 0;
for (int y = 0; y < 13; y++)
{
int rowStart = -1;
for (int x = 0; x < 21; x++)
{
if (isDirty(x, y) && (x < 20))
{
if (rowStart == -1)
rowStart = x;
}
else if (rowStart != -1)
{
rects[numrects].y = blockY*y;
rects[numrects].x = blockX*rowStart;
if (y == 12)
rects[numrects].h = blockY/2;
else
rects[numrects].h = blockY;
rects[numrects].w = blockX*(x-rowStart);
numrects++;
rowStart = -1;
}
}
}
SDL_UpdateRects(video, numrects, rects);
animationState = 0;
}
示例5: MoveSprite
void
MoveSprite(SDL_Surface * screen, SDL_Surface * light)
{
SDL_Rect updates[2];
Uint8 alpha;
/* Erase the sprite if it was visible */
if (sprite_visible) {
updates[0] = position;
SDL_BlitSurface(backing, NULL, screen, &updates[0]);
} else {
updates[0].x = 0;
updates[0].y = 0;
updates[0].w = 0;
updates[0].h = 0;
sprite_visible = 1;
}
/* Since the sprite is off the screen, we can do other drawing
without being overwritten by the saved area behind the sprite.
*/
if (light != NULL) {
int x, y;
SDL_GetMouseState(&x, &y);
FlashLight(screen, light, x, y);
}
/* Move the sprite, bounce at the wall */
position.x += x_vel;
if ((position.x < 0) || (position.x >= screen->w)) {
x_vel = -x_vel;
position.x += x_vel;
}
position.y += y_vel;
if ((position.y < 0) || (position.y >= screen->h)) {
y_vel = -y_vel;
position.y += y_vel;
}
/* Update transparency (fade in and out) */
SDL_GetSurfaceAlphaMod(sprite, &alpha);
if (((int) alpha + alpha_vel) < 0) {
alpha_vel = -alpha_vel;
} else if (((int) alpha + alpha_vel) > 255) {
alpha_vel = -alpha_vel;
}
SDL_SetAlpha(sprite, SDL_SRCALPHA, (Uint8) (alpha + alpha_vel));
/* Save the area behind the sprite */
updates[1] = position;
SDL_BlitSurface(screen, &updates[1], backing, NULL);
/* Blit the sprite onto the screen */
updates[1] = position;
SDL_BlitSurface(sprite, NULL, screen, &updates[1]);
/* Make it so! */
SDL_UpdateRects(screen, 2, updates);
}
示例6: no_rows
/**
* Initialize SDL
*
* @param int rows the number of rows that will be displayed
* @param int cols the number of columns that will be displayed
* @param int i the time interval in milliseconds after which the next
* generation is drawn
* @param ConwaysGameOfLife *cgol pointer to the object that encapsulates the
* game's actual logic
* @param positions_t positions the first generation of cells to be displayed
*
* @throws SDLException if SDL coudn't be initialized
*
* @see{
* game::getWindowSize
* }
*
* TODO: allow the user to draw his own pattern using the mouse at the start
* A nice feature for this would be to highlight the cell under the and only
* set it if the user clicks on it
*/
Game::Game(int rows, int cols, unsigned int i, SDL_Color acolor,
SDL_Color dcolor, ConwaysGameOfLife *cgol, positions_t pos)
: no_rows(rows), no_columns(cols), interval(i), life(cgol){
if(SDL_Init(SDL_INIT_VIDEO) < 0){
throw SDLException("Couldn't initialize SDL!");
}
const SDL_VideoInfo* vinfo = SDL_GetVideoInfo();
unsigned int length = std::min(vinfo->current_w, vinfo->current_h) - 50;
setCellSideLength(length);
SDL_Rect size = getWindowSize(length);
screen = SDL_SetVideoMode(size.w, size.h, vinfo->vfmt->BitsPerPixel, flags);
if(screen == nullptr){
throw SDLException("Couldn't set SDL video mode!");
}
alive_color = SDL_MapRGB(vinfo->vfmt, acolor.r, acolor.g, acolor.b);
dead_color = SDL_MapRGB(vinfo->vfmt, dcolor.r, dcolor.g, dcolor.b);
std::vector<SDL_Rect> rects = setCells(pos, alive_color);
SDL_UpdateRects(screen, rects.size(), rects.data());
running = true;
}
示例7: put_sprite2
/**
* Put sprite to screen and immediately update
* real screen.
* This version double y co-ordinate and height
*/
void put_sprite2(int x, int y, int breite, int hoehe, pointer sprite)
{
pointer screen_ptr;
SDL_Rect pos;
int row;
y <<=1;
screen_ptr = (pointer)screen->pixels + ((y << 8) + (y << 6) + x);
for (row = 0; row < hoehe; row++)
{
memcpy(screen_ptr, sprite, breite);
screen_ptr+=320;
memcpy(screen_ptr, sprite, breite);
screen_ptr+=320;
sprite += breite;
}
pos.x = x;
pos.y = y;
pos.w = breite;
pos.h = hoehe<<1;
SDL_BlitSurface(screen, &pos, real_screen, &pos);
SDL_UpdateRects(real_screen, 1, &pos);
}
示例8: SDL_UpdateRect
/*
Refresh display at given coordinates.
Unlike SDL_UpdateRect() this function can eat coords that goes beyond screen
boundaries.
"rect" will be modified to represent the area actually refreshed.
*/
void SDLGui_UpdateRect(SDL_Rect *rect)
{
if (rect->x < 0)
{
rect->w += rect->x;
rect->x = 0;
}
if ((rect->x + rect->w) > sdlscrn->w)
rect->w = (sdlscrn->w - rect->x);
if (rect->y < 0)
{
rect->h += rect->y;
rect->y = 0;
}
if ((rect->y + rect->h) > sdlscrn->h)
rect->h = (sdlscrn->h - rect->y);
if ((rect->w > 0) && (rect->h > 0))
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
host->video->refreshScreenFromSurface(sdlscrn);
#else
SDL_UpdateRects(sdlscrn, 1, rect);
#endif
} else
{
rect->x = 0;
rect->y = 0;
rect->w = 0;
rect->h = 0;
}
}
示例9: jpeg_blitimg2screen
static int jpeg_blitimg2screen(SDL_Surface *img, /* proper name? */
SDL_Surface *screen){
int ret;
SDL_Rect dstrect;
if (SDL_MUSTLOCK(screen)) {
if (SDL_LockSurface(screen) < 0) {
ComplainAndExit();
}
}
dstrect.x = 0;
dstrect.y = 0;
dstrect.w = img->w;
dstrect.h = img->h;
ret=0;
if (SDL_BlitSurface(img, NULL, screen, &dstrect) < 0) {
ret=1;
goto fail;
}
SDL_UpdateRects(screen, 1, &dstrect);
/* screen surface unlock */
fail:
if (SDL_MUSTLOCK(screen)) {
SDL_UnlockSurface(screen);
}
return ret;
}
示例10: gameover
void
gameover(struct game *g)
{
SDL_Rect r;
struct position *p = g->frontend;
int pph; /* points per hour */
#if 0
if (g->running == false)
return;
#endif
pph = g->points * 3600.f / (time(NULL) - g->game_time);
r.x = p->x + 10;
r.y = p->y + p->size * PREVIEW_H + 60;
char endMsg[1024];
sprintf(endMsg,"GAME OVER\nYour Score: %i\nPress any key/button",g->points,g->lines_cleared,g->level);
sf_puts(screen, &r, endMsg);
SDL_UpdateRects(screen, 1, &r);
r.y += r.h;
SDL_Event e;
while (SDL_WaitEvent(&e) && (e.type != SDL_KEYDOWN && e.type != SDL_MOUSEBUTTONDOWN)) {
SDL_Delay(10);
}
#if 0
g->running = false;
#endif
restart_game(g);
}
示例11: Statusbar_OverlayDraw
/**
* Draw overlay led onto screen surface if any drives are enabled.
*/
static void Statusbar_OverlayDraw(SDL_Surface *surf)
{
Uint32 currentticks = SDL_GetTicks();
int i;
assert(surf);
for (i = 0; i < NUM_DEVICE_LEDS; i++) {
if (Led[i].state) {
if (Led[i].expire && Led[i].expire < currentticks) {
Led[i].state = false;
continue;
}
Statusbar_OverlayDrawLed(surf, LedColorOn);
break;
}
}
/* possible state transitions:
* NONE -> DRAWN -> RESTORED -> DRAWN -> RESTORED -> NONE
* Other than NONE state needs to be updated on screen
*/
switch (bOverlayState) {
case OVERLAY_RESTORED:
bOverlayState = OVERLAY_NONE;
case OVERLAY_DRAWN:
SDL_UpdateRects(surf, 1, &OverlayLedRect);
DEBUGPRINT(("Overlay LED = %s\n", bOverlayState==OVERLAY_DRAWN?"ON":"OFF"));
break;
case OVERLAY_NONE:
break;
}
}
示例12: DrawBox
/* Draw a randomly sized and colored box centered about (X,Y) */
void
DrawBox(SDL_Surface * screen, int X, int Y, int width, int height)
{
static unsigned int seeded = 0;
SDL_Rect area;
Uint32 color;
Uint32 randc;
/* Seed the random number generator */
if (seeded == 0) {
srand((unsigned int)time(NULL));
seeded = 1;
}
/* Get the bounds of the rectangle */
area.w = (rand() % width);
area.h = (rand() % height);
area.x = X - (area.w / 2);
area.y = Y - (area.h / 2);
randc = (rand() % NUM_COLORS);
if (screen->format->BytesPerPixel == 1) {
color = randc;
} else {
color = SDL_MapRGB(screen->format, randc, randc, randc);
}
/* Do it! */
SDL_FillRect(screen, &area, color);
if (screen->flags & SDL_DOUBLEBUF) {
SDL_Flip(screen);
} else {
SDL_UpdateRects(screen, 1, &area);
}
}
示例13: RealizeVideoMemory
/**
** Realize video memory.
*/
void RealizeVideoMemory()
{
#if defined(USE_OPENGL) || defined(USE_GLES)
if (UseOpenGL) {
#ifdef USE_GLES_MAEMO
SDL_GLES_SwapBuffers();
#endif
#ifdef USE_GLES_EGL
eglSwapBuffers(eglDisplay, eglSurface);
#endif
#if defined(USE_OPENGL) || defined(USE_GLES_NATIVE)
if (GLShaderPipelineSupported) {
RenderFramebufferToScreen();
} else {
SDL_GL_SwapBuffers();
}
#endif
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} else
#endif
{
if (NumRects) {
SDL_UpdateRects(TheScreen, NumRects, Rects);
NumRects = 0;
}
}
HideCursor();
}
示例14: SDL_UpdateRects
// generate_clips must be called once before this
bool RectManager::update_rects(SDL_Surface * surf) {
if (!m_Clips)
return false;
SDL_UpdateRects(surf, m_Clips->length, &m_Clips->rects);
return true;
}
示例15: Display
/* Redraw the widget and only the widget */
void GUI_Widget::Redraw(void)
{
if (status==WIDGET_VISIBLE)
{
Display();
SDL_UpdateRects(screen,1,&area);
}
}