1 /* 2 * This file is part of Dune Legacy. 3 * 4 * Dune Legacy 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 * Dune Legacy 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. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with Dune Legacy. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef DUNESTYLE_H 19 #define DUNESTYLE_H 20 21 #include <GUI/GUIStyle.h> 22 23 class DuneStyle : public GUIStyle { 24 public: 25 /// default constructor DuneStyle()26 DuneStyle() : GUIStyle() { 27 } 28 29 /// destructor ~DuneStyle()30 virtual ~DuneStyle() { 31 } 32 33 34 /** 35 Returns the minimum size of a label with this text 36 \param text The text for the label 37 \param fontID The ID of the font to use 38 \return the mimimum size of this label 39 */ 40 virtual Point getMinimumLabelSize(const std::string& text, int fontID); 41 42 /** 43 Creates the surface for a label with TextLines as content. 44 \param width the width of the label 45 \param height the height of the label 46 \param textLines a vector of text lines for this label 47 \param fontID the ID of the font to use 48 \param alignment the alignment for this label 49 \param textcolor the color of the text (COLOR_DEFAULT = default color for this style) 50 \param textshadowcolor the color of the shadow under the text (COLOR_DEFAULT = default color for this style) 51 \param backgroundcolor the background color (default is transparent) 52 \return the new surface (has to be freed by the caller) 53 */ 54 virtual SDL_Surface* createLabelSurface(Uint32 width, Uint32 height, const std::vector<std::string>& textLines, int fontID, Alignment_Enum alignment = Alignment_HCenter, Uint32 textcolor = COLOR_DEFAULT, Uint32 textshadowcolor = COLOR_DEFAULT, Uint32 backgroundcolor = COLOR_TRANSPARENT); 55 56 57 58 59 /** 60 Returns the minimum size of a checkbox with this text 61 \param text The text for the checkbox 62 \return the mimimum size of this checkbox 63 */ 64 virtual Point getMinimumCheckboxSize(const std::string& text); 65 66 /** 67 Creates the surface for a checkbox with text as content. 68 \param width the width of the checkbox 69 \param height the height of the checkbox 70 \param text the text for this checkbox 71 \param checked true, if the checkbox is checked, false otherwise 72 \param activated true if the checkbox is activated (e.g. mouse hover) 73 \param textcolor the color of the text (COLOR_DEFAULT = default color for this style) 74 \param textshadowcolor the color of the shadow under the text (COLOR_DEFAULT = default color for this style) 75 \param backgroundcolor the background color (default is transparent) 76 \return the new surface (has to be freed by the caller) 77 */ 78 virtual SDL_Surface* createCheckboxSurface(Uint32 width, Uint32 height, const std::string& text, bool checked, bool activated, Uint32 textcolor = COLOR_DEFAULT, Uint32 textshadowcolor = COLOR_DEFAULT, Uint32 backgroundcolor = COLOR_TRANSPARENT); 79 80 81 82 83 /** 84 Returns the minimum size of a radio button with this text 85 \param text The text for the radio button 86 \return the mimimum size of this radio button 87 */ 88 virtual Point getMinimumRadioButtonSize(const std::string& text); 89 90 /** 91 Creates the surface for a radio button with text as content. 92 \param width the width of the radio button 93 \param height the height of the radio button 94 \param text the text for this radio button 95 \param checked true, if the radio button is checked, false otherwise 96 \param activated true if the radio button is activated (e.g. mouse hover) 97 \param textcolor the color of the text (COLOR_DEFAULT = default color for this style) 98 \param textshadowcolor the color of the shadow under the text (COLOR_DEFAULT = default color for this style) 99 \param backgroundcolor the background color (default is transparent) 100 \return the new surface (has to be freed by the caller) 101 */ 102 virtual SDL_Surface* createRadioButtonSurface(Uint32 width, Uint32 height, const std::string& text, bool checked, bool activated, Uint32 textcolor = COLOR_DEFAULT, Uint32 textshadowcolor = COLOR_DEFAULT, Uint32 backgroundcolor = COLOR_TRANSPARENT); 103 104 105 106 107 /** 108 Creates the surface for a drop down box 109 \param size the width and height of the drop down button 110 \param pressed true if the button should be pressed 111 \param activated true if the button is activated (e.g. mouse hover) 112 \param color the color of the text (COLOR_DEFAULT = default color for this style) 113 \return the new surface (has to be freed by the caller) 114 */ 115 virtual SDL_Surface* createDropDownBoxButton(Uint32 size, bool pressed, bool activated, Uint32 color = COLOR_DEFAULT); 116 117 118 119 120 /** 121 Returns the minumum size of a button with this text 122 \param text The text for the button 123 \return the mimimum size of this button 124 */ 125 virtual Point getMinimumButtonSize(const std::string& text); 126 127 /** 128 Creates the surface for a button with text as content. 129 \param width the width of the button 130 \param height the height of the button 131 \param text the text for this button 132 \param pressed true if the button should be pressed 133 \param activated true if the button is activated (e.g. mouse hover) 134 \param textcolor the color of the text (COLOR_DEFAULT = default color for this style) 135 \param textshadowcolor the color of the shadow under the text (COLOR_DEFAULT = default color for this style) 136 \return the new surface (has to be freed by the caller) 137 */ 138 virtual SDL_Surface* createButtonSurface(Uint32 width, Uint32 height, const std::string& text, bool pressed, bool activated, Uint32 textcolor = COLOR_DEFAULT, Uint32 textshadowcolor = COLOR_DEFAULT); 139 140 141 142 143 /** 144 Returns the minumum size of a text box 145 \param fontID The ID of the font to use 146 \return the mimimum size of a text box 147 */ 148 virtual Point getMinimumTextBoxSize(int fontID); 149 150 /** 151 Creates the surface for a text box with text as content. 152 \param width the width of the text box 153 \param height the height of the text box 154 \param text the text for this text box 155 \param carret true if a carret should be shown 156 \param fontID the ID of the font to use 157 \param alignment the alignment for this text box 158 \param textcolor the color of the text (COLOR_DEFAULT = default color for this style) 159 \param textshadowcolor the color of the shadow under the text (COLOR_DEFAULT = default color for this style) 160 \return the new surface (has to be freed by the caller) 161 */ 162 virtual SDL_Surface* createTextBoxSurface(Uint32 width, Uint32 height, const std::string& text, bool carret, int fontID, Alignment_Enum alignment = Alignment_Left, Uint32 textcolor = COLOR_DEFAULT, Uint32 textshadowcolor = COLOR_DEFAULT); 163 164 165 166 167 /** 168 Returns the minumum size of a scroll bar arrow button. 169 \return the mimimum size of a scroll bar arrow 170 */ 171 virtual Point getMinimumScrollBarArrowButtonSize(); 172 173 /** 174 Creates the surface for a scroll bar arrow button. 175 \param down true = downward arrow, false = upward arrow 176 \param pressed true if the button should be pressed 177 \param activated true if the button is activated (e.g. mouse hover) 178 \param color the color of the text (COLOR_DEFAULT = default color for this style) 179 \return the new surface (has to be freed by the caller) 180 */ 181 virtual SDL_Surface* createScrollBarArrowButton(bool down, bool pressed, bool activated, Uint32 color = COLOR_DEFAULT); 182 183 184 185 186 /** 187 Returns the minumum height of a list box entry. 188 \return the mimimum height of a list box entry 189 */ 190 virtual Uint32 getListBoxEntryHeight(); 191 192 /** 193 Creates the surface for a list box entry with text as content. 194 \param width the width of the entry 195 \param text the text for this entry 196 \param selected true if a entry should be highlighted 197 \param color the color of the text (COLOR_DEFAULT = default color for this style) 198 \return the new surface (has to be freed by the caller) 199 */ 200 virtual SDL_Surface* createListBoxEntry(Uint32 width, const std::string& text, bool selected, Uint32 color = COLOR_DEFAULT); 201 202 203 204 205 /** 206 Creates the overlay surface for a progress bar widget. This surface is then drawn 207 above the progress bar widget. 208 \param width the width of the progress bar 209 \param height the height of the progress bar 210 \param percent a value between 0.0 and 100.0 211 \param color the color of the overlay (COLOR_DEFAULT = default color for this style) 212 \return the new surface (has to be freed by the caller) 213 */ 214 virtual SDL_Surface* createProgressBarOverlay(Uint32 width, Uint32 height, double percent, Uint32 color = COLOR_DEFAULT); 215 216 217 /** 218 Creates a tool tip surface. 219 \param text the tool tip text 220 \return the new surface (has to be freed by the caller) 221 */ 222 virtual SDL_Surface* createToolTip(const std::string& text); 223 224 /** 225 Creates a simple background for e.g. a window 226 \param width the width of the surface 227 \param height the height of the surface 228 \return the new surface (has to be freed by the caller) 229 */ 230 virtual SDL_Surface* createBackground(Uint32 width, Uint32 height); 231 232 /** 233 Creates a simple background for widgets 234 \param width the width of the surface 235 \param height the height of the surface 236 \return the new surface (has to be freed by the caller) 237 */ 238 virtual SDL_Surface* createWidgetBackground(Uint32 width, Uint32 height); 239 240 /** 241 Get the height of the font specified by fontnum 242 \param FontNum the font 243 \return the height of the font 244 */ 245 virtual unsigned int getTextHeight(unsigned int FontNum); 246 247 /** 248 Get the weidth of the text with the font specified by fontnum 249 \param text the text to get the width from 250 \param FontNum the font 251 \return the width of the text 252 */ 253 virtual unsigned int getTextWidth(const std::string& text, unsigned int FontNum); 254 255 public: 256 static const Uint32 defaultForegroundColor = COLOR_RGB(125,0,0); 257 static const Uint32 defaultShadowColor = COLOR_LIGHTYELLOW; 258 259 static const Uint32 buttonBackgroundColor = COLOR_RGB(202,141,16); 260 static const Uint32 pressedButtonBackgroundColor = COLOR_RGB(182,125,12); 261 static const Uint32 buttonBorderColor = COLOR_RGB(60,36,0); 262 static const Uint32 buttonEdgeBottomRightColor = COLOR_RGB(153,105,0); 263 static const Uint32 buttonEdgeTopLeftColor = COLOR_RGB(255,190,76); 264 265 private: 266 267 /** 268 Creates a surface with text on it 269 \param text text to draw 270 \param color the color of the text 271 \param fontsize the size of the text 272 \return the new created surface (the caller of this method is responsible of freeing it) 273 */ 274 SDL_Surface* createSurfaceWithText(const std::string& text, Uint32 color, unsigned int fontsize); 275 brightenUp(Uint32 color)276 Uint32 brightenUp(Uint32 color) { 277 Uint32 r = (color & RMASK) >> RSHIFT; 278 Uint32 g = (color & GMASK) >> GSHIFT; 279 Uint32 b = (color & BMASK) >> BSHIFT; 280 Uint32 a = (color & AMASK) >> ASHIFT; 281 282 r = std::min(255U, (r*3)/2); 283 g = std::min(255U, (g*3)/2); 284 b = std::min(255U, (b*3)/2); 285 286 return COLOR_RGBA(r,g,b,a); 287 } 288 }; 289 290 #endif // DUNESTYLEBASE_H 291