SuperTuxKart
skin.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2009-2015 Marianne Gagnon
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (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.
13 //
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.
17 
18 
19 #ifndef HEADER_SKIN_HPP
20 #define HEADER_SKIN_HPP
21 
22 #include <string>
23 
24 #include <rect.h>
25 #include <SColor.h>
26 #include <vector2d.h>
27 #include <dimension2d.h>
28 #include <IGUISkin.h>
29 namespace irr
30 {
31  namespace video { class ITexture; }
32  namespace gui { class IGUIElement; class IGUIFont; class IGUISpriteBank; }
33 }
34 
35 using namespace irr;
36 
37 
38 #include "utils/leak_check.hpp"
39 #include "utils/ptr_vector.hpp"
40 
133 namespace GUIEngine
134 {
142  {
143  public:
144  int m_skin_x, m_skin_y, m_skin_w, m_skin_h;
145 
146  bool m_skin_dest_areas_inited;
147  bool m_skin_dest_areas_yflip_inited;
148  int m_skin_dest_x, m_skin_dest_y, m_skin_dest_x2, m_skin_dest_y2;
149 
150  // see comments in Skin::drawBoxFromStretchableTexture for
151  // explaination of what these are
152  core::rect<s32> m_skin_dest_area_left;
153  core::rect<s32> m_skin_dest_area_center;
154  core::rect<s32> m_skin_dest_area_right;
155 
156  core::rect<s32> m_skin_dest_area_top;
157  core::rect<s32> m_skin_dest_area_bottom;
158 
159  core::rect<s32> m_skin_dest_area_top_left;
160  core::rect<s32> m_skin_dest_area_top_right;
161  core::rect<s32> m_skin_dest_area_bottom_left;
162  core::rect<s32> m_skin_dest_area_bottom_right;
163 
164  // y flip
165  core::rect<s32> m_skin_dest_area_left_yflip;
166  core::rect<s32> m_skin_dest_area_center_yflip;
167  core::rect<s32> m_skin_dest_area_right_yflip;
168 
169  core::rect<s32> m_skin_dest_area_top_yflip;
170  core::rect<s32> m_skin_dest_area_bottom_yflip;
171 
172  core::rect<s32> m_skin_dest_area_top_left_yflip;
173  core::rect<s32> m_skin_dest_area_top_right_yflip;
174  core::rect<s32> m_skin_dest_area_bottom_left_yflip;
175  core::rect<s32> m_skin_dest_area_bottom_right_yflip;
176 
177  short m_skin_r, m_skin_g, m_skin_b;
178 
179  SkinWidgetContainer *m_next;
180 
182  {
183  m_skin_dest_areas_inited = false;
184  m_skin_dest_areas_yflip_inited = false;
185  m_skin_x = -1;
186  m_skin_y = -1;
187  m_skin_w = -1;
188  m_skin_h = -1;
189  m_skin_r = -1;
190  m_skin_g = -1;
191  m_skin_b = -1;
192  m_next = nullptr;
193  } // SkinWidgetContainer
194 
196  {
197  if (m_next != nullptr)
198  {
199  delete m_next;
200  }
201  }
202  }; // class SkinWidgetContainer
203 
204  // ========================================================================
205  class Widget;
206 
214  {
215  video::ITexture* m_image;
216  bool m_y_flip_set;
217 
218  public:
219  int m_left_border, m_right_border, m_top_border, m_bottom_border;
220  bool m_preserve_h_aspect_ratios;
221  float m_hborder_out_portion, m_vborder_out_portion;
222  float m_horizontal_inner_padding, m_vertical_inner_padding;
223  float m_horizontal_margin, m_vertical_margin;
224 
225  // this parameter is a bit special since it's the only one that can
226  // change at runtime
227  bool m_vertical_flip;
228 
230  int areas;
231  // possible values in areas
232  static const int BODY = 1;
233  static const int LEFT = 2;
234  static const int RIGHT = 4;
235  static const int TOP = 8;
236  static const int BOTTOM = 16;
237  static const int ALL = BODY+LEFT+RIGHT+TOP+BOTTOM;
238 
239  core::rect<s32> m_source_area_left;
240  core::rect<s32> m_source_area_center;
241  core::rect<s32> m_source_area_right;
242 
243  core::rect<s32> m_source_area_top;
244  core::rect<s32> m_source_area_bottom;
245 
246  core::rect<s32> m_source_area_top_left;
247  core::rect<s32> m_source_area_top_right;
248  core::rect<s32> m_source_area_bottom_left;
249  core::rect<s32> m_source_area_bottom_right;
250 
251 
252  // y-flipped coords
253  core::rect<s32> m_source_area_left_yflip;
254  core::rect<s32> m_source_area_center_yflip;
255  core::rect<s32> m_source_area_right_yflip;
256 
257  core::rect<s32> m_source_area_top_yflip;
258  core::rect<s32> m_source_area_bottom_yflip;
259 
260  core::rect<s32> m_source_area_top_left_yflip;
261  core::rect<s32> m_source_area_top_right_yflip;
262  core::rect<s32> m_source_area_bottom_left_yflip;
263  core::rect<s32> m_source_area_bottom_right_yflip;
264 
265  BoxRenderParams();
266  void setTexture(video::ITexture* image);
267  void calculateYFlipIfNeeded();
268  // --------------------------------------------------------------------
270  video::ITexture* getImage() { return m_image; }
271  }; // BoxRenderParams
272 
273  // ========================================================================
279  class Skin : public gui::IGUISkin
280  {
281  gui::IGUISkin* m_fallback_skin;
282 
283  video::ITexture* m_bg_image;
284  std::vector<Widget*> m_tooltips;
285  std::vector<bool> m_tooltip_at_mouse;
286 
287  // The paths to the folder of the active skin and its base themes
288  std::vector<std::string> m_skin_paths;
289 
290  LEAK_CHECK()
291 
292  void drawBoxFromStretchableTexture(SkinWidgetContainer* w,
293  const core::rect< s32 > &dest,
294  BoxRenderParams& params,
295  bool deactivated=false,
296  const core::rect<s32>* clipRect=NULL);
297  private:
298  // my utility methods, to work around irrlicht's very
299  // Windows-95-like-look-enforcing skin system
300  void process3DPane(gui::IGUIElement *element,
301  const core::rect< s32 > &rect, const bool pressed);
302  void drawButton(Widget* w, const core::rect< s32 > &rect,
303  const bool pressed, const bool focused);
304  void drawProgress(Widget* w, const core::rect< s32 > &rect,
305  const bool pressed, const bool focused);
306  void drawRatingBar(Widget* w, const core::rect< s32 > &rect,
307  const bool pressed, const bool focused);
308  void drawRibbon(const core::rect< s32 > &rect, Widget* widget,
309  const bool pressed, bool focused);
310  void drawRibbonChild(const core::rect< s32 > &rect, Widget* widget,
311  const bool pressed, bool focused);
312  void drawSpinnerChild(const core::rect< s32 > &rect, Widget* widget,
313  const bool pressed, bool focused);
314  void drawSpinnerBody(const core::rect< s32 > &rect, Widget* widget,
315  const bool pressed, bool focused);
316  void drawGauge(const core::rect< s32 > &rect, Widget* widget,
317  bool focused);
318  void drawGaugeFill(const core::rect< s32 > &rect, Widget* widget,
319  bool focused);
320  void drawCheckBox(const core::rect< s32 > &rect, Widget* widget,
321  bool focused);
322  void drawList(const core::rect< s32 > &rect, Widget* widget,
323  bool focused);
324  void drawListHeader(const core::rect< s32 > &rect, Widget* widget);
325  void drawListSelection(const core::rect< s32 > &rect, Widget* widget,
326  bool focused, const core::rect< s32 > *clip);
327  void drawIconButton(const core::rect< s32 > &rect, Widget* widget,
328  const bool pressed, bool focused);
329  void drawScrollbarBackground(const core::rect< s32 > &rect);
330  void drawScrollbarThumb(const core::rect< s32 > &rect);
331  void drawScrollbarButton(const core::rect< s32 > &rect,
332  const bool pressed, const bool bottomArrow);
333 
334  void drawTooltip(Widget* widget, bool atMouse);
335  irr::video::SColorf getPlayerColor(int player_id);
336 
337  public:
338 
339  // dirty way to have dialogs that zoom in
340  bool m_dialog;
341  float m_dialog_size;
346  Skin(gui::IGUISkin* fallback_skin);
347 
348  ~Skin();
349 
350  void chainLoad(std::string skin_id);
351  void resetBackgroundImage() { m_bg_image = NULL; }
352  static video::SColor getColor(const std::string &name);
353  void renderSections(PtrVector<Widget>* within_vector=NULL);
354  void drawBgImage();
355  void drawBGFadeColor();
356  void drawBadgeOn(const Widget* widget, const core::rect<s32>& rect);
357  void drawProgressBarInScreen(SkinWidgetContainer* swc,
358  const core::rect< s32 > &rect,
359  float progress, bool deactivated = false);
360 
361  // irrlicht's callbacks
362  virtual void draw2DRectangle (gui::IGUIElement *element,
363  const video::SColor &color,
364  const core::rect< s32 > &pos,
365  const core::rect< s32 > *clip);
366  virtual void draw3DButtonPanePressed(gui::IGUIElement *element,
367  const core::rect< s32 > &rect,
368  const core::rect< s32 > *clip);
369  virtual void draw3DButtonPaneStandard(gui::IGUIElement *element,
370  const core::rect< s32 > &rect,
371  const core::rect< s32 > *clip);
372  virtual void draw3DMenuPane (gui::IGUIElement *element,
373  const core::rect< s32 > &rect,
374  const core::rect< s32 > *clip);
375  virtual void draw3DSunkenPane (gui::IGUIElement *element,
376  video::SColor bgcolor,
377  bool flat, bool fillBackGround,
378  const core::rect< s32 > &rect,
379  const core::rect< s32 > *clip);
380  virtual void draw3DTabBody (gui::IGUIElement *element, bool border,
381  bool background,
382  const core::rect< s32 > &rect,
383  const core::rect< s32 > *clip,
384  s32 tabHeight=-1,
385  gui::EGUI_ALIGNMENT alignment=
386  gui::EGUIA_UPPERLEFT);
387  virtual void draw3DTabButton (gui::IGUIElement *element,
388  bool active,
389  const core::rect< s32 > &rect,
390  const core::rect< s32 > *clip,
391  gui::EGUI_ALIGNMENT alignment=
392  gui::EGUIA_UPPERLEFT);
393  virtual void draw3DToolBar (gui::IGUIElement *element,
394  const core::rect< s32 > &rect,
395  const core::rect< s32 > *clip);
396  virtual core::rect< s32 >
397  draw3DWindowBackground(gui::IGUIElement *element,
398  bool drawTitleBar,
399  video::SColor titleBarColor,
400  const core::rect< s32 > &rect,
401  const core::rect< s32 > *clip,
402  core::rect<s32>* checkClientArea=0);
403 
404  virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
405  const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
406  const video::SColor* const colors, bool useAlphaChannelOfTexture);
407 
408  virtual void drawIcon (gui::IGUIElement *element,
409  gui::EGUI_DEFAULT_ICON icon,
410  const core::position2di position,
411  u32 starttime, u32 currenttime,
412  bool loop=false,
413  const core::rect< s32 > *clip=NULL);
414  virtual video::SColor getColor (gui::EGUI_DEFAULT_COLOR color) const;
415  virtual const wchar_t*
416  getDefaultText(gui::EGUI_DEFAULT_TEXT text) const;
417  virtual gui::IGUIFont* getFont(gui::EGUI_DEFAULT_FONT which=
418  gui::EGDF_DEFAULT) const;
419  virtual u32 getIcon (gui::EGUI_DEFAULT_ICON icon) const;
420  virtual s32 getSize (gui::EGUI_DEFAULT_SIZE size) const;
421  const BoxRenderParams& getBoxRenderParams(const std::string &type);
422  virtual gui::IGUISpriteBank * getSpriteBank () const;
423  virtual void setColor (gui::EGUI_DEFAULT_COLOR which,
424  video::SColor newColor);
425  virtual void setDefaultText (gui::EGUI_DEFAULT_TEXT which,
426  const wchar_t* newText);
427  virtual void setFont (gui::IGUIFont *font,
428  gui::EGUI_DEFAULT_FONT which=gui::EGDF_DEFAULT);
429  virtual void setIcon (gui::EGUI_DEFAULT_ICON icon, u32 index);
430  virtual void setSize (gui::EGUI_DEFAULT_SIZE which, s32 size);
431  virtual void setSpriteBank (gui::IGUISpriteBank *bank);
432 
433  void drawTooltips();
434  void drawMessage(SkinWidgetContainer* w, const core::recti &dest,
435  const std::string &type);
436 
437  video::ITexture* getImage(const char* name);
438 
439  gui::IGUISkin* getFallbackSkin() { return m_fallback_skin; }
440 
441  bool hasIconTheme() const;
442 
443  bool hasFont() const;
444 
445  const std::vector<std::string>& getNormalTTF() const;
446 
447  const std::vector<std::string>& getDigitTTF() const;
448 
449  const std::string& getColorEmojiTTF() const;
450 
451  std::string getThemedIcon(const std::string& relative_path) const;
452 
453  float getScalingFactor(std::string params, float height);
454  }; // Skin
455 } // guiengine
456 
457 namespace SkinConfig
458 {
459  enum options {
460  MARGIN,
461  BORDER,
462  PADDING,
463  TOP,
464  BOTTOM,
465  LEFT,
466  RIGHT,
467  HORIZONTAL,
468  VERTICAL
469  };
470  float getVerticalInnerPadding(int wtype, GUIEngine::Widget* widget);
471  float getHorizontalInnerPadding(int wtype, GUIEngine::Widget* widget);
472  float getInnerPadding(int wtype, int rtype, int axis);
473  float getValue(int value_type, int widget_type, int ribbon_type, int axis);
474 }
475 #endif
class containing render params for the 'drawBoxFromStretchableTexture' function see Overview of GUI s...
Definition: skin.hpp:214
int areas
bitmap containing which areas to render
Definition: skin.hpp:230
video::ITexture * getImage()
Returns the image for this BoxRenderParams.
Definition: skin.hpp:270
In order to avoid calculating render information every frame, it's stored in a SkinWidgetContainer fo...
Definition: skin.hpp:142
Object used to render the GUI widgets see Overview of GUI skin for more information about skinning in...
Definition: skin.hpp:280
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:147
Definition: ptr_vector.hpp:44
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
irr::gui::ScalableFont * getFont()
Definition: engine.hpp:146
Small utility to read config file info from a XML file.
Definition: skin.cpp:65