/** * 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")); }
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; } }
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; }
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; }
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); }
/** * 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; }
/** * 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); }
/* 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; } }
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; }
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); }
/** * 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; } }
/* 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); } }
/** ** 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(); }
// 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; }
/* Redraw the widget and only the widget */ void GUI_Widget::Redraw(void) { if (status==WIDGET_VISIBLE) { Display(); SDL_UpdateRects(screen,1,&area); } }
void MoveSprites(SDL_Surface *screen, Uint32 background) { int i, nupdates; SDL_Rect area, *position, *velocity; nupdates = 0; /* Erase all the sprites if necessary */ if ( sprites_visible ) { SDL_FillRect(screen, NULL, background); } /* Move the sprite, bounce at the wall, and draw */ for ( i=0; i<numsprites; ++i ) { position = &positions[i]; velocity = &velocities[i]; position->x += velocity->x; if ( (position->x < 0) || (position->x >= (screen->w - sprite_w)) ) { velocity->x = -velocity->x; position->x += velocity->x; } position->y += velocity->y; if ( (position->y < 0) || (position->y >= (screen->h - sprite_w)) ) { velocity->y = -velocity->y; position->y += velocity->y; } /* Blit the sprite onto the screen */ area = *position; SDL_BlitSurface(sprite, NULL, screen, &area); sprite_rects[nupdates++] = area; } #if DEBUG_FLIP { if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { static int t = 0; Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0); SDL_Rect r; r.x = (sin((float)t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w-20); r.y = 0; r.w = 20; r.h = screen->h; SDL_FillRect (screen, &r, color); t+=2; } } #endif /* Update the screen! */ if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { SDL_Flip(screen); } else { SDL_UpdateRects(screen, nupdates, sprite_rects); } sprites_visible = 1; }
void CWidgetDisplay::PaintAllWidgets(CPaintingParms* pPaintingParms, CScreenEngine* pEngine) { for (int iWidget = 0; iWidget < m_pWidgetManager->GetNumWidgets(); iWidget++) { m_pWidgetManager->GetWidget(iWidget)->PaintWidget(pPaintingParms, pEngine); } SDL_UpdateRects(pPaintingParms->m_pDrawingSurface, pPaintingParms->m_aRectsToUpdate); pPaintingParms->m_aRectsToUpdate.clear(); }
void sdl_swap_buffers() { if (dirty_rect_counter > MAX_DIRTY_RECTS) { SDL_UpdateRect(screen.surf, 0, 0, 0, 0); } else if (dirty_rect_counter > 0) { SDL_UpdateRects(screen.surf, dirty_rect_counter, dirty_rects); } dirty_rect_counter = 0; }
HOOKFUNC void SDLCALL MySDL_UpdateRects(SDL_Surface* screen, int numrects, SDL_Rect* rects) { debuglog(LCF_SDL|LCF_FRAME, __FUNCTION__ "(0x%X, %d, 0x%X) called.\n", screen, numrects, rects); usingSDLOrDD = true; if(!ShouldSkipDrawing(true, true)) SDL_UpdateRects(screen, numrects, rects); // used_sdl_flip check needed for eversion, not needed for ? if(!used_sdl_flip) SDLFrameBoundary(screen); }
void clean() { int i; if (gameflags.isfullscreen) { for( i = 0; i < laundrycount; i++) { // fix -- sucks to have to do a loop here, but not // easy to avoid. laundrylist[i].x += (FULLWIDTH - WIDTH) / 2; laundrylist[i].y += FULLTOPMARGIN; } SDL_UpdateRects(fullscreen, laundrycount, laundrylist); } else { SDL_UpdateRects(screen, laundrycount, laundrylist); } laundrycount=0; }
/* ** Thread who manage the SDL event [update map] */ int movement_map(void *param) { t_sdl *sdl; sdl = (t_sdl *)param; while (42) { print_init_map(sdl); put_items_map(sdl); put_users(sdl); put_menu_minimap_sdl(sdl); SDL_UpdateRects(sdl->screen, 1, &sdl->game.pos_player); SDL_UpdateRects(sdl->screen, 1, &sdl->game.pos_item); event_radar(sdl); SDL_UpdateRect(sdl->screen, 0, 0, 0, 0); SDL_Delay(15); } return (0); }
int FbSdl::update(int x, int y, int w, int h, bool /*full*/) { clc::Log::debug("ocher.sdl", "update"); SDL_Rect dest; dest.x = x; dest.y = y; dest.w = w; dest.h = h; SDL_UpdateRects(m_screen, 1, &dest); return 0; }
void Font::drawString(SDL_Surface* surf, const string& text, int x, int y) { int width, height; TTF_SizeText(font_, text.c_str(), &width, &height); SDL_Rect target = { x, y, width, height }; SDL_Surface* textSurface = TTF_RenderText_Blended(font_, text.c_str(), color_); SDL_BlitSurface(textSurface, NULL, surf, &target); SDL_FreeSurface(textSurface); SDL_UpdateRects(surf, 1, &target); }
void gui_refresh(void) { if(dirtyrects < 0) { SDL_UpdateRect(screen, 0, 0, 0, 0); dirtyrects = 0; } else SDL_UpdateRects(screen, dirtyrects, dirtytab); dirtyrects = 0; }
void UpdateScreen(void) { int i; for ( i=0; i<numupdates; ++i ) { SDL_LowerBlit(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect); } SDL_UpdateRects(screen, numupdates, dstupdate); numupdates = 0; }
/** * Draw 'msg' centered to the message area */ static void Statusbar_DrawMessage(SDL_Surface *surf, const char *msg) { int fontw, fonth, offset; SDL_FillRect(surf, &MessageRect, GrayBg); if (*msg) { SDLGui_GetFontSize(&fontw, &fonth); offset = (MessageRect.w - strlen(msg) * fontw) / 2; SDLGui_Text(MessageRect.x + offset, MessageRect.y, msg); } SDL_UpdateRects(surf, 1, &MessageRect); DEBUGPRINT(("Draw message: '%s'\n", msg)); }
void sdl_draw_mandelbrot(SDL_Surface *surface, complex double center, double zoom) { int f,x,y,n; int maxiter = (WIDTH/2) * 0.049715909 * log10(zoom); complex double z, c; float C; static SDL_Rect rects[HEIGHT/FLIPS]; fprintf(stderr, "zoom: %f\n", zoom); fprintf(stderr, "center point: %f %+fi\n", creal(center), cimag(center) ); fprintf(stderr, "iterations: %d\n", maxiter); for (f = 0; f < FLIPS; f++) { for (y = f; y < HEIGHT; y += FLIPS) { for (x = 0; x < WIDTH; x++) { /* Get the complex poing on gauss space to be calculate */ z = c = creal(center) + ((x - (WIDTH/2))/zoom) + ((cimag(center) + ((y - (HEIGHT/2))/zoom))*_Complex_I); #define X creal(z) #define Y cimag(z) /* Check if point lies within the main cardiod or in the period-2 buld */ if ( (pow(X-.25,2) + pow(Y,2))*(pow(X,2) + (X/2) + pow(Y,2) - .1875) < pow(Y,2)/4 || pow(X+1,2) + pow(Y,2) < .0625 ) n = maxiter; else /* Applies the actual mandelbrot formula on that point */ for (n = 0; n <= maxiter && cabs(z) < BAIL_OUT; n ++) z = cpow(z, 2) + c; C = n - log2f(logf(cabs(z)) / M_LN2 ); /* Paint the pixel calculated depending on the number of iterations found */ ((Uint32*)surface->pixels)[(y*surface->w) + x] = (n >= maxiter)? 0 : SDL_MapRGB( surface->format, (1+sin(C*0.27 + 5))*127., (1+cos(C*0.85))*127., (1+sin(C*0.15))*127. ); } rects[y/FLIPS].x = 0; rects[y/FLIPS].y = y; rects[y/FLIPS].w = WIDTH; rects[y/FLIPS].h = 1; } SDL_UpdateRects(surface, HEIGHT/FLIPS, rects); } }
void drawInstructions(struct game *g) { SDL_Rect r; struct position *p = g->frontend; r.x = p->x2; r.y = p->y2 + p->size * PREVIEW_H + 60; char instMsg[1024]; sprintf(instMsg,"\nCopypastris\nby Christiaan Janssen\nRemixed from sdltetris (sourceforge)\nBerlin 5h microJam 2012\n\nInstructions:\nMouse: select on click\nCTRL+X: cut\nCTRL+C: copy\nCTRL+V: paste"); sf_puts(screen, &r, instMsg); SDL_UpdateRects(screen, 1, &r); }
static mrb_value mrb_sdl_video_update_rects (mrb_state *mrb, mrb_value self) { mrb_value surface = mrb_nil_value(); mrb_int num; mrb_value rects = mrb_nil_value(); mrb_get_args(mrb, "|o", &surface); mrb_get_args(mrb, "|i", &num); mrb_get_args(mrb, "|o", &rects); SDL_UpdateRects(mrb_value_to_sdl_surface(mrb, surface), num, mrb_value_to_sdl_rect(mrb, rects)); return mrb_nil_value(); }
static void DrawSurfaceToScreen() { int n = _num_dirty_rects; if (n == 0) return; _num_dirty_rects = 0; if (n > MAX_DIRTY_RECTS) { SDL_CALL SDL_UpdateRect(_sdl_screen, 0, 0, 0, 0); } else { SDL_CALL SDL_UpdateRects(_sdl_screen, n, _dirty_rects); } }