Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / src / gui / skin.h
blob519a25be952accde6308dc43253c449ea068b9cb
1 //
2 // Copyright (C) 2008 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file skin.h
22 * Ble.
25 #pragma once
27 #include <string>
28 #include <vector>
29 #include <boost/smart_ptr.hpp>
31 #include "platform.h"
33 #ifdef PLATFORM_MSVC
34 # include <unordered_map>
35 #else /* PLATFORM_MSVC */
36 # include <tr1/unordered_map>
37 #endif /* PLATFORM_MSVC */
39 #include "stdtypes.h"
40 #include "cpair.h"
42 #include "gui/widget.h"
43 #include "gui/richtext.h"
45 class TiXmlElement;
47 namespace tre {
49 class WidgetTemplate {
50 public:
51 struct StateTexture {
52 uint ustate;
53 WidgetState wstate;
54 std::string tex;
56 StateTexture(uint us, WidgetState ws, const std::string & t)
57 : ustate(us), wstate(ws), tex(t) {}
60 typedef std::vector<StateTexture> TexVector;
62 public:
63 Float2Vector texCoords;
64 TexVector states;
66 float scale;
68 public:
69 void LoadFromXml(TiXmlElement & root);
72 class GuiSkin;
74 typedef boost::shared_ptr<GuiSkin> GuiSkinPtr;
75 typedef boost::weak_ptr<GuiSkin> GuiSkinRef;
77 class GuiSkinFactory {
78 public:
79 const GuiSkinPtr CreateInstance(const std::string & filename);
81 private:
82 typedef std::tr1::unordered_map<std::string, GuiSkinRef> SkinMap;
84 private:
85 SkinMap skinMap_;
88 class GuiSkin {
89 public:
90 static GuiSkinFactory & Factory(void)
92 static GuiSkinFactory fac;
93 return fac;
96 public:
97 typedef cpair<std::string, WidgetTemplate> TemplatePair;
98 typedef std::vector<TemplatePair> TempVector;
100 struct TextDefaults {
101 std::string effect;
102 std::string font;
103 TextStyle plainStyle;
104 TextStyle richStyles[ssLast];
107 public:
108 const std::string & GetEffect(void) const {return effect_;}
109 const TextDefaults & GetTextDefaults(void) const {return textDefs_;}
111 const WidgetTemplate * GetTemplate(const std::string & name) const;
113 void LoadFromXml(TiXmlElement & root);
115 private:
116 std::string effect_;
117 TextDefaults textDefs_;
119 TempVector templates_;