Move CColor in its own file.
Remove SDL dependency for font.h Remove duplicated container AllFonts Remove unused Macro MaxFonts
This commit is contained in:
parent
bea5669354
commit
16f09eecc7
6 changed files with 121 additions and 41 deletions
|
@ -304,6 +304,7 @@ set(unit_SRCS
|
|||
source_group(unit FILES ${unit_SRCS})
|
||||
|
||||
set(video_SRCS
|
||||
src/video/color.cpp
|
||||
src/video/cursor.cpp
|
||||
src/video/font.cpp
|
||||
src/video/graphic.cpp
|
||||
|
@ -477,6 +478,7 @@ set(stratagus_generic_HDRS
|
|||
src/include/actions.h
|
||||
src/include/ai.h
|
||||
src/include/animation.h
|
||||
src/include/color.h
|
||||
src/include/commands.h
|
||||
src/include/construct.h
|
||||
src/include/cursor.h
|
||||
|
|
57
src/include/color.h
Normal file
57
src/include/color.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name color.h - The A platform independent color headerfile. */
|
||||
//
|
||||
// (c) Copyright 2012 by Joris Dauphin
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
//@{
|
||||
|
||||
struct SDL_Color;
|
||||
|
||||
/// A platform independent color
|
||||
class CColor
|
||||
{
|
||||
public:
|
||||
CColor() : R(0), G(0), B(0), A(0) {}
|
||||
CColor(unsigned char r, unsigned char g, unsigned char b,
|
||||
unsigned char a = 0) : R(r), G(g), B(b), A(a) {}
|
||||
|
||||
/// Cast to a SDL_Color
|
||||
operator SDL_Color() const;
|
||||
|
||||
public:
|
||||
unsigned char R; /// Red
|
||||
unsigned char G; /// Green
|
||||
unsigned char B; /// Blue
|
||||
unsigned char A; /// Alpha
|
||||
};
|
||||
|
||||
//@}
|
||||
|
||||
#endif
|
|
@ -60,7 +60,7 @@
|
|||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include "SDL.h"
|
||||
#include "color.h"
|
||||
#include "guichan/font.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
@ -129,15 +129,13 @@ public:
|
|||
static CFontColor *Get(const std::string &ident);
|
||||
|
||||
std::string Ident;
|
||||
SDL_Color Colors[MaxFontColors];
|
||||
CColor Colors[MaxFontColors];
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Definitions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#define MaxFonts 15 /// Number of fonts supported
|
||||
|
||||
/**
|
||||
** FIXME: should be moved to lua
|
||||
*/
|
||||
|
@ -188,7 +186,7 @@ public:
|
|||
normal = CFontColor::Get(nc);
|
||||
reverse = CFontColor::Get(rc);
|
||||
}
|
||||
CLabel(const CFont &f);
|
||||
explicit CLabel(const CFont &f);
|
||||
|
||||
int Height() const { return font->Height(); }
|
||||
|
||||
|
|
|
@ -40,9 +40,10 @@
|
|||
#else
|
||||
#include "SDL_opengl.h"
|
||||
#endif
|
||||
|
||||
#include "guichan.h"
|
||||
|
||||
|
||||
#include "color.h"
|
||||
#include "vec2i.h"
|
||||
|
||||
class CFont;
|
||||
|
@ -177,25 +178,6 @@ public:
|
|||
};
|
||||
#endif
|
||||
|
||||
/// A platform independent color
|
||||
class CColor
|
||||
{
|
||||
public:
|
||||
CColor(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0,
|
||||
unsigned char a = 0) : R(r), G(g), B(b), A(a) {}
|
||||
|
||||
/// Cast to a SDL_Color
|
||||
operator SDL_Color() const {
|
||||
SDL_Color c = { R, G, B, A };
|
||||
return c;
|
||||
};
|
||||
|
||||
unsigned char R; /// Red
|
||||
unsigned char G; /// Green
|
||||
unsigned char B; /// Blue
|
||||
unsigned char A; /// Alpha
|
||||
};
|
||||
|
||||
class CUnitColors
|
||||
{
|
||||
public:
|
||||
|
|
44
src/video/color.cpp
Normal file
44
src/video/color.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name color.h - The A platform independent color. */
|
||||
//
|
||||
// (c) Copyright 2012 by Joris Dauphin
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
//@{
|
||||
|
||||
#include "stratagus.h"
|
||||
|
||||
#include "color.h"
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
CColor::operator SDL_Color() const
|
||||
{
|
||||
SDL_Color c = { R, G, B, A };
|
||||
return c;
|
||||
}
|
||||
|
||||
//@}
|
|
@ -38,7 +38,6 @@
|
|||
#include "font.h"
|
||||
|
||||
#include "intern_video.h"
|
||||
#include "script.h"
|
||||
#include "video.h"
|
||||
|
||||
#include <vector>
|
||||
|
@ -48,8 +47,8 @@
|
|||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
static std::vector<CFont *> AllFonts; /// Vector of all fonts
|
||||
static std::map<std::string, CFont *> Fonts; /// Font mappings
|
||||
typedef std::map<std::string, CFont *> FontMap;
|
||||
static FontMap Fonts; /// Font mappings
|
||||
|
||||
static std::vector<CFontColor *> AllFontColors; /// Vector of all font colors.
|
||||
std::map<std::string, CFontColor *> FontColors; /// Map of ident to font color.
|
||||
|
@ -136,8 +135,8 @@ static void VideoDrawChar(const CGraphic &g,
|
|||
if (!UseOpenGL) {
|
||||
SDL_Rect srect = {gx, gy, w, h};
|
||||
SDL_Rect drect = {x, y, 0, 0};
|
||||
|
||||
SDL_SetColors(g.Surface, const_cast<SDL_Color *>(fc.Colors), 0, MaxFontColors);
|
||||
std::vector<SDL_Color> sdlColors(fc.Colors, fc.Colors + MaxFontColors);
|
||||
SDL_SetColors(g.Surface, &sdlColors[0], 0, MaxFontColors);
|
||||
SDL_BlitSurface(g.Surface, &srect, TheScreen, &drect);
|
||||
} else {
|
||||
g.DrawSub(gx, gy, w, h, x, y);
|
||||
|
@ -868,8 +867,9 @@ void CFont::DynamicLoad() const
|
|||
*/
|
||||
void LoadFonts()
|
||||
{
|
||||
for (unsigned int i = 0; i < AllFonts.size(); ++i) {
|
||||
AllFonts[i]->Load();
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont &font = *it->second;
|
||||
font.Load();
|
||||
}
|
||||
|
||||
// TODO: remove this
|
||||
|
@ -892,8 +892,8 @@ void CFont::FreeOpenGL()
|
|||
*/
|
||||
void FreeOpenGLFonts()
|
||||
{
|
||||
for (size_t i = 0; i != AllFonts.size(); ++i) {
|
||||
CFont &font = *AllFonts[i];
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont &font = *it->second;
|
||||
|
||||
font.FreeOpenGL();
|
||||
}
|
||||
|
@ -920,8 +920,8 @@ void CFont::Reload() const
|
|||
*/
|
||||
void ReloadFonts()
|
||||
{
|
||||
for (size_t i = 0; i != AllFonts.size(); ++i) {
|
||||
const CFont &font = *AllFonts[i];
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont &font = *it->second;
|
||||
|
||||
font.Reload();
|
||||
}
|
||||
|
@ -946,7 +946,6 @@ CFont *CFont::New(const std::string &ident, CGraphic *g)
|
|||
} else {
|
||||
font = new CFont(ident);
|
||||
font->G = g;
|
||||
AllFonts.push_back(font);
|
||||
Fonts[ident] = font;
|
||||
}
|
||||
return font;
|
||||
|
@ -971,7 +970,6 @@ CFont *CFont::Get(const std::string &ident)
|
|||
CFontColor::CFontColor(const std::string &ident)
|
||||
{
|
||||
Ident = ident;
|
||||
memset(Colors, 0, sizeof(Colors));
|
||||
}
|
||||
|
||||
CFontColor::~CFontColor()
|
||||
|
@ -1037,8 +1035,8 @@ void CFont::Clean()
|
|||
*/
|
||||
void CleanFonts()
|
||||
{
|
||||
for (size_t i = 0; i != AllFonts.size(); ++i) {
|
||||
CFont *font = AllFonts[i];
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont *font = it->second;
|
||||
|
||||
font->Clean();
|
||||
delete font;
|
||||
|
@ -1046,7 +1044,6 @@ void CleanFonts()
|
|||
if (UseOpenGL) {
|
||||
FontColorGraphics.clear();
|
||||
}
|
||||
AllFonts.clear();
|
||||
Fonts.clear();
|
||||
|
||||
for (size_t i = 0; i != AllFontColors.size(); ++i) {
|
||||
|
|
Loading…
Add table
Reference in a new issue