void CMessageBoxBitmapGalaxy::init()
{
	initGalaxyFrame();

	SDL_Rect rect = mMBRect;

	rect.x = 16;

	// Move text to the right if bitmap is on the left side
	if( mAlignment == LEFT )
		rect.x += mBitmap.getWidth();

	rect.w -= 16;
	rect.h -= 8;
	rect.y = (rect.h-mTextHeight)/2;

	initText(rect);

	const Uint16 bmpX = ( mAlignment == LEFT ) ? 10 : mMBRect.w-(mBitmap.getWidth()+32);


	mBitmap._draw( mpMBSurface.get(), bmpX, 10 );
}
Ejemplo n.º 2
0
void CMessageBoxSelection::init()
{
    mpMBSurface.reset(CG_CreateRGBSurface( mMBRect ), &SDL_FreeSurface);
    mpMBSurface.reset(gVideoDriver.convertThroughBlitSfc( mpMBSurface.get() ), &SDL_FreeSurface);

	initGalaxyFrame();

	SDL_Rect rect = mMBRect;
	rect.x = 8;
	rect.y = 10;
	rect.w -= 16;
	rect.h -= 16;
    
	GsFont &Font = gGraphics.getFont(FONT_ID);

	SDL_PixelFormat *format = gVideoDriver.getBlitSurface()->format;
	
	SDL_Surface *pColoredTextSurface = CG_CreateRGBSurface(rect);

	const Uint32 oldColor = Font.getFGColor();

	Font.setupColor( SDL_MapRGB( format, 0, 0, 0 ) );

	auto textList = explode(mText, "\n");
	
	int yoff = 0;
	for( auto &it : textList  )
	{	    
	    int xmid = (rect.w-Font.getPixelTextWidth(it))/2+rect.x;
	    Font.drawFont( pColoredTextSurface, it, xmid, yoff);
	    yoff += 12;
	}	

	// Adapt the newly created surface to the running screen.
	SDL_Surface *temp;


    if(RES_BPP == 32) // Only if there is an Alpha Channel (32 BPP)
        temp = gVideoDriver.convertThroughBlitSfc(pColoredTextSurface);
	else // or
        temp = gVideoDriver.convertThroughBlitSfc(pColoredTextSurface);

	SDL_FreeSurface(pColoredTextSurface);
	pColoredTextSurface = temp;

	Font.setupColor( oldColor );

	std::unique_ptr<SDL_Surface,SDL_Surface_Deleter> pTextSfc(pColoredTextSurface);			
	SDL_BlitSurface(pTextSfc.get(), NULL, mpMBSurface.get(), const_cast<SDL_Rect*>(&rect));
	
	
	// Create the Border and with two Surfaces of different colors create the rectangle
	SDL_Rect selRect;
	SDL_Rect cutRect;
	selRect.x = selRect.y = 0;
	selRect.w = rect.w-rect.x;
	selRect.h = 14;
	cutRect = selRect;
	cutRect.x += 2;
	cutRect.y += 2;
	cutRect.w -= 4;
	cutRect.h -= 4;
		
    mpSelSurface1.reset( SDL_CreateRGBSurface( SDL_SWSURFACE,
                                               selRect.w,
                                               selRect.h,
                                               RES_BPP,
                                               format->Rmask,
                                               format->Gmask,
                                               format->Bmask,
                                               0 ),
                         &SDL_FreeSurface);

    mpSelSurface2.reset( SDL_CreateRGBSurface( SDL_SWSURFACE,
                                               selRect.w,
                                               selRect.h,
                                               RES_BPP,
                                               format->Rmask,
                                               format->Gmask,
                                               format->Bmask,
                                               0 ),
                         &SDL_FreeSurface);

	SDL_FillRect( mpSelSurface1.get(), &selRect, SDL_MapRGB( format, 255, 0, 0 ) );
	SDL_FillRect( mpSelSurface2.get(), &selRect, SDL_MapRGB( format, 0, 0, 255 ) );
#if SDL_VERSION_ATLEAST(2, 0, 0)
    SDL_SetColorKey(mpSelSurface1.get(), SDL_TRUE, SDL_MapRGB( format, 0, 0, 0 ));
    SDL_SetColorKey(mpSelSurface2.get(), SDL_TRUE, SDL_MapRGB( format, 0, 0, 0 ));    
    SDL_SetSurfaceBlendMode(mpSelSurface1.get(), SDL_BLENDMODE_BLEND);
    SDL_SetSurfaceBlendMode(mpSelSurface2.get(), SDL_BLENDMODE_BLEND);
#else
    SDL_SetColorKey( mpSelSurface1.get(), SDL_SRCCOLORKEY, SDL_MapRGB( format, 0, 0, 0 ) );
    SDL_SetColorKey( mpSelSurface2.get(), SDL_SRCCOLORKEY, SDL_MapRGB( format, 0, 0, 0 ) );
#endif
	SDL_FillRect( mpSelSurface1.get(), &cutRect, SDL_MapRGB( format, 0, 0, 0 ) );
	SDL_FillRect( mpSelSurface2.get(), &cutRect, SDL_MapRGB( format, 0, 0, 0 ) );
}