Commit 32de353e authored by Gerhard Stein's avatar Gerhard Stein

Cleanups and HUD fixes in Galaxy

parent 27c9722d
......@@ -46,6 +46,25 @@ const std::list<std::string> filledStrList( const size_t amount, const char *fir
}
/**
* Returns of a given string the number of lines
*/
unsigned int calcNumLines(const std::string& text)
{
unsigned int numLines = 1;
if(text.size() == 0)
return 0;
for( unsigned int i=0 ; i<text.size() ; i++ )
{
if ( endofText( text.substr(i) ) )
numLines++;
}
return numLines;
}
/**
* Formats a string they way it looks like it's right aligned
*/
......
......@@ -114,6 +114,7 @@ inline char* itoa(int val, char* buf, int base) {
// HINT: use these where possible
const std::list<std::string> filledStrList( const size_t amount, const char *first, ... );
unsigned int calcNumLines(const std::string& text);
std::string getRightAlignedString(std::string text, size_t size);
bool endofText(const std::string& Text);
void TrimSpaces(std::string& szLine);
......
......@@ -27,6 +27,14 @@ m_charges(charges)
if( Episode>=1 && Episode<=3 )
CreateBackground();
else
{
CSprite &HUDBox = g_pGfxEngine->getSprite(129);
m_Rect.h = HUDBox.getHeight()+2;
m_Rect.w = HUDBox.getWidth()+2;
mpHUDBlit = CG_CreateRGBSurface( m_Rect );
mpHUDBlit = SDL_DisplayFormatAlpha( mpHUDBlit.get() );
}
}
/**
......@@ -144,15 +152,15 @@ void CHUD::renderGalaxy()
lives = (m_lives<99) ? m_lives : 99;
charges = (m_charges<99) ? m_charges : 99;
// Draw the background
// Draw the HUD with all the digits
SDL_Surface* blitsfc = mpHUDBlit.get();
CSprite &HUDBox = g_pGfxEngine->getSprite(129);
HUDBox.drawSprite( m_Rect.x, m_Rect.y);
SDL_Surface* blitsfc = g_pVideoDriver->getBlitSurface();
HUDBox._drawSprite( blitsfc, m_Rect.x, m_Rect.y );
g_pGfxEngine->drawDigits(getRightAlignedString(itoa(score),9), m_Rect.x+8, m_Rect.y+4, blitsfc );
g_pGfxEngine->drawDigits(getRightAlignedString(itoa(charges),2), m_Rect.x+64, m_Rect.y+20, blitsfc );
g_pGfxEngine->drawDigits(getRightAlignedString(itoa(lives),2), m_Rect.x+24, m_Rect.y+20, blitsfc );
g_pVideoDriver->mDrawTasks.add( new BlitSurfaceTask( mpHUDBlit, NULL, &m_Rect ) );
}
/**
* \brief This part of the code will render the entire HUD. Vorticon version
......@@ -166,7 +174,6 @@ void CHUD::renderVorticon()
charges = (m_charges<99) ? m_charges : 99;
// Draw the background
g_pVideoDriver->mDrawTasks.add( new BlitSurfaceTask( mpBackground, NULL, &m_Rect ) );
SDL_BlitSurface(mpBackground.get(), NULL, mpHUDBlit.get(), NULL );
CFont &Font = g_pGfxEngine->getFont(1);
......@@ -182,7 +189,6 @@ void CHUD::renderVorticon()
//Font.setFGColour(blitsurface->format, 0x0);
// Draw the background
g_pVideoDriver->mDrawTasks.add( new BlitSurfaceTask( mpHUDBlit, NULL, &m_Rect ) );
}
......
......@@ -8,7 +8,8 @@
#include "CDlgFrame.h"
#include "graphics/CGfxEngine.h"
CDlgFrame::CDlgFrame(int x, int y, int w, int h, int tilewidth, int tileheight) {
CDlgFrame::CDlgFrame(int x, int y, int w, int h, int tilewidth, int tileheight)
{
m_8x8tileheight = tilewidth;
m_8x8tilewidth = tileheight;
......@@ -35,7 +36,7 @@ void CDlgFrame::draw(SDL_Surface *dst)
}
else if(m_theme == ENGINE_GALAXY )
{
drawGalaxyFrame(dst);
//drawGalaxyFrame(dst);
}
}
......@@ -90,47 +91,6 @@ void CDlgFrame::drawVorticonFrame(SDL_Surface *dst)
Font.drawCharacter(dst, 8, m_w - m_8x8tilewidth, m_h - m_8x8tileheight ); // Lower-Right corner
}
void CDlgFrame::drawGalaxyFrame(SDL_Surface *dst)
{
// first draw the blank rect
SDL_Rect rect;
rect.x = m_x + m_8x8tilewidth;
rect.y = m_y + m_8x8tileheight;
rect.w = m_w - m_8x8tilewidth*2;
rect.h = m_h - m_8x8tileheight*2;
SDL_FillRect(dst, &rect, 0xFFFFFF);
CTilemap &Tilemap = g_pGfxEngine->getTileMap(3);
/// Now draw the borders
// Upper Left corner
Tilemap.drawTile(dst, m_x, m_y, 0);
// Upper border
for(int x=m_8x8tilewidth ; x<(m_w-m_8x8tilewidth) ; x+=m_8x8tilewidth)
Tilemap.drawTile(dst, m_x+x, m_y, 1);
// Upper Right corner
Tilemap.drawTile(dst, m_x+m_w-m_8x8tilewidth, m_y, 2);
// Left border
for(int y=m_8x8tileheight ; y<(m_h-m_8x8tileheight) ; y+=m_8x8tileheight)
Tilemap.drawTile(dst, m_x, m_y+y, 3);
// Right border
for(int y=m_8x8tileheight ; y<(m_h-m_8x8tileheight) ; y+=m_8x8tileheight)
Tilemap.drawTile(dst, m_x+m_w-m_8x8tilewidth, m_y+y, 5);
// Lower Left corner
Tilemap.drawTile(dst, m_x, m_y+m_h-m_8x8tileheight, 6);
// Lower border
for(int x=m_8x8tilewidth ; x<(m_w-m_8x8tilewidth) ; x+=m_8x8tilewidth)
Tilemap.drawTile(dst, m_x+x, m_y+m_h-m_8x8tileheight, 7);
// Lower Right corner
Tilemap.drawTile(dst, m_x+m_w-m_8x8tilewidth, m_y+m_h-m_8x8tileheight, 8);
}
......@@ -34,6 +34,7 @@ class CMessageBox : public CGUIDialog
public:
// Init functions
CMessageBox(const std::string& Text, bool lower, bool keymsg, bool leftbound);
virtual ~CMessageBox() {}
/** Processing
* There are dialog boxes in both engines. They have are different and must be overloaded with this function.
......
......@@ -143,7 +143,7 @@ void CPlayGameGalaxy::process()
CMessageBoxGalaxy *pMB = mMessageBoxes.front().get();
pMB->process();
if(pMB->m_mustclose)
if(pMB->isFinished())
{
mMessageBoxes.pop_front();
}
......@@ -192,6 +192,7 @@ void CPlayGameGalaxy::process()
if( EventSendBitmapDialogMsg* ev = EventContainer.occurredEvent<EventSendBitmapDialogMsg>() )
{
CMessageBoxBitmapGalaxy *pMsgBox = new CMessageBoxBitmapGalaxy( ev->Msg, ev->BitmapID, ev->Direction );
pMsgBox->init();
//CMessageBoxGalaxy *pMsgBox = new CMessageBoxGalaxy( ev->Msg );
mMessageBoxes.push_back( pMsgBox );
......
......@@ -7,55 +7,51 @@
#include "CMessageBoxBitmapGalaxy.h"
#include "sdl/CVideoDriver.h"
#include "sdl/extensions.h"
const int FONT_ID = 0;
CMessageBoxBitmapGalaxy::CMessageBoxBitmapGalaxy( const std::string& Text, const Uint16 BitmapId,
const direction_t alignment ) :
CMessageBoxGalaxy(Text)//,
//m_Bitmap(g_pGfxEngine->getBitmap(BitmapId)),
//m_alignment(alignment)
CMessageBoxBitmapGalaxy::CMessageBoxBitmapGalaxy( const std::string& Text,
const Uint16 BitmapId,
const direction_t alignment ) :
CMessageBoxGalaxy(Text),
mBitmap(g_pGfxEngine->getBitmap(BitmapId)),
mAlignment(alignment)
{
/*int new_height = m_boxrect.h;
// Looking if the Bitmap is too big for the Message box. In that case enlarge it!
if( m_Bitmap.getHeight() > m_boxrect.h )
if( (mBitmap.getHeight()+26) > mMBRect.h )
{
new_height = m_Bitmap.getHeight();
mMBRect.h = mBitmap.getHeight()+26;
}
if( m_alignment == RIGHT )
m_TextPos.x = 10;
else
m_TextPos.x = 10+m_Bitmap.getWidth();
mMBRect.w += (mBitmap.getWidth()+32);
// I think this depends on the font height itself. I don't get why 6 is correct here.
m_TextPos.y = ( (new_height+16)/2 ) - 6*m_Lines.size();
mMBRect.x = (320-mMBRect.w)/2;
mMBRect.y = (200-mMBRect.h)/2;
// Resize
mp_DlgFrame->resize(m_boxrect.w+m_Bitmap.getWidth()+2, new_height+16);
mpMBSurface = CG_CreateRGBSurface( mMBRect );
mpMBSurface = SDL_DisplayFormatAlpha( mpMBSurface.get() );
// Now calculate new coordinates and remove the box
SDL_Rect gamerect = g_pVideoDriver->getGameResolution().SDLRect();
m_boxrect.x = (gamerect.w - mp_DlgFrame->m_w)/2;
m_boxrect.y = (gamerect.h - mp_DlgFrame->m_h)/2;
mp_DlgFrame->setPos(m_boxrect.x, m_boxrect.y);
*/
}
void CMessageBoxBitmapGalaxy::process()
void CMessageBoxBitmapGalaxy::init()
{
CMessageBoxGalaxy::process();
initGalaxyFrame();
SDL_Rect rect = mMBRect;
rect.x = 16;
//int bitmap_xcoord;
// Move text to the right if bitmap is on the left side
if( mAlignment == LEFT )
rect.x += mBitmap.getWidth();
// now compute where the bitmap is to be drawn
/*if( m_alignment == RIGHT )
bitmap_xcoord = mp_DlgFrame->m_x+mp_DlgFrame->m_w-(m_Bitmap.getWidth()+8);
else
bitmap_xcoord = m_boxrect.x+8;
rect.w -= 16;
rect.h -= 8;
rect.y = (rect.h-mTextHeight)/2;
SDL_Surface *sfc = g_pVideoDriver->mp_VideoEngine->getBlitSurface();
initText(rect);
m_Bitmap.draw( sfc,bitmap_xcoord, m_boxrect.y+8 );*/
mBitmap._draw( mpMBSurface.get(), 10, 10 );
}
......@@ -25,14 +25,11 @@ public:
const direction_t alignment = LEFT );
virtual ~CMessageBoxBitmapGalaxy() {};
/**
* \brief the cycle to be processed for rendering the Message-Box
*/
void process();
virtual void init();
private:
//CBitmap &m_Bitmap;
//const direction_t m_alignment;
CBitmap &mBitmap;
const direction_t mAlignment;
};
#endif /* CMESSAGEBOXBITMAPGALAXY_H_ */
......@@ -11,62 +11,122 @@
#include "sdl/CVideoDriver.h"
#include "sdl/input/CInput.h"
#include "graphics/CGfxEngine.h"
#include "sdl/extensions.h"
const int FONT_ID = 0;
CMessageBoxGalaxy::CMessageBoxGalaxy(const std::string& Text) /*:
CMessageBox(Text, false, false, false)*/
CMessageBoxGalaxy::CMessageBoxGalaxy(const std::string& Text) :
mMustClose(false),
mText(Text)
{
// Center that dialog box
/*CFont &Font = g_pGfxEngine->getFont(FONT_ID);
m_boxrect = g_pVideoDriver->getGameResolution().SDLRect();
CFont &Font = g_pGfxEngine->getFont(FONT_ID);
m_boxrect.x = m_boxrect.w/2;
m_boxrect.y = m_boxrect.h/2;
mTextHeight = Font.getPixelTextHeight()*calcNumLines(mText);
int width = 0;
for( size_t i=0 ; i<m_Lines.size() ; i++)
{
const int newwidth = Font.getPixelTextWidth(m_Lines[i]);
if( width < newwidth )
width = newwidth;
}
width += 16;
// Create a surface for that
mMBRect.w = Font.getPixelTextWidth(mText)+16;
mMBRect.h = Font.getPixelTextHeight()*(calcNumLines(mText)+1)+16;
mMBRect.x = (320-mMBRect.w)/2;
mMBRect.y = (200-mMBRect.h)/2;
m_text_height = Font.getPixelTextHeight();
m_boxrect.h = (m_text_height+2)*m_Lines.size()+16;
m_boxrect.w = width;
mpMBSurface = CG_CreateRGBSurface( mMBRect );
mpMBSurface = SDL_DisplayFormatAlpha( mpMBSurface.get() );
}
m_boxrect.x -= m_boxrect.w/2;
m_boxrect.y -= m_boxrect.h/2;
void CMessageBoxGalaxy::init()
{
initGalaxyFrame();
mp_DlgFrame = new CDlgFrame(m_boxrect.x, m_boxrect.y,
m_boxrect.w, m_boxrect.h, DLG_THEME_GALAXY);
SDL_Rect rect = mMBRect;
rect.x = 8;
rect.y = 8;
rect.w -= 16;
rect.h -= 16;
m_TextPos.x = 8;
m_TextPos.y = 8;*/
initText(rect);
}
void CMessageBoxGalaxy::process()
void CMessageBoxGalaxy::initGalaxyFrame()
{
//SDL_Surface *sfc = g_pVideoDriver->mp_VideoEngine->getBlitSurface();
SDL_Surface *dst = mpMBSurface.get();
// Look, if somebody pressed a button, and close this dialog!
if(g_pInput->getPressedAnyCommand())
{
m_mustclose = true;
return;
}
// first draw a blank rect
SDL_Rect rect;
rect.x = 4;
rect.y = 4;
rect.w = mMBRect.w-16;
rect.h = mMBRect.h-16;
SDL_FillRect(dst, &rect, 0xFFFFFFFF);
// Draw the borders
rect = mMBRect;
rect.x += 8;
rect.y += 8;
rect.w -= 16;
rect.h -= 16;
CTilemap &Tilemap = g_pGfxEngine->getTileMap(3);
/// Now draw the borders
// Upper Left corner
Tilemap.drawTile(dst, 0, 0, 0);
// Upper border
for(int x=8 ; x<rect.w ; x+=8)
Tilemap.drawTile(dst, x, 0, 1);
// Upper Right corner
Tilemap.drawTile(dst, rect.w, 0, 2);
// Left border
for(int y=8 ; y<rect.h ; y+=8)
Tilemap.drawTile(dst, 0, y, 3);
// Right border
for(int y=8 ; y<rect.h ; y+=8)
Tilemap.drawTile(dst, rect.w, y, 5);
// Lower Left corner
Tilemap.drawTile(dst, 0, rect.h, 6);
// Draw the empty Dialog Box
/*mp_DlgFrame->draw(sfc);
// Lower border
for(int x=8 ; x<rect.w ; x+=8)
Tilemap.drawTile(dst, x, rect.h, 7);
// Lower Right corner
Tilemap.drawTile(dst, rect.w, rect.h, 8);
}
void CMessageBoxGalaxy::initText(const SDL_Rect &rect)
{
CFont &Font = g_pGfxEngine->getFont(FONT_ID);
// Set the proper Font colors
//g_pGfxEngine->getFont(FONT_ID).setBGColour(sfc->format, 0xFFFFFFFF);
//g_pGfxEngine->getFont(FONT_ID).setFGColour(sfc->format, 0xFF000000);
// Draw the Text on our surface
for( size_t i=0 ; i<m_Lines.size() ; i++)
/*for( size_t i=0 ; i<m_Lines.size() ; i++)
g_pGfxEngine->getFont(FONT_ID).drawFont(sfc, m_Lines[i], m_boxrect.x+m_TextPos.x, m_boxrect.y+(i*m_text_height+m_TextPos.y) );*/
//Font.drawFont(mpMBSurface.get(), mText, rect.x, rect.y);
//Font.drawFont(mpMBSurface.get(), "Loading!", 16, 16);
SDL_PixelFormat *format = g_pVideoDriver->getBlitSurface()->format;
SmartPointer<SDL_Surface> pTextSfc = Font.fetchColoredTextSfc( mText, SDL_MapRGB( format, 0, 0, 0 ) );
SDL_BlitSurface(pTextSfc.get(), NULL, mpMBSurface.get(), const_cast<SDL_Rect*>(&rect));
}
void CMessageBoxGalaxy::process()
{
// Look, if somebody pressed a button, and close this dialog!
if(g_pInput->getPressedAnyCommand())
{
mMustClose = true;
return;
}
g_pVideoDriver->mDrawTasks.add( new BlitSurfaceTask( mpMBSurface, NULL, &mMBRect ) );
}
......@@ -8,10 +8,12 @@
#ifndef CMESSAGEBOXGALAXY_H_
#define CMESSAGEBOXGALAXY_H_
#include "dialog/CMessageBox.h"
#include "CVec.h"
#include <string>
#include <SDL.h>
#include "SmartPointer.h"
class CMessageBoxGalaxy //: public CMessageBox
class CMessageBoxGalaxy
{
public:
......@@ -22,13 +24,25 @@ public:
CMessageBoxGalaxy(const std::string& Text);
virtual ~CMessageBoxGalaxy() {};
virtual void init();
virtual void process();
bool m_mustclose;
const bool isFinished() const
{ return mMustClose; }
protected:
SDL_Rect m_TextPos;
void initGalaxyFrame();
void initText(const SDL_Rect &rect);
bool mMustClose;
SDL_Rect mMBRect;
std::string mText;
SmartPointer<SDL_Surface> mpMBSurface;
unsigned int mTextHeight;
};
#endif /* CMESSAGEBOXGALAXY_H_ */
......@@ -136,7 +136,7 @@ SDL_Surface* CFont::fetchColoredTextSfc(const std::string& text, const Uint32 fg
SDL_Rect rect;
rect.x = rect.y = 0;
rect.w = getPixelTextWidth(text);
rect.h = getPixelTextHeight();
rect.h = getPixelTextHeight()*calcNumLines(text);
SDL_Surface *pColoredTextSurface = CG_CreateRGBSurface(rect);
......@@ -152,10 +152,6 @@ SDL_Surface* CFont::fetchColoredTextSfc(const std::string& text, const Uint32 fg
drawFont( pColoredTextSurface, text, 0, 0);
// Change palette colors back to the white one
//SDL_GetRGB(0xFFFFFF, pPixelformat, &pColor[15].r, &pColor[15].g, &pColor[15].b);
//SDL_SetColors( mFontSurface, pColor, 0, 16);
// Adapt the newly created surface to the running screen.
SDL_Surface *temp = SDL_DisplayFormatAlpha(pColoredTextSurface);
SDL_FreeSurface(pColoredTextSurface);
......@@ -170,12 +166,25 @@ SDL_Surface* CFont::fetchColoredTextSfc(const std::string& text, const Uint32 fg
unsigned int CFont::getPixelTextWidth( const std::string& text )
{
unsigned int c = 0, width = 0;
unsigned int c = 0, width = 0, len = 0;
for( ; c<text.size() ; c++)
{
const int e = text[c];
width += (mWidthtable[e]+1);
if ( endofText( text.substr(c) ) )
{
if(len > width)
width = len;
len = 0;
}
else
{
const int e = text[c];
len += (mWidthtable[e]+1);
}
}
if(len > width)
width = len;
return width;
}
......@@ -268,7 +277,7 @@ void CFont::drawFontCentered(SDL_Surface* dst, const std::string& text, Uint16 x
Uint16 xmidpos = 0;
for( unsigned int i=0 ; i<text.size() ; i++)
xmidpos += mWidthtable[text[i]];
xmidpos += mWidthtable[ static_cast<unsigned int>(text[i]) ];
xmidpos = (width-xmidpos)/2+x;
......@@ -281,7 +290,7 @@ void CFont::drawFontCentered(SDL_Surface* dst, const std::string& text, Uint16 x
Uint16 ymidpos = 0;
for( unsigned int i=0 ; i<text.size() ; i++)
xmidpos += mWidthtable[text[i]];
xmidpos += mWidthtable[ static_cast<unsigned int>(text[i]) ];
xmidpos = (width-xmidpos)/2+x;
ymidpos = yoff + (height - 8)/2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment