CMessageBoxBitmapGalaxy.cpp 1.45 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * CMessageBoxBitmapGalaxy.cpp
 *
 *  Created on: 04.05.2011
 *      Author: gerstrong
 */

#include "CMessageBoxBitmapGalaxy.h"
Gerhard Stein's avatar
Gerhard Stein committed
9
#include <base/video/CVideoDriver.h>
10
#include "sdl/extensions.h"
11

12
const int FONT_ID = 0;
13

14
CMessageBoxBitmapGalaxy::CMessageBoxBitmapGalaxy( const std::string& Text,
15
														 const GsBitmap &BitmapRef,
16 17
														 const direction_t alignment ) :
CMessageBoxGalaxy(Text),
18
mBitmap(BitmapRef),
19
mAlignment(alignment)
20
{
Gerhard Stein's avatar
Gerhard Stein committed
21
    GsRect<Uint16> gameRes = gVideoDriver.getGameResolution();
22

23
	// Looking if the Bitmap is too big for the Message box. In that case enlarge it!
24
	if( (mBitmap.getHeight()+26) > mMBRect.h )
25
	{
26
		mMBRect.h = mBitmap.getHeight()+26;
27 28
	}

29
	mMBRect.w += (mBitmap.getWidth()+32);
30

31 32
    mMBRect.x = (gameRes.w-mMBRect.w)/2;
    mMBRect.y = (gameRes.h-mMBRect.h)/2;
33

34
	mpMBSurface.reset(CG_CreateRGBSurface( mMBRect ), &SDL_FreeSurface);
Gerhard Stein's avatar
Gerhard Stein committed
35
//#if SDL_VERSION_ATLEAST(2, 0, 0)
Chad Anderson's avatar
Chad Anderson committed
36
    
Gerhard Stein's avatar
Gerhard Stein committed
37
//#else
Gerhard Stein's avatar
Gerhard Stein committed
38
    mpMBSurface.reset(gVideoDriver.convertThroughBlitSfc( mpMBSurface.get() ), &SDL_FreeSurface);
Gerhard Stein's avatar
Gerhard Stein committed
39
//#endif
40 41
}

42
void CMessageBoxBitmapGalaxy::init()
43
{
44 45 46 47 48
	initGalaxyFrame();

	SDL_Rect rect = mMBRect;

	rect.x = 16;
49

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

54 55 56
	rect.w -= 16;
	rect.h -= 8;
	rect.y = (rect.h-mTextHeight)/2;
57

58
	initText(rect);
59

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

62
    mBitmap._draw( bmpX, 10, mpMBSurface.get() );
63
}