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 // 11 /**@name popup.h - The Popup header file. */ 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 33 //@{ 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 52 class PopupConditionPanel 53 { 54 public: PopupConditionPanel()55 PopupConditionPanel() : HasHint(false), HasDescription(false), HasDependencies(false), 56 ButtonAction(-1), BoolFlags(NULL), Variables(NULL) {} ~PopupConditionPanel()57 ~PopupConditionPanel() 58 { 59 delete[] BoolFlags; 60 delete[] Variables; 61 } 62 63 bool HasHint; /// check if button has hint. 64 bool HasDescription; /// check if button has description. 65 bool HasDependencies; /// check if button has dependencies or restrictions. 66 int ButtonAction; /// action type of button 67 std::string ButtonValue; /// value used in ValueStr field of button 68 69 char *BoolFlags; /// array of condition about user flags. 70 char *Variables; /// array of variable to verify (enable and max > 0) 71 }; 72 73 class CPopupContentType 74 { 75 public: CPopupContentType()76 CPopupContentType() : pos(0, 0), 77 MarginX(MARGIN_X), MarginY(MARGIN_Y), minSize(0, 0), 78 Wrap(true), Condition(NULL) {} ~CPopupContentType()79 virtual ~CPopupContentType() { delete Condition; } 80 81 /// Tell how show the variable Index. 82 virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const = 0; 83 /// Get the content's width 84 virtual int GetWidth(const ButtonAction &button, int *Costs) const = 0; 85 /// Get the content's height 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: 93 PixelPos pos; /// position to draw. 94 95 int MarginX; /// Left and right margin width. 96 int MarginY; /// Upper and lower margin height. 97 PixelSize minSize; /// Minimal size covered by content type. 98 bool Wrap; /// If true, the next content will be placed on the next "line". 99 protected: 100 std::string TextColor; /// Color used for plain text in content. 101 std::string HighlightColor; /// Color used for highlighted letters. 102 public: 103 PopupConditionPanel *Condition; /// Condition to show the content; if NULL, no condition. 104 }; 105 106 enum PopupButtonInfo_Types { 107 PopupButtonInfo_Hint, 108 PopupButtonInfo_Description, 109 PopupButtonInfo_Dependencies 110 }; 111 112 class CPopupContentTypeButtonInfo : public CPopupContentType 113 { 114 public: CPopupContentTypeButtonInfo()115 CPopupContentTypeButtonInfo() : InfoType(0), MaxWidth(0), Font(NULL) {} ~CPopupContentTypeButtonInfo()116 virtual ~CPopupContentTypeButtonInfo() {} 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; /// Type of information to show. 127 unsigned int MaxWidth; /// Maximum width of multilined information. 128 CFont *Font; /// Font to use. 129 }; 130 131 class CPopupContentTypeText : public CPopupContentType 132 { 133 public: CPopupContentTypeText()134 CPopupContentTypeText() : MaxWidth(0), Font(NULL) {} ~CPopupContentTypeText()135 virtual ~CPopupContentTypeText() {} 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; /// Text to display 146 unsigned int MaxWidth; /// Maximum width of multilined text. 147 CFont *Font; /// Font to use. 148 }; 149 150 class CPopupContentTypeCosts : public CPopupContentType 151 { 152 public: CPopupContentTypeCosts()153 CPopupContentTypeCosts() : Font(NULL), Centered(0) {} ~CPopupContentTypeCosts()154 virtual ~CPopupContentTypeCosts() {} 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; /// Font to use. 165 char Centered; /// if true, center the display. 166 }; 167 168 class CPopupContentTypeLine : public CPopupContentType 169 { 170 public: 171 CPopupContentTypeLine(); ~CPopupContentTypeLine()172 virtual ~CPopupContentTypeLine() {} 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; /// Color used for line. 183 unsigned int Width; /// line height 184 unsigned int Height; /// line height 185 }; 186 187 class CPopupContentTypeVariable : public CPopupContentType 188 { 189 public: CPopupContentTypeVariable()190 CPopupContentTypeVariable() : Text(NULL), Font(NULL), Centered(0), Index(-1) {} ~CPopupContentTypeVariable()191 virtual ~CPopupContentTypeVariable() 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; /// Text to display. 206 CFont *Font; /// Font to use. 207 char Centered; /// if true, center the display. 208 int Index; /// Index of the variable to show, -1 if not. 209 }; 210 211 class CPopup 212 { 213 public: 214 CPopup(); 215 ~CPopup(); 216 217 std::vector<CPopupContentType *> Contents; /// Array of contents to display. 218 std::string Ident; /// Ident of the popup. 219 int MarginX; /// Left and right margin width. 220 int MarginY; /// Upper and lower margin height. 221 int MinWidth; /// Minimal width covered by popup. 222 int MinHeight; /// Minimal height covered by popup. 223 CFont *DefaultFont; /// Default font for content. 224 IntColor BackgroundColor; /// Color used for popup's background. 225 IntColor BorderColor; /// Color used for popup's borders. 226 }; 227 228 229 //@} 230 231 #endif // !__UI_H__ 232