void CSprite::generateSprite( const int points ) { Uint32 color = 0; Uint8 r,g,b,a; std::string pointStr = itoa(points); setSize( pointStr.size()*8, 8); createSurface( g_pVideoDriver->mp_VideoEngine->getBlitSurface()->flags, g_pGfxEngine->Palette.m_Palette ); optimizeSurface(); SDL_FillRect(mpSurface.get(), NULL, 0xFFFFFFFF); CFont &smallFont = g_pGfxEngine->getFont(2); // Create Text Borders TODO: Make this code to draw better looking fonts smallFont.drawFont( mpSurface.get(), pointStr, -1, 0 ); smallFont.drawFont( mpSurface.get(), pointStr, 0, -1 ); smallFont.drawFont( mpSurface.get(), pointStr, 1, 0 ); smallFont.drawFont( mpSurface.get(), pointStr, 0, 1 ); // Now draw the alternate font. It just has another color. smallFont.drawFont( mpSurface.get(), pointStr, 0, 0, true ); if(SDL_MUSTLOCK(mpSurface.get())) SDL_LockSurface(mpSurface.get()); // This makes the white pixel transparent TODO: This and other must get more elegant Uint8 *pixel = (Uint8*)mpSurface->pixels; for( Uint8 y=0 ; y<mpSurface->h ; y++ ) { for( Uint8 x=0 ; x<mpSurface->w ; x++ ) { memcpy( &color, pixel, mpSurface->format->BytesPerPixel ); SDL_GetRGBA( color, mpSurface->format, &r, &g, &b, &a ); if( color == 0xFFFFFFFF ) // White a = 0; color = SDL_MapRGBA( mpSurface->format, r, g, b, a ); memcpy( pixel, &color, mpSurface->format->BytesPerPixel ); pixel += mpSurface->format->BytesPerPixel; } } if(SDL_MUSTLOCK(mpSurface.get())) SDL_LockSurface(mpSurface.get()); m_bboxX1=0; m_bboxY1=0; m_bboxX2=getWidth(); m_bboxY2=getHeight(); }
bool GsBitmap::scaleTo(const GsRect<Uint16> &destRes) { SDL_Rect newRect = destRes.SDLRect(); // Need to do that, otherwise it won't work. optimizeSurface(); if(newRect.w == mpBitmapSurface->w && newRect.h == mpBitmapSurface->h) return true; std::shared_ptr<SDL_Surface> newSfc; auto bmpSfc = mpBitmapSurface.get(); auto bmpFormat = bmpSfc->format; newSfc.reset( SDL_CreateRGBSurface(bmpSfc->flags, newRect.w, newRect.h, bmpFormat->BitsPerPixel, bmpFormat->Rmask, bmpFormat->Gmask, bmpFormat->Bmask, bmpFormat->Amask ), &SDL_FreeSurface ); if(!newSfc) return false; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_BlendMode blendMode; SDL_GetSurfaceBlendMode(bmpSfc, &blendMode); SDL_SetSurfaceBlendMode(newSfc.get(), blendMode); #endif CVidConfig &vidConf = gVideoDriver.getVidConfig(); blitScaled(bmpSfc, bmpSfc->clip_rect, newSfc.get(), newRect, vidConf.m_ScaleXFilter); mpBitmapSurface = newSfc; return true; }