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 
180  {
181  m_skin_dest_areas_inited = false;
182  m_skin_dest_areas_yflip_inited = false;
183  m_skin_x = -1;
184  m_skin_y = -1;
185  m_skin_w = -1;
186  m_skin_h = -1;
187  m_skin_r = -1;
188  m_skin_g = -1;
189  m_skin_b = -1;
190  } // SkinWidgetContainer
191  }; // class SkinWidgetContainer
192 
193  // ========================================================================
194  class Widget;
195 
203  {
204  video::ITexture* m_image;
205  bool m_y_flip_set;
206 
207  public:
208  int m_left_border, m_right_border, m_top_border, m_bottom_border;
209  bool m_preserve_h_aspect_ratios;
210  float m_hborder_out_portion, m_vborder_out_portion;
211 
212  // this parameter is a bit special since it's the only one that can
213  // change at runtime
214  bool m_vertical_flip;
215 
217  int areas;
218  // possible values in areas
219  static const int BODY = 1;
220  static const int LEFT = 2;
221  static const int RIGHT = 4;
222  static const int TOP = 8;
223  static const int BOTTOM = 16;
224 
225  core::rect<s32> m_source_area_left;
226  core::rect<s32> m_source_area_center;
227  core::rect<s32> m_source_area_right;
228 
229  core::rect<s32> m_source_area_top;
230  core::rect<s32> m_source_area_bottom;
231 
232  core::rect<s32> m_source_area_top_left;
233  core::rect<s32> m_source_area_top_right;
234  core::rect<s32> m_source_area_bottom_left;
235  core::rect<s32> m_source_area_bottom_right;
236 
237 
238  // y-flipped coords
239  core::rect<s32> m_source_area_left_yflip;
240  core::rect<s32> m_source_area_center_yflip;
241  core::rect<s32> m_source_area_right_yflip;
242 
243  core::rect<s32> m_source_area_top_yflip;
244  core::rect<s32> m_source_area_bottom_yflip;
245 
246  core::rect<s32> m_source_area_top_left_yflip;
247  core::rect<s32> m_source_area_top_right_yflip;
248  core::rect<s32> m_source_area_bottom_left_yflip;
249  core::rect<s32> m_source_area_bottom_right_yflip;
250 
251  BoxRenderParams();
252  void setTexture(video::ITexture* image);
253  void calculateYFlipIfNeeded();
254  // --------------------------------------------------------------------
256  video::ITexture* getImage() { return m_image; }
257  }; // BoxRenderParams
258 
259  // ========================================================================
265  class Skin : public gui::IGUISkin
266  {
267  gui::IGUISkin* m_fallback_skin;
268 
269 
270  video::ITexture* m_bg_image;
271  std::vector<Widget*> m_tooltips;
272  std::vector<bool> m_tooltip_at_mouse;
273 
274  LEAK_CHECK()
275 
276  void drawBoxFromStretchableTexture(SkinWidgetContainer* w,
277  const core::rect< s32 > &dest,
278  BoxRenderParams& params,
279  bool deactivated=false,
280  const core::rect<s32>* clipRect=NULL);
281  private:
282  // my utility methods, to work around irrlicht's very
283  // Windows-95-like-look-enforcing skin system
284  void process3DPane(gui::IGUIElement *element,
285  const core::rect< s32 > &rect, const bool pressed);
286  void drawButton(Widget* w, const core::rect< s32 > &rect,
287  const bool pressed, const bool focused);
288  void drawProgress(Widget* w, const core::rect< s32 > &rect,
289  const bool pressed, const bool focused);
290  void drawRatingBar(Widget* w, const core::rect< s32 > &rect,
291  const bool pressed, const bool focused);
292  void drawRibbon(const core::rect< s32 > &rect, Widget* widget,
293  const bool pressed, bool focused);
294  void drawRibbonChild(const core::rect< s32 > &rect, Widget* widget,
295  const bool pressed, bool focused);
296  void drawSpinnerChild(const core::rect< s32 > &rect, Widget* widget,
297  const bool pressed, bool focused);
298  void drawSpinnerBody(const core::rect< s32 > &rect, Widget* widget,
299  const bool pressed, bool focused);
300  void drawGauge(const core::rect< s32 > &rect, Widget* widget,
301  bool focused);
302  void drawGaugeFill(const core::rect< s32 > &rect, Widget* widget,
303  bool focused);
304  void drawCheckBox(const core::rect< s32 > &rect, Widget* widget,
305  bool focused);
306  void drawList(const core::rect< s32 > &rect, Widget* widget,
307  bool focused);
308  void drawListHeader(const core::rect< s32 > &rect, Widget* widget);
309  void drawListSelection(const core::rect< s32 > &rect, Widget* widget,
310  bool focused, const core::rect< s32 > *clip);
311  void drawIconButton(const core::rect< s32 > &rect, Widget* widget,
312  const bool pressed, bool focused);
313  void drawScrollbarBackground(const core::rect< s32 > &rect);
314  void drawScrollbarThumb(const core::rect< s32 > &rect);
315  void drawScrollbarButton(const core::rect< s32 > &rect,
316  const bool pressed, const bool bottomArrow);
317 
318  void drawTooltip(Widget* widget, bool atMouse);
319  irr::video::SColorf getPlayerColor(int player_id);
320 
321  public:
322 
323  // dirty way to have dialogs that zoom in
324  bool m_dialog;
325  float m_dialog_size;
330  Skin(gui::IGUISkin* fallback_skin);
331 
332  ~Skin();
333 
334  static video::SColor getColor(const std::string &name);
335  void renderSections(PtrVector<Widget>* within_vector=NULL);
336  void drawBgImage();
337  void drawBGFadeColor();
338  void drawBadgeOn(const Widget* widget, const core::rect<s32>& rect);
339  void drawProgressBarInScreen(SkinWidgetContainer* swc,
340  const core::rect< s32 > &rect,
341  float progress, bool deactivated = false);
342 
343  // irrlicht's callbacks
344  virtual void draw2DRectangle (gui::IGUIElement *element,
345  const video::SColor &color,
346  const core::rect< s32 > &pos,
347  const core::rect< s32 > *clip);
348  virtual void draw3DButtonPanePressed(gui::IGUIElement *element,
349  const core::rect< s32 > &rect,
350  const core::rect< s32 > *clip);
351  virtual void draw3DButtonPaneStandard(gui::IGUIElement *element,
352  const core::rect< s32 > &rect,
353  const core::rect< s32 > *clip);
354  virtual void draw3DMenuPane (gui::IGUIElement *element,
355  const core::rect< s32 > &rect,
356  const core::rect< s32 > *clip);
357  virtual void draw3DSunkenPane (gui::IGUIElement *element,
358  video::SColor bgcolor,
359  bool flat, bool fillBackGround,
360  const core::rect< s32 > &rect,
361  const core::rect< s32 > *clip);
362  virtual void draw3DTabBody (gui::IGUIElement *element, bool border,
363  bool background,
364  const core::rect< s32 > &rect,
365  const core::rect< s32 > *clip,
366  s32 tabHeight=-1,
367  gui::EGUI_ALIGNMENT alignment=
368  gui::EGUIA_UPPERLEFT);
369  virtual void draw3DTabButton (gui::IGUIElement *element,
370  bool active,
371  const core::rect< s32 > &rect,
372  const core::rect< s32 > *clip,
373  gui::EGUI_ALIGNMENT alignment=
374  gui::EGUIA_UPPERLEFT);
375  virtual void draw3DToolBar (gui::IGUIElement *element,
376  const core::rect< s32 > &rect,
377  const core::rect< s32 > *clip);
378  virtual core::rect< s32 >
379  draw3DWindowBackground(gui::IGUIElement *element,
380  bool drawTitleBar,
381  video::SColor titleBarColor,
382  const core::rect< s32 > &rect,
383  const core::rect< s32 > *clip,
384  core::rect<s32>* checkClientArea=0);
385 
386  virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
387  const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
388  const video::SColor* const colors, bool useAlphaChannelOfTexture);
389 
390  virtual void drawIcon (gui::IGUIElement *element,
391  gui::EGUI_DEFAULT_ICON icon,
392  const core::position2di position,
393  u32 starttime, u32 currenttime,
394  bool loop=false,
395  const core::rect< s32 > *clip=NULL);
396  virtual video::SColor getColor (gui::EGUI_DEFAULT_COLOR color) const;
397  virtual const wchar_t*
398  getDefaultText(gui::EGUI_DEFAULT_TEXT text) const;
399  virtual gui::IGUIFont* getFont(gui::EGUI_DEFAULT_FONT which=
400  gui::EGDF_DEFAULT) const;
401  virtual u32 getIcon (gui::EGUI_DEFAULT_ICON icon) const;
402  virtual s32 getSize (gui::EGUI_DEFAULT_SIZE size) const;
403  const BoxRenderParams& getBoxRenderParams(const std::string &type);
404  virtual gui::IGUISpriteBank * getSpriteBank () const;
405  virtual void setColor (gui::EGUI_DEFAULT_COLOR which,
406  video::SColor newColor);
407  virtual void setDefaultText (gui::EGUI_DEFAULT_TEXT which,
408  const wchar_t* newText);
409  virtual void setFont (gui::IGUIFont *font,
410  gui::EGUI_DEFAULT_FONT which=gui::EGDF_DEFAULT);
411  virtual void setIcon (gui::EGUI_DEFAULT_ICON icon, u32 index);
412  virtual void setSize (gui::EGUI_DEFAULT_SIZE which, s32 size);
413  virtual void setSpriteBank (gui::IGUISpriteBank *bank);
414 
415  void drawTooltips();
416  void drawMessage(SkinWidgetContainer* w, const core::recti &dest,
417  const std::string &type);
418 
419  video::ITexture* getImage(const char* name);
420 
421  gui::IGUISkin* getFallbackSkin() { return m_fallback_skin; }
422 
423  const std::string& getDataPath() const;
424 
425  bool hasIconTheme() const;
426 
427  bool hasFont() const;
428 
429  const std::vector<std::string>& getNormalTTF() const;
430 
431  const std::vector<std::string>& getDigitTTF() const;
432 
433  const std::string& getColorEmojiTTF() const;
434 
435  std::string getThemedIcon(const std::string& relative_path) const;
436  }; // Skin
437 } // guiengine
438 #endif
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
int areas
bitmap containing which areas to render
Definition: skin.hpp:217
Object used to render the GUI widgets see Overview of GUI skin for more information about skinning in...
Definition: skin.hpp:265
video::ITexture * getImage()
Returns the image for this BoxRenderParams.
Definition: skin.hpp:256
irr::gui::ScalableFont * getFont()
Definition: engine.hpp:144
Definition: ptr_vector.hpp:43
class containing render params for the 'drawBoxFromStretchableTexture' function see Overview of GUI s...
Definition: skin.hpp:202
In order to avoid calculating render information every frame, it's stored in a SkinWidgetContainer fo...
Definition: skin.hpp:141
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:138