Commit dd79c391 authored by Gerhard Stein's avatar Gerhard Stein

Cleanups and more SmartPointers

parent 8c449d3f
......@@ -21,14 +21,6 @@
#include <vector>
// Holder for some tile that have to be drawn
struct TileHolder
{
Uint16 tile;
Uint16 x;
Uint16 y;
};
class CMessageBox : public CGUIDialog
{
public:
......
......@@ -9,6 +9,8 @@
#include "sdl/CVideoDriver.h"
#include "sdl/input/CInput.h"
#include "graphics/CGfxEngine.h"
#include "sdl/extensions.h"
#include "gui/CGUIBitmap.h"
CMessageBoxVort::CMessageBoxVort(const std::string& Text, bool lower, bool keymsg, bool leftbound) :
CMessageBox(Text, lower, keymsg, leftbound)
......@@ -18,15 +20,31 @@ CMessageBox(Text, lower, keymsg, leftbound)
// This special Messagebox can hold up to 4 images
void CMessageBoxVort::addTileAt(Uint16 tile, Uint16 x, Uint16 y)
{
TileHolder tileholder;
CTilemap &tilemap = g_pGfxEngine->getTileMap(1);
tileholder.tile = tile;
tileholder.x = x;
tileholder.y = y;
const int tileDim = tilemap.getDimension();
m_Tiles.push_back(tileholder);
// now we'll create a new surface on which the Tile will be printed.
SDL_Rect rect;
rect.x = rect.y = 0;
rect.w = rect.h = tileDim;
SmartPointer<SDL_Surface> bmpSfc = CG_CreateRGBSurface(rect);
// new CGUIImage(...); // TODO...
tilemap.drawTile(bmpSfc.get(), 0, 0, tile);
//addControl( mpTextCtrl, TextRect );
SDL_FillRect(bmpSfc.get(), NULL, 0x0000FF00);
rect.x = x; rect.y = y;
/*CRect<float> fRect( x, y, 16.0f, 16.0f);
CRect<float> gameRect = g_pVideoDriver->getGameResolution();
fRect.transformInverse(gameRect);
fRect.transform(mRect);*/
CRect<float> fRect( 0.0f, 0.0f, 1.0f, 1.0f);
SmartPointer<CBitmap> pBitmap = new CBitmap(bmpSfc);
addControl( new CGUIBitmap(pBitmap), fRect );
}
......@@ -21,8 +21,6 @@ public:
*/
void addTileAt(Uint16 tile, Uint16 x, Uint16 y);
private:
std::vector<TileHolder> m_Tiles;
};
#endif /* CMESSAGEBOXVORT_H_ */
......@@ -11,20 +11,21 @@
#include "sdl/CVideoDriver.h"
CBitmap::CBitmap()
{}
CBitmap::CBitmap(const SmartPointer<SDL_Surface> &bmpSfc)
{
m_BitmapSurface = NULL;
m_name = "";
mpBitmapSurface = bmpSfc;
}
CBitmap::CBitmap(const CBitmap &bitmap) :
m_ImageRect(bitmap.getRect()),
m_name(bitmap.getName()),
m_BitmapSurface(NULL)
mImageRect(bitmap.getRect()),
mName(bitmap.getName())
{
//SDL_Surface *sfc = const_cast<SDL_Surface*>(bitmap.getSDLSurface());
SDL_Surface *sfc = bitmap.getSDLSurface();
if( sfc != NULL )
m_BitmapSurface = SDL_DisplayFormat( sfc );
mpBitmapSurface = SDL_DisplayFormat( sfc );
}
///
......@@ -32,22 +33,19 @@ m_BitmapSurface(NULL)
///
bool CBitmap::createSurface(Uint32 flags, SDL_Color *Palette)
{
if(m_BitmapSurface) SDL_FreeSurface(m_BitmapSurface);
m_BitmapSurface = SDL_CreateRGBSurface(flags, m_ImageRect.w, m_ImageRect.h, 8, 0, 0, 0, 0);
SDL_SetColors(m_BitmapSurface, Palette, 0, 255);
SDL_SetColorKey(m_BitmapSurface, SDL_SRCCOLORKEY, COLORKEY);
return (m_BitmapSurface != NULL);
mpBitmapSurface = SDL_CreateRGBSurface(flags, mImageRect.w, mImageRect.h, 8, 0, 0, 0, 0);
SDL_SetColors(mpBitmapSurface.get(), Palette, 0, 255);
SDL_SetColorKey(mpBitmapSurface.get(), SDL_SRCCOLORKEY, COLORKEY);
return (!mpBitmapSurface.empty());
}
bool CBitmap::optimizeSurface()
{
if(m_BitmapSurface)
if(!mpBitmapSurface.empty())
{
SDL_Surface *temp_surface;
temp_surface = SDL_DisplayFormat(m_BitmapSurface);
SDL_FreeSurface(m_BitmapSurface);
m_BitmapSurface = temp_surface;
temp_surface = SDL_DisplayFormat(mpBitmapSurface.get());
mpBitmapSurface = temp_surface;
return true;
}
else
......@@ -59,15 +57,15 @@ bool CBitmap::loadHQBitmap( const std::string& filename )
if(!IsFileAvailable(filename))
return false;
if(m_BitmapSurface)
if(!mpBitmapSurface.empty())
{
SDL_Surface *temp_surface = SDL_LoadBMP(GetFullFileName(filename).c_str());
if(temp_surface)
SDL_Surface *tempSurface = SDL_LoadBMP(GetFullFileName(filename).c_str());
if(tempSurface)
{
SDL_Surface *displaysurface = SDL_ConvertSurface(temp_surface, m_BitmapSurface->format, m_BitmapSurface->flags);
SDL_BlitSurface(displaysurface, NULL, m_BitmapSurface, NULL);
SDL_Surface *displaysurface = SDL_ConvertSurface(tempSurface, mpBitmapSurface->format, mpBitmapSurface->flags);
SDL_BlitSurface(displaysurface, NULL, mpBitmapSurface.get(), NULL);
SDL_FreeSurface(displaysurface);
SDL_FreeSurface(temp_surface);
SDL_FreeSurface(tempSurface);
return true;
}
}
......@@ -77,20 +75,17 @@ bool CBitmap::loadHQBitmap( const std::string& filename )
///
// Getters and Setters
///
/*SDL_Surface *CBitmap::getSDLSurface()
{
return m_BitmapSurface;
}*/
void CBitmap::setDimensions(const Uint16 w, const Uint16 h)
{
m_ImageRect.w = w;
m_ImageRect.h = h;
mImageRect.w = w;
mImageRect.h = h;
}
void CBitmap::setName(const std::string &name)
{
m_name = name;
mName = name;
}
/**
......@@ -110,18 +105,9 @@ void CBitmap::_draw(SDL_Surface *dst, Uint16 x, Uint16 y)
{
SDL_Rect dst_rect;
dst_rect.x = x; dst_rect.y = y;
dst_rect.w = m_ImageRect.w;
dst_rect.h = m_ImageRect.h;
dst_rect.w = mImageRect.w;
dst_rect.h = mImageRect.h;
if( dst_rect.w>0 && dst_rect.h>0 )
SDL_BlitSurface(m_BitmapSurface, NULL, dst, &dst_rect);
}
///
// Freeing Routines
///
void CBitmap::destroySurface() {
if(m_BitmapSurface) SDL_FreeSurface(m_BitmapSurface);
m_BitmapSurface = NULL;
SDL_BlitSurface(mpBitmapSurface.get(), NULL, dst, &dst_rect);
}
......@@ -11,12 +11,16 @@
#include <SDL.h>
#include <vector>
#include <string>
#include "SmartPointer.h"
class CBitmap
{
public:
CBitmap();
CBitmap(const SmartPointer<SDL_Surface> &bmpSfc);
explicit CBitmap(const CBitmap &bitmap);
bool createSurface(Uint32 flags, SDL_Color *Palette);
......@@ -25,33 +29,28 @@ public:
SDL_Surface *getSDLSurface() const
{
return m_BitmapSurface;
return mpBitmapSurface.get();
}
void setSDLSurface(SDL_Surface *surface)
{ m_BitmapSurface = surface; }
void setDimensions(const Uint16 w, const Uint16 h);
void setName(const std::string &name);
void setColorPalette(SDL_Color *Palette);
Uint16 getWidth() { return m_ImageRect.w; }
Uint16 getHeight() { return m_ImageRect.h; }
Uint16 getWidth() { return mImageRect.w; }
Uint16 getHeight() { return mImageRect.h; }
SDL_Rect getRect() const { return m_ImageRect; }
void setRect(SDL_Rect &rect) { m_ImageRect = rect; }
SDL_Rect getRect() const { return mImageRect; }
void setRect(SDL_Rect &rect) { mImageRect = rect; }
std::string getName() const { return m_name; }
void setName(std::string &name) { m_name = name; }
std::string getName() const { return mName; }
void setName(std::string &name) { mName = name; }
void draw(Uint16 x, Uint16 y);
void _draw(SDL_Surface *dst, Uint16 x, Uint16 y);
void destroySurface();
private:
SDL_Rect m_ImageRect;
std::string m_name;
SDL_Surface *m_BitmapSurface;
SDL_Rect mImageRect;
std::string mName;
SmartPointer<SDL_Surface> mpBitmapSurface;
};
#endif /* CBITMAP_H_ */
......@@ -116,7 +116,6 @@ void CGfxEngine::freeBitmaps(std::vector<CBitmap> &Bitmap)
while ( !Bitmap.empty() )
{
CBitmap &bitmap = Bitmap.back();
bitmap.destroySurface();
Bitmap.pop_back();
}
}
......
......@@ -75,6 +75,18 @@ SDL_Surface *CTilemap::getSDLSurface()
return m_Tilesurface;
}
////////////////////////////
///// Getters /////
////////////////////////////
int CTilemap::getDimension()
{
return (1<<m_pbasesize);
}
////////////////////////////
///// Drawing Routines /////
////////////////////////////
......
......@@ -23,6 +23,8 @@ public:
bool optimizeSurface();
SDL_Surface *getSDLSurface();
int getDimension();
int EmptyBackgroundTile() { return m_EmptyBackgroundTile; }
void drawTile(SDL_Surface *dst, Uint16 x, Uint16 y, Uint16 t);
......
......@@ -8,6 +8,13 @@
#include "CGUIBitmap.h"
#include "graphics/CGfxEngine.h"
CGUIBitmap::CGUIBitmap(const SmartPointer<CBitmap>& pBitmap)
{
mpBitmap = pBitmap;
}
CGUIBitmap::CGUIBitmap(const std::string &text)
{
......@@ -15,10 +22,12 @@ CGUIBitmap::CGUIBitmap(const std::string &text)
}
void CGUIBitmap::processLogic()
{
{}
}
void CGUIBitmap::processRender(const CRect<float> &RectDispCoordFloat)
{
......
......@@ -16,8 +16,14 @@
class CGUIBitmap : public CGUIControl
{
public:
// Loads an Bitmap that is given directly
CGUIBitmap(const SmartPointer<CBitmap>& pBitmap);
// Load an Bitmap using an internal string ID of all the loaded Bitmaps
CGUIBitmap(const std::string &text);
void processLogic();
void processRender(const CRect<float> &RectDispCoordFloat);
......
......@@ -18,6 +18,14 @@
template <typename T>
struct CRect
{
template <typename T2>
CRect( CRect<T2> rect )
{
x = rect.x; y = rect.y;
w = rect.w; h = rect.h;
}
CRect( const T lwidth = 0,
const T lheight = 0 )
{ w=lwidth; h=lheight; }
......@@ -63,6 +71,16 @@ struct CRect
return Rect;
}
void transformInverse(const CRect &scaleRect)
{
x /= scaleRect.w;
x -= scaleRect.x;
y /= scaleRect.h;
y -= scaleRect.y;
w /= scaleRect.w;
h /= scaleRect.h;
}
void transform(const CRect &scaleRect)
{
x *= scaleRect.w;
......
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