_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

popup.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2012 by Joris Dauphin
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef __POPUP_H__
31 #define __POPUP_H__
32 
34 
35 #include "script.h"
36 #include "color.h"
37 #include "vec2i.h"
38 #include <vector>
39 #include <string>
40 
41 /*----------------------------------------------------------------------------
42 -- Declarations
43 ----------------------------------------------------------------------------*/
44 
45 class ButtonAction;
46 class CFont;
47 class CPopup;
48 
49 #define MARGIN_X 4
50 #define MARGIN_Y 2
51 
53 {
54 public:
56  ButtonAction(-1), BoolFlags(NULL), Variables(NULL) {}
58  {
59  delete[] BoolFlags;
60  delete[] Variables;
61  }
62 
63  bool HasHint;
67  std::string ButtonValue;
68 
69  char *BoolFlags;
70  char *Variables;
71 };
72 
74 {
75 public:
78  Wrap(true), Condition(NULL) {}
79  virtual ~CPopupContentType() { delete Condition; }
80 
82  virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const = 0;
84  virtual int GetWidth(const ButtonAction &button, int *Costs) const = 0;
86  virtual int GetHeight(const ButtonAction &button, int *Costs) const = 0;
87 
88  virtual void Parse(lua_State *l) = 0;
89 
90  static CPopupContentType *ParsePopupContent(lua_State *l);
91 
92 public:
94 
95  int MarginX;
96  int MarginY;
98  bool Wrap;
99 protected:
100  std::string TextColor;
101  std::string HighlightColor;
102 public:
104 };
105 
110 };
111 
113 {
114 public:
115  CPopupContentTypeButtonInfo() : InfoType(0), MaxWidth(0), Font(NULL) {}
117 
118  virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
119 
120  virtual int GetWidth(const ButtonAction &button, int *Costs) const;
121  virtual int GetHeight(const ButtonAction &button, int *Costs) const;
122 
123  virtual void Parse(lua_State *l);
124 
125 private:
126  int InfoType;
127  unsigned int MaxWidth;
128  CFont *Font;
129 };
130 
132 {
133 public:
134  CPopupContentTypeText() : MaxWidth(0), Font(NULL) {}
136 
137  virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
138 
139  virtual int GetWidth(const ButtonAction &button, int *Costs) const;
140  virtual int GetHeight(const ButtonAction &button, int *Costs) const;
141 
142  virtual void Parse(lua_State *l);
143 
144 private:
145  std::string Text;
146  unsigned int MaxWidth;
147  CFont *Font;
148 };
149 
151 {
152 public:
153  CPopupContentTypeCosts() : Font(NULL), Centered(0) {}
155 
156  virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
157 
158  virtual int GetWidth(const ButtonAction &button, int *Costs) const;
159  virtual int GetHeight(const ButtonAction &button, int *Costs) const;
160 
161  virtual void Parse(lua_State *l);
162 
163 private:
164  CFont *Font;
165  char Centered;
166 };
167 
169 {
170 public:
173 
174  virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
175 
176  virtual int GetWidth(const ButtonAction &button, int *Costs) const;
177  virtual int GetHeight(const ButtonAction &button, int *Costs) const;
178 
179  virtual void Parse(lua_State *l);
180 
181 private:
182  IntColor Color;
183  unsigned int Width;
184  unsigned int Height;
185 };
186 
188 {
189 public:
190  CPopupContentTypeVariable() : Text(NULL), Font(NULL), Centered(0), Index(-1) {}
192  {
193  FreeStringDesc(Text);
194  delete Text;
195  }
196 
197  virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
198 
199  virtual int GetWidth(const ButtonAction &button, int *Costs) const;
200  virtual int GetHeight(const ButtonAction &button, int *Costs) const;
201 
202  virtual void Parse(lua_State *l);
203 
204 private:
205  StringDesc *Text;
206  CFont *Font;
207  char Centered;
208  int Index;
209 };
210 
211 class CPopup
212 {
213 public:
214  CPopup();
215  ~CPopup();
216 
217  std::vector<CPopupContentType *> Contents;
218  std::string Ident;
219  int MarginX;
220  int MarginY;
221  int MinWidth;
222  int MinHeight;
226 };
227 
228 
230 
231 #endif // !__UI_H__
CPopupContentType::ParsePopupContent
static CPopupContentType * ParsePopupContent(lua_State *l)
Definition: popup.cpp:549
CPopupContentTypeButtonInfo::GetWidth
virtual int GetWidth(const ButtonAction &button, int *Costs) const
Get the content's width.
Definition: popup.cpp:49
CPopup::MarginX
int MarginX
Ident of the popup.
Definition: popup.h:219
CPopup::~CPopup
~CPopup()
Definition: popup.cpp:619
PopupConditionPanel
Definition: popup.h:52
CPopupContentTypeButtonInfo::GetHeight
virtual int GetHeight(const ButtonAction &button, int *Costs) const
Get the content's height.
Definition: popup.cpp:78
CPopupContentType::GetWidth
virtual int GetWidth(const ButtonAction &button, int *Costs) const =0
Get the content's width.
CPopupContentTypeText::Draw
virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const
Tell how show the variable Index.
Definition: popup.cpp:187
CPopupContentType::pos
PixelPos pos
Definition: popup.h:93
CPopupContentType::HighlightColor
std::string HighlightColor
Color used for plain text in content.
Definition: popup.h:101
CPopupContentTypeText::~CPopupContentTypeText
virtual ~CPopupContentTypeText()
Definition: popup.h:135
PopupButtonInfo_Description
@ PopupButtonInfo_Description
Definition: popup.h:108
CPopupContentType::~CPopupContentType
virtual ~CPopupContentType()
Definition: popup.h:79
CPopupContentTypeCosts
Definition: popup.h:150
CPopupContentTypeVariable::Parse
virtual void Parse(lua_State *l)
Definition: popup.cpp:424
IntColor
uint32_t IntColor
Definition: color.h:37
ButtonAction
Action of button.
Definition: interface.h:88
vec2i.h
PopupButtonInfo_Types
PopupButtonInfo_Types
Definition: popup.h:106
CPopupContentTypeText::Parse
virtual void Parse(lua_State *l)
Definition: popup.cpp:203
CPopup::Ident
std::string Ident
Array of contents to display.
Definition: popup.h:218
CPopupContentTypeCosts::CPopupContentTypeCosts
CPopupContentTypeCosts()
Definition: popup.h:153
CPopupContentType::MarginY
int MarginY
Left and right margin width.
Definition: popup.h:96
CPopupContentType::Condition
PopupConditionPanel * Condition
Color used for highlighted letters.
Definition: popup.h:103
CPopupContentTypeLine::~CPopupContentTypeLine
virtual ~CPopupContentTypeLine()
Definition: popup.h:172
PopupConditionPanel::HasHint
bool HasHint
Definition: popup.h:63
CPopupContentType::minSize
PixelSize minSize
Upper and lower margin height.
Definition: popup.h:97
Vec2T< int >
CPopupContentTypeButtonInfo
Definition: popup.h:112
CPopupContentTypeVariable
Definition: popup.h:187
CPopup::BackgroundColor
IntColor BackgroundColor
Default font for content.
Definition: popup.h:224
CPopupContentType::TextColor
std::string TextColor
If true, the next content will be placed on the next "line".
Definition: popup.h:100
CPopupContentTypeVariable::CPopupContentTypeVariable
CPopupContentTypeVariable()
Definition: popup.h:190
PopupConditionPanel::HasDescription
bool HasDescription
check if button has hint.
Definition: popup.h:64
CPopupContentTypeText::GetHeight
virtual int GetHeight(const ButtonAction &button, int *Costs) const
Get the content's height.
Definition: popup.cpp:176
CPopup::MinWidth
int MinWidth
Upper and lower margin height.
Definition: popup.h:221
CPopup::Contents
std::vector< CPopupContentType * > Contents
Definition: popup.h:217
CPopupContentTypeVariable::GetHeight
virtual int GetHeight(const ButtonAction &button, int *Costs) const
Get the content's height.
Definition: popup.cpp:383
CPopupContentTypeText
Definition: popup.h:131
CPopupContentTypeVariable::~CPopupContentTypeVariable
virtual ~CPopupContentTypeVariable()
Definition: popup.h:191
CPopupContentTypeVariable::Draw
virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const
Tell how show the variable Index.
Definition: popup.cpp:389
PopupConditionPanel::Variables
char * Variables
array of condition about user flags.
Definition: popup.h:70
CPopupContentTypeText::GetWidth
virtual int GetWidth(const ButtonAction &button, int *Costs) const
Get the content's width.
Definition: popup.cpp:160
CPopupContentType::Draw
virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const =0
Tell how show the variable Index.
CPopupContentTypeButtonInfo::Draw
virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const
Tell how show the variable Index.
Definition: popup.cpp:104
PopupConditionPanel::ButtonValue
std::string ButtonValue
action type of button
Definition: popup.h:67
CPopupContentType::CPopupContentType
CPopupContentType()
Definition: popup.h:76
CPopup::CPopup
CPopup()
Definition: popup.cpp:614
CPopupContentTypeCosts::~CPopupContentTypeCosts
virtual ~CPopupContentTypeCosts()
Definition: popup.h:154
CPopupContentTypeButtonInfo::Parse
virtual void Parse(lua_State *l)
Definition: popup.cpp:135
CPopup::MinHeight
int MinHeight
Minimal width covered by popup.
Definition: popup.h:222
CPopupContentTypeButtonInfo::~CPopupContentTypeButtonInfo
virtual ~CPopupContentTypeButtonInfo()
Definition: popup.h:116
PopupConditionPanel::~PopupConditionPanel
~PopupConditionPanel()
Definition: popup.h:57
CPopupContentTypeLine::Draw
virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const
Tell how show the variable Index.
Definition: popup.cpp:348
StringDesc
Definition: script.h:259
PopupConditionPanel::ButtonAction
int ButtonAction
check if button has dependencies or restrictions.
Definition: popup.h:66
CPopupContentTypeCosts::GetWidth
virtual int GetWidth(const ButtonAction &button, int *Costs) const
Get the content's width.
Definition: popup.cpp:221
CPopupContentTypeLine
Definition: popup.h:168
CPopupContentTypeLine::GetWidth
virtual int GetWidth(const ButtonAction &button, int *Costs) const
Get the content's width.
Definition: popup.cpp:338
CPopupContentTypeButtonInfo::CPopupContentTypeButtonInfo
CPopupContentTypeButtonInfo()
Definition: popup.h:115
CPopup::BorderColor
IntColor BorderColor
Color used for popup's background.
Definition: popup.h:225
CPopupContentTypeCosts::GetHeight
virtual int GetHeight(const ButtonAction &button, int *Costs) const
Get the content's height.
Definition: popup.cpp:262
PopupButtonInfo_Dependencies
@ PopupButtonInfo_Dependencies
Definition: popup.h:109
PopupConditionPanel::BoolFlags
char * BoolFlags
value used in ValueStr field of button
Definition: popup.h:69
CPopupContentTypeLine::GetHeight
virtual int GetHeight(const ButtonAction &button, int *Costs) const
Get the content's height.
Definition: popup.cpp:343
CPopup::MarginY
int MarginY
Left and right margin width.
Definition: popup.h:220
CPopupContentTypeLine::Parse
virtual void Parse(lua_State *l)
Definition: popup.cpp:354
PopupButtonInfo_Hint
@ PopupButtonInfo_Hint
Definition: popup.h:107
CPopupContentType::Parse
virtual void Parse(lua_State *l)=0
MARGIN_Y
#define MARGIN_Y
Definition: popup.h:50
script.h
CPopupContentType::GetHeight
virtual int GetHeight(const ButtonAction &button, int *Costs) const =0
Get the content's height.
CPopupContentTypeCosts::Draw
virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const
Tell how show the variable Index.
Definition: popup.cpp:275
PopupConditionPanel::PopupConditionPanel
PopupConditionPanel()
Definition: popup.h:55
FreeStringDesc
void FreeStringDesc(StringDesc *s)
Free unit description content. (no pointer itself).
Definition: script.cpp:1294
CPopupContentTypeLine::CPopupContentTypeLine
CPopupContentTypeLine()
Definition: popup.cpp:333
CPopup::DefaultFont
CFont * DefaultFont
Minimal height covered by popup.
Definition: popup.h:223
CPopupContentType::MarginX
int MarginX
position to draw.
Definition: popup.h:95
Color
Definition: png2stratagus.cpp:57
CPopup
Definition: popup.h:211
PopupConditionPanel::HasDependencies
bool HasDependencies
check if button has description.
Definition: popup.h:65
CPopupContentType::Wrap
bool Wrap
Minimal size covered by content type.
Definition: popup.h:98
CPopupContentTypeVariable::GetWidth
virtual int GetWidth(const ButtonAction &button, int *Costs) const
Get the content's width.
Definition: popup.cpp:374
CPopupContentTypeCosts::Parse
virtual void Parse(lua_State *l)
Definition: popup.cpp:315
MARGIN_X
#define MARGIN_X
Definition: popup.h:49
CFont
Font definition.
Definition: font.h:73
CPopupContentTypeText::CPopupContentTypeText
CPopupContentTypeText()
Definition: popup.h:134
CPopupContentType
Definition: popup.h:73
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.