Commit fc0abb72 authored by gerstrong@gmail.com's avatar gerstrong@gmail.com

Font class fixes

parent e6584c0e
......@@ -107,13 +107,16 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
if(USE_SDL2)
find_package(SDL2 REQUIRED)
if(SDL2_FOUND)
find_package(SDL2_image REQUIRED)
# find_package(SDL2_ttf REQUIRED)
message(STATUS "Using shared SDL Version 2 for Commander Genius")
include_directories(${SDL2_INCLUDE_DIRS})
include_directories(${SDL2_TTF_INCLUDE_DIRS})
include_directories(${SDL2_IMAGE_INCLUDE_DIRS})
endif(SDL2_FOUND)
......@@ -138,6 +141,7 @@ if(USE_SDL2)
Target_link_libraries(GsKit ${SDL2_LIBRARY})
Target_link_libraries(GsKit ${SDL2IMAGE_LIBRARIES})
Target_link_libraries(GsKit ${SDLIMAGE_LIBRARY})
Target_link_libraries(GsKit ${SDL2_TTF_LIBRARY})
else()
Target_link_libraries(GsKit ${SDL_LIBRARY})
Target_link_libraries(GsKit ${SDL_LIBRARIES})
......
......@@ -51,10 +51,10 @@ bool getBooleanArgument( int argc, char *argv[], const std::string& text )
GsApp::GsApp() :
mSink(this)
GsApp::GsApp()
{
gEventManager.regSink(&mSink);
mpSink.reset(new GsAppEventSink(this));
gEventManager.regSink(mpSink);
}
......@@ -70,12 +70,12 @@ mSink(this)
void GsApp::cleanup()
{
gInput.shutdown();
mpSink = nullptr;
//gInput.shutdown();
}
GsApp::~GsApp()
{
gEventManager.unregSink(&mSink);
}
......@@ -231,7 +231,11 @@ void GsApp::setEngine(GsEngine *engPtr)
void GsApp::runMainCycle()
{
// I hope the engine has been set. Otherwise quit the app
assert(mpCurEngine);
if(!mpCurEngine)
{
gLogging << "No Engine set. This should not happen. Please report this the developers";
return ;
}
mpCurEngine->start();
......
......@@ -63,7 +63,7 @@ public:
private:
std::unique_ptr<GsEngine> mpCurEngine;
GsAppEventSink mSink;
std::shared_ptr<GsAppEventSink> mpSink;
};
// It's a simple quit event which will force CG to close the App
......
......@@ -10,8 +10,8 @@
*
*/
#ifndef __GSENGINE_H_
#define __GSENGINE_H_
#ifndef GSENGINE_H
#define GSENGINE_H
#include <base/GsEvent.h>
#include <vector>
......@@ -58,4 +58,4 @@ struct SwitchEngineEvent : CEvent
};
#endif /* __GSENGINE_H_ */
#endif /* GSENGINE_H */
......@@ -16,7 +16,7 @@ void CEventContainer::processSinks()
// We don't need anything from this list anymore
m_EventList.clear();
for( GsEventSink* sink : mSinkPtrList )
for( auto sink : mSinkPtrList )
{
for( auto &event : mPumpEventPtrs )
{
......
......@@ -24,12 +24,12 @@ public:
* Otherwise app might crash.
* @param pSink pointer to the sink to be registered
*/
void regSink(GsEventSink *pSink)
void regSink(std::shared_ptr<GsEventSink> pSink)
{
mSinkPtrList.push_back(pSink);
}
void unregSink(GsEventSink *pSink)
void unregSink(std::shared_ptr<GsEventSink> pSink)
{
mSinkPtrList.remove(pSink);
}
......@@ -80,7 +80,7 @@ public:
void pop_Event() { m_EventList.pop_front(); }
private:
std::list< GsEventSink* > mSinkPtrList;
std::list< std::shared_ptr<GsEventSink> > mSinkPtrList;
std::deque< std::shared_ptr<CEvent> > m_EventList;
std::vector< std::shared_ptr<CEvent> > mPumpEventPtrs;
......
......@@ -21,7 +21,7 @@ GsCursor::GsCursor(SDL_Surface *p_screen)
SDL_FillRect(mp_Surface, nullptr, 0x0);
}
void GsCursor::generateTwirls(GsFont &Font)
void GsCursor::generateTwirls(GsFontLegacy &Font)
{
// The positions from the fonts are from 9 to 14
// You see, just six direction
......
......@@ -12,14 +12,14 @@
#ifndef GsCursor_H_
#define GsCursor_H_
#include <graphics/GsFont.h>
#include <graphics/GsFontLegacy.h>
#include <SDL.h>
class GsCursor
{
public:
GsCursor(SDL_Surface *p_screen);
void generateTwirls(GsFont &Font);
void generateTwirls(GsFontLegacy &Font);
void draw(SDL_Surface* dst, Uint8 character, Uint16 x, Uint16 y);
virtual ~GsCursor();
......
......@@ -12,7 +12,7 @@
#include <base/video/GsEffectController.h>
#include "GsFont.h"
#include "GsFontLegacy.h"
#include "GsTilemap.h"
#include "GsSprite.h"
#include "GsBitmap.h"
......@@ -121,7 +121,7 @@ void GsGraphics::createEmptyMisGsBitmaps(Uint16 num_bmps)
void GsGraphics::createEmptyFontmaps(Uint8 num_fonts)
{
freeFonts();
Font.assign(num_fonts, GsFont());
Font.assign(num_fonts, GsFontLegacy());
}
/*void GsGraphics::createEmptyCursorMap(SDL_Surface *surface)
......@@ -295,7 +295,7 @@ std::vector<GsSprite> &GsGraphics::getSpriteVec(const int var)
GsSprite &GsGraphics::getSpecialSpriteRef(const std::string &name)
{ return mSpecialSpriteMap[name]; }
GsFont &GsGraphics::getFont(Uint8 index)
GsFontLegacy &GsGraphics::getFont(Uint8 index)
{ return Font.at(index); }
GsBitmap *GsGraphics::getBitmapFromStr(const size_t sprVar,
......
......@@ -29,7 +29,7 @@
#define gGraphics GsGraphics::get()
class GsFont;
class GsFontLegacy;
class GsGraphics : public GsSingleton<GsGraphics>
{
......@@ -89,7 +89,7 @@ public:
void optimizeSprites();
GsFont &getFont(Uint8 index);
GsFontLegacy &getFont(Uint8 index);
GsPalette Palette;
......@@ -102,7 +102,7 @@ private:
void freeBitmaps(std::vector<GsBitmap> &mBitmap);
void freeSprites();
std::vector<GsFont> Font;
std::vector<GsFontLegacy> Font;
std::vector<GsTilemap> Tilemap;
std::vector< std::vector<GsBitmap> > mBitmap;
......
......@@ -156,7 +156,7 @@ void GsSprite::generateSprite( const int points )
mSurface.createRGBSurface(rect);
GsFont &smallFont = gGraphics.getFont(2);
GsFontLegacy &smallFont = gGraphics.getFont(2);
// Create Text Borders TODO: Make this code to draw better looking fonts
smallFont.drawFont( mSurface, pointStr, 0, 1, false );
......
......@@ -10,7 +10,7 @@
#include <cassert>
static inline int BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
SDL_Surface *dst, SDL_Rect *dstrect)
{
assert(src); assert(dst);
......@@ -194,12 +194,20 @@ public:
fill( rect, mapRGBA(r,g,b,a) );
}
void fill(const GsRect<Uint16> &rect, const Uint32 color)
void fill(const GsRect<Uint16> &rect,
const Uint32 color)
{
SDL_Rect sdlRect = rect.SDLRect();
SDL_FillRect( mpSurface, &sdlRect, color );
}
void fill(const GsRect<Uint16> &rect,
const GsColor &color)
{
fill( rect, color.get(mpSurface->format) );
}
void fill(const Uint32 color)
{
SDL_FillRect( mpSurface, nullptr, color );
......
......@@ -5,6 +5,15 @@
#if SDL_VERSION_ATLEAST(2, 0, 0)
GsTexture::~GsTexture()
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
if(mpTexture)
unload();
#endif
}
void GsTexture::fillRGB( SDL_Renderer *renderer,
const Uint8 r,
const Uint8 g,
......@@ -35,7 +44,10 @@ bool GsTexture::loadFromMem(const unsigned char *data,
if(mpTexture)
unload();
SDL_RWops *rw = SDL_RWFromMem( (void*)(data), size);
SDL_RWops *rw =
SDL_RWFromMem(
const_cast<void*>(reinterpret_cast<const void*>(data)),
int(size));
// Load image at specified path
SDL_Surface* loadedSurface = IMG_Load_RW(rw, 1);
......@@ -61,4 +73,9 @@ bool GsTexture::loadFromMem(const unsigned char *data,
return (mpTexture!=nullptr);
}
bool GsTexture::loadFromSurface(const GsSurface &sfc)
{
return false;
}
#endif
......@@ -6,6 +6,7 @@
#include <cstdio>
#include <string>
/**
* @brief The GsTexture class is a wrapper for SDL Textures introduced in SDL 2.0. It can be used extended with other libraries, OpenGL maybe, but
* this wrapper manages the texture memory a bit more C++ like, so trouble with managing it's pointer
......@@ -14,6 +15,8 @@
#if SDL_VERSION_ATLEAST(2, 0, 0)
class GsSurface;
class GsTexture
{
public:
......@@ -26,14 +29,7 @@ public:
/**
* @brief ~GsTexture Standard constructor
*/
virtual ~GsTexture()
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
if(mpTexture)
unload();
#endif
}
virtual ~GsTexture();
#if SDL_VERSION_ATLEAST(2, 0, 0)
......@@ -161,6 +157,8 @@ public:
SDL_Renderer *renderer,
const bool dark);
bool loadFromSurface(const GsSurface &sfc);
private:
SDL_Texture* mpTexture = nullptr;
......
......@@ -70,7 +70,7 @@ void CGUIBanner::processRender(const GsRect<float> &RectDispCoordFloat)
SDL_Rect lRect = displayRect.SDLRect();
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(mFontID);
GsFontLegacy &Font = gGraphics.getFont(mFontID);
if(transition)
{
......
......@@ -142,7 +142,7 @@ void GsButton::drawNoStyle(SDL_Rect& lRect)
void GsButton::setupButtonSurface(const std::string &text)
{
GsFont &Font = gGraphics.getFont(mFontID);
GsFontLegacy &Font = gGraphics.getFont(mFontID);
if(text.empty())
{
......
......@@ -134,7 +134,7 @@ void CGUIComboSelection::processRender(const GsRect<float> &RectDispCoordFloat)
}
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(mFontID);
GsFontLegacy &Font = gGraphics.getFont(mFontID);
const int fontHeight = 8;
//const int textX = lRect.x+24+(mText.size()+2)*fontHeight;
......
......@@ -11,7 +11,7 @@
#include <base/video/CVideoDriver.h>
#include <base/GsTimer.h>
#include <base/PointDevice.h>
#include <base/GsLogging.h>
#include "GsControl.h"
......@@ -31,6 +31,9 @@ GsControl::GsControl(const Style style) :
GsControl::GsControl() :
GsControl(Style::NONE) {}
GsControl::~GsControl()
{}
void GsControl::processBlendEffects()
{
......@@ -85,9 +88,6 @@ void GsControl::processPointingState(const GsRect<float> &rect)
if(hasPoint)
{
gLogging.ftextOut("rect = %f,%f,%f,%f\n", rect.x, rect.y, rect.w, rect.h);
gLogging.ftextOut("pointingState.mPos = %f,%f\n", pointingState.mPos.x, pointingState.mPos.y);
mReleased = true;
}
}
......@@ -119,7 +119,7 @@ void GsControl::drawTwirl( const SDL_Rect& lRect )
GsWeakSurface blit(gVideoDriver.getBlitSurface());
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(mFontID);
auto &Font = gGraphics.getFont(mFontID);
if( gTimer.HasTimeElapsed(100) )
{
......
......@@ -29,7 +29,7 @@ public:
GsControl(const Style style);
virtual ~GsControl() {}
virtual ~GsControl();
virtual void processLogic() = 0;
......@@ -59,14 +59,10 @@ public:
void select( const bool value )
{
mSelected = value;
}
{ mSelected = value; }
bool isSelected()
{
return mSelected;
}
{ return mSelected; }
bool Up()
......
......@@ -43,23 +43,22 @@ void CGUIDialog::updateGraphics()
}
std::shared_ptr<GsControl>
CGUIDialog::addControl( std::unique_ptr<GsControl> &newControl,
std::shared_ptr<GsControl>
CGUIDialog::addControl( std::shared_ptr<GsControl> &newControl,
const GsRect<float>& RelRect )
{
GsRect<float> AbsRect = RelRect;
AbsRect.transform(mRect);
newControl->mRect = AbsRect;
AbsRect.transform(mRect);
newControl->mRect = AbsRect;
auto ctrlPtr = std::shared_ptr<GsControl>( move(newControl) );
auto ctrlPtr = newControl;
mControlList.push_back( ctrlPtr );
if(mControlList.size() == 1)
{
mpCurrentCtrl = mControlList.front().get();
}
if(mControlList.size() == 1)
{
mpCurrentCtrl = mControlList.front().get();
}
return ctrlPtr;
}
......@@ -293,7 +292,7 @@ void CGUIDialog::initEmptyBackground()
void CGUIDialog::drawBorderRect(SDL_Surface *backSfc, const SDL_Rect &Rect)
{
GsFont &Font = gGraphics.getFont(1);
GsFontLegacy &Font = gGraphics.getFont(1);
Font.drawCharacter( backSfc, 1, 0, 0 );
for( int x=8 ; x<Rect.w-8 ; x+=8 )
......
......@@ -20,8 +20,9 @@
#include "GsControl.h"
#include "GsBitmapBox.h"
#include "GsControlsManager.h"
class CGUIDialog
class CGUIDialog : public GsControlsManager
{
public:
......@@ -60,9 +61,34 @@ public:
// Update all graphics. Happens when Video settings are normally changed
void updateGraphics();
// Adds a control instance to the list of controls to be processed.
template <class T>
std::shared_ptr<T> addControl( T *newControl,
const GsRect<float>& RelRect );
template <class T>
std::shared_ptr<T> addControl( T *newControl,
const float x,
const float y,
const float w,
const float h)
{
const GsRect<float> RelRect(x,y,w,h);
addControl( newControl, RelRect );
}
// Adds a control instance to the list of controls to be processed.
std::shared_ptr<GsControl> addControl( std::unique_ptr<GsControl> &newControl,
const GsRect<float>& RelRect );
const GsRect<float>& RelRect )
{
std::shared_ptr<GsControl> shared(move(newControl));
return addControl(shared, RelRect);
}
std::shared_ptr<GsControl> addControl( std::shared_ptr<GsControl> &newControl,
const GsRect<float>& RelRect );
std::shared_ptr<GsControl> addControl(std::unique_ptr<GsControl> &newControl);
......@@ -142,8 +168,23 @@ private:
FXKind mFXSetup;
int mFXhStep;
int mFXvStep;
};
template <class T>
std::shared_ptr<T> CGUIDialog::addControl( T *newControl,
const GsRect<float>& RelRect )
{
std::shared_ptr<T> ctrl(newControl);
std::shared_ptr<GsControl> abstract =
std::static_pointer_cast< GsControl >(ctrl);
addControl( abstract, RelRect );
return ctrl;
}
#endif /* CGUIDIALOG_H_ */
......@@ -120,7 +120,7 @@ void CGUIInputText::processRender(const GsRect<float> &RectDispCoordFloat)
}
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(mFontID);
GsFontLegacy &Font = gGraphics.getFont(mFontID);
Font.drawFontCentered( blitsfc, getInputString(), lRect.x, lRect.w, lRect.y, lRect.h,false );
}
......
......@@ -165,7 +165,7 @@ void CGUINumberControl::processLogic()
}
}
#else
if(bDown && hasPoint)
if(bDown)
{
mPressed = true;
......@@ -249,9 +249,7 @@ void CGUINumberControl::processRender(const GsRect<float> &RectDispCoordFloat)
else
lComp = 0xFF - (mLightRatio*(0xFF-0xDF)/255);
const Uint32 fillColor = blitsfc.mapRGBA( Uint8(lComp),
Uint8(lComp),
Uint8(lComp), 0xFF);
const Uint32 fillColor = blitsfc.mapRGBA( lComp, lComp, lComp, 0xFF);
GsRect<Uint16> rect(lRect);
......@@ -259,7 +257,7 @@ void CGUINumberControl::processRender(const GsRect<float> &RectDispCoordFloat)
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(mFontID);
GsFontLegacy &Font = gGraphics.getFont(mFontID);
const int fontHeight = 8;
const int textX = lRect.x+24+(mText.size()+2)*8;
......
......@@ -94,7 +94,7 @@ void GsScrollbar::drawScrollBar(const SDL_Rect &lRect)
// Set the up and down arrows
//GsFont &Font = gGraphics.getFont(mFontID);
//auto &Font = gGraphics.getFont(mFontID);
blitSurface.fillRGB( bScUpRect, 0x7F, 0x7F, 0x7F);
//Font.drawFontCentered(blitSurface.getSDLSurface(), "\017", bScUpRect.x, bScUpRect.w, bScUpRect.y, false );
blitSurface.fillRGB( bScDownRect, 0x7F, 0x7F, 0x7F);
......
......@@ -28,7 +28,7 @@ void CGUISwitch::drawVorticonStyle(SDL_Rect& lRect)
SDL_Surface *blitsfc = gVideoDriver.getBlitSurface();
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(2);
auto &Font = gGraphics.getFont(2);
Font.drawFont( blitsfc, mText, lRect.x+24, lRect.y, false );
Font.drawFont( blitsfc, ":", lRect.x+24+mText.size()*8, lRect.y, false );
......
......@@ -97,7 +97,7 @@ void CGUIText::processRender(const GsRect<float> &RectDispCoordFloat)
SDL_Rect lRect = displayRect.SDLRect();
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(mFontID);
auto &Font = gGraphics.getFont(mFontID);
std::list<std::string>::iterator textIt = mTextList.begin();
for( size_t i=0 ; textIt != mTextList.end() ; textIt++, i++ )
......
......@@ -147,7 +147,7 @@ void CGUITextSelectionList::processLogic()
const float fy = mRect.y;
const float fh = mRect.h;
GsFont &Font = gGraphics.getFont(mFontID);
GsFontLegacy &Font = gGraphics.getFont(mFontID);
const int pixth = Font.getPixelTextHeight();
......
......@@ -60,7 +60,7 @@ void CDlgFrame::setPos(const Uint32 x, const Uint32 y)
void CDlgFrame::drawVorticonFrame(SDL_Surface *dst)
{
GsFont &Font = gGraphics.getFont(1);
auto &Font = gGraphics.getFont(1);
// first draw the blank rect
int i, j;
......
......@@ -67,7 +67,7 @@ void CDlgOptionText::setText(const std::string &text, unsigned int delimit) {
*/
void CDlgOptionText::draw(SDL_Surface *Textsurface, Uint16 x, Uint16 y, bool highlight, Uint32 colour)
{
GsFont &Font = gGraphics.getFont(m_FontMapID);
auto &Font = gGraphics.getFont(m_FontMapID);
//Font.setFGColour(Textsurface->format, colour);
......
......@@ -249,7 +249,7 @@ void CTextViewer::renderBox()
SDL_Surface *sfc = mTextVSfc.getSDLSurface();
// first draw the blank rect
GsFont &Font = gGraphics.getFont(1);
auto &Font = gGraphics.getFont(1);
int i, j;
for(j = 0 ; j < m_h - m_8x8tileheight ; j+= m_8x8tileheight )
{
......
......@@ -448,7 +448,7 @@ bool CGameLauncher::start()
// Resources for the main menu
// This is only for the menu. We only need one fontmap for the list of games and some buttons
gGraphics.createEmptyFontmaps(1);
GsFont &Font = gGraphics.getFont(0);
auto &Font = gGraphics.getFont(0);
const auto height = gVideoDriver.getHeight();
......
option(NOTYPESAVE "Enable this if you don't want to type names for your savesgames" no)
if(NOTYPESAVE)
add_definitions(-DNOTYPESAVE)
endif()
include_directories(${SDL_INCLUDE_DIR})
add_subdirectory(core)
......
......@@ -138,7 +138,7 @@ void CHUD::DrawCircle(int x, int y, int width)
Uint8 r,g,b;
GsFont &Font = gGraphics.getFont(1);
auto &Font = gGraphics.getFont(1);
Font.getBGColour(&r, &g, &b);
outline.x = x+4;
......@@ -248,7 +248,7 @@ void CHUD::renderVorticon()
mBackground.blitTo(mHUDBlit);
GsFont &Font = gGraphics.getFont(1);
auto &Font = gGraphics.getFont(1);
// Print the lives
Font.drawFont(mHUDBlit, getRightAlignedString(itoa(lives),2), 15, 15, false);
......
......@@ -51,7 +51,7 @@ void CPassive::pumpEvent(const CEvent *evPtr)
void CPassive::createOutlinedText(const int splash_x, const int splash_y, const std::string &text)
{
GsFont &Font = gGraphics.getFont(1);
auto &Font = gGraphics.getFont(1);
SDL_Surface *sfc = mTextSfc.getSDLSurface();
SDL_PixelFormat *format = sfc->format;
......
......@@ -130,7 +130,7 @@ void CResourceLoaderBackground::render()
if(m_style == PROGRESS_STYLE_TEXT)
{
// Draw Loading Font... here!
GsFont &Font = gGraphics.getFont(0);
auto &Font = gGraphics.getFont(0);
int percent = m_permil/10;
int rest = m_permil%10;
std::string text = "Loading ... " + itoa(percent)+"."+ itoa(rest)+" \%";
......
......@@ -40,7 +40,7 @@ void GameMenu::initVorticonBackground()
mBackground.create(0, sdlRect.w, sdlRect.h, RES_BPP, 0, 0, 0, 0);
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(1);
auto &Font = gGraphics.getFont(1);
SDL_Surface *backSfc = mBackground.getSDLSurface();
......@@ -68,7 +68,7 @@ void GameMenu::initBackgroundNoStyle()
mBackground.create(0, sdlRect.w, sdlRect.h, RES_BPP, 0, 0, 0, 0);
// Now lets draw the text of the list control
//GsFont &Font = gGraphics.getFont(0);