SuperTuxKart
Loading...
Searching...
No Matches
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>
29namespace irr
30{
31 namespace video { class ITexture; }
32 namespace gui { class IGUIElement; class IGUIFont; class IGUISpriteBank; }
33}
34
35using namespace irr;
36
37
38#include "utils/leak_check.hpp"
39#include "utils/ptr_vector.hpp"
40
133namespace 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 float m_horizontal_inner_padding, m_vertical_inner_padding;
212 float m_horizontal_margin, m_vertical_margin;
213
214 // this parameter is a bit special since it's the only one that can
215 // change at runtime
216 bool m_vertical_flip;
217
219 int areas;
220 // possible values in areas
221 static const int BODY = 1;
222 static const int LEFT = 2;
223 static const int RIGHT = 4;
224 static const int TOP = 8;
225 static const int BOTTOM = 16;
226 static const int ALL = BODY+LEFT+RIGHT+TOP+BOTTOM;
227
228 core::rect<s32> m_source_area_left;
229 core::rect<s32> m_source_area_center;
230 core::rect<s32> m_source_area_right;
231
232 core::rect<s32> m_source_area_top;
233 core::rect<s32> m_source_area_bottom;
234
235 core::rect<s32> m_source_area_top_left;
236 core::rect<s32> m_source_area_top_right;
237 core::rect<s32> m_source_area_bottom_left;
238 core::rect<s32> m_source_area_bottom_right;
239
240
241 // y-flipped coords
242 core::rect<s32> m_source_area_left_yflip;
243 core::rect<s32> m_source_area_center_yflip;
244 core::rect<s32> m_source_area_right_yflip;
245
246 core::rect<s32> m_source_area_top_yflip;
247 core::rect<s32> m_source_area_bottom_yflip;
248
249 core::rect<s32> m_source_area_top_left_yflip;
250 core::rect<s32> m_source_area_top_right_yflip;
251 core::rect<s32> m_source_area_bottom_left_yflip;
252 core::rect<s32> m_source_area_bottom_right_yflip;
253
255 void setTexture(video::ITexture* image);
256 void calculateYFlipIfNeeded();
257 // --------------------------------------------------------------------
259 video::ITexture* getImage() { return m_image; }
260 }; // BoxRenderParams
261
262 // ========================================================================
268 class Skin : public gui::IGUISkin
269 {
270 gui::IGUISkin* m_fallback_skin;
271
272
273 video::ITexture* m_bg_image;
274 std::vector<Widget*> m_tooltips;
275 std::vector<bool> m_tooltip_at_mouse;
276
277 LEAK_CHECK()
278
279 void drawBoxFromStretchableTexture(SkinWidgetContainer* w,
280 const core::rect< s32 > &dest,
281 BoxRenderParams& params,
282 bool deactivated=false,
283 const core::rect<s32>* clipRect=NULL);
284 private:
285 // my utility methods, to work around irrlicht's very
286 // Windows-95-like-look-enforcing skin system
287 void process3DPane(gui::IGUIElement *element,
288 const core::rect< s32 > &rect, const bool pressed);
289 void drawButton(Widget* w, const core::rect< s32 > &rect,
290 const bool pressed, const bool focused);
291 void drawProgress(Widget* w, const core::rect< s32 > &rect,
292 const bool pressed, const bool focused);
293 void drawRatingBar(Widget* w, const core::rect< s32 > &rect,
294 const bool pressed, const bool focused);
295 void drawRibbon(const core::rect< s32 > &rect, Widget* widget,
296 const bool pressed, bool focused);
297 void drawRibbonChild(const core::rect< s32 > &rect, Widget* widget,
298 const bool pressed, bool focused);
299 void drawSpinnerChild(const core::rect< s32 > &rect, Widget* widget,
300 const bool pressed, bool focused);
301 void drawSpinnerBody(const core::rect< s32 > &rect, Widget* widget,
302 const bool pressed, bool focused);
303 void drawGauge(const core::rect< s32 > &rect, Widget* widget,
304 bool focused);
305 void drawGaugeFill(const core::rect< s32 > &rect, Widget* widget,
306 bool focused);
307 void drawCheckBox(const core::rect< s32 > &rect, Widget* widget,
308 bool focused);
309 void drawList(const core::rect< s32 > &rect, Widget* widget,
310 bool focused);
311 void drawListHeader(const core::rect< s32 > &rect, Widget* widget);
312 void drawListSelection(const core::rect< s32 > &rect, Widget* widget,
313 bool focused, const core::rect< s32 > *clip);
314 void drawIconButton(const core::rect< s32 > &rect, Widget* widget,
315 const bool pressed, bool focused);
316 void drawScrollbarBackground(const core::rect< s32 > &rect);
317 void drawScrollbarThumb(const core::rect< s32 > &rect);
318 void drawScrollbarButton(const core::rect< s32 > &rect,
319 const bool pressed, const bool bottomArrow);
320
321 void drawTooltip(Widget* widget, bool atMouse);
322 irr::video::SColorf getPlayerColor(int player_id);
323
324 public:
325
326 // dirty way to have dialogs that zoom in
327 bool m_dialog;
328 float m_dialog_size;
333 Skin(gui::IGUISkin* fallback_skin);
334
335 ~Skin();
336
337 void resetBackgroundImage() { m_bg_image = NULL; }
338 static video::SColor getColor(const std::string &name);
339 void renderSections(PtrVector<Widget>* within_vector=NULL);
340 void drawBgImage();
341 void drawBGFadeColor();
342 void drawBadgeOn(const Widget* widget, const core::rect<s32>& rect);
343 void drawProgressBarInScreen(SkinWidgetContainer* swc,
344 const core::rect< s32 > &rect,
345 float progress, bool deactivated = false);
346
347 // irrlicht's callbacks
348 virtual void draw2DRectangle (gui::IGUIElement *element,
349 const video::SColor &color,
350 const core::rect< s32 > &pos,
351 const core::rect< s32 > *clip);
352 virtual void draw3DButtonPanePressed(gui::IGUIElement *element,
353 const core::rect< s32 > &rect,
354 const core::rect< s32 > *clip);
355 virtual void draw3DButtonPaneStandard(gui::IGUIElement *element,
356 const core::rect< s32 > &rect,
357 const core::rect< s32 > *clip);
358 virtual void draw3DMenuPane (gui::IGUIElement *element,
359 const core::rect< s32 > &rect,
360 const core::rect< s32 > *clip);
361 virtual void draw3DSunkenPane (gui::IGUIElement *element,
362 video::SColor bgcolor,
363 bool flat, bool fillBackGround,
364 const core::rect< s32 > &rect,
365 const core::rect< s32 > *clip);
366 virtual void draw3DTabBody (gui::IGUIElement *element, bool border,
367 bool background,
368 const core::rect< s32 > &rect,
369 const core::rect< s32 > *clip,
370 s32 tabHeight=-1,
371 gui::EGUI_ALIGNMENT alignment=
372 gui::EGUIA_UPPERLEFT);
373 virtual void draw3DTabButton (gui::IGUIElement *element,
374 bool active,
375 const core::rect< s32 > &rect,
376 const core::rect< s32 > *clip,
377 gui::EGUI_ALIGNMENT alignment=
378 gui::EGUIA_UPPERLEFT);
379 virtual void draw3DToolBar (gui::IGUIElement *element,
380 const core::rect< s32 > &rect,
381 const core::rect< s32 > *clip);
382 virtual core::rect< s32 >
383 draw3DWindowBackground(gui::IGUIElement *element,
384 bool drawTitleBar,
385 video::SColor titleBarColor,
386 const core::rect< s32 > &rect,
387 const core::rect< s32 > *clip,
388 core::rect<s32>* checkClientArea=0);
389
390 virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
391 const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
392 const video::SColor* const colors, bool useAlphaChannelOfTexture);
393
394 virtual void drawIcon (gui::IGUIElement *element,
395 gui::EGUI_DEFAULT_ICON icon,
396 const core::position2di position,
397 u32 starttime, u32 currenttime,
398 bool loop=false,
399 const core::rect< s32 > *clip=NULL);
400 virtual video::SColor getColor (gui::EGUI_DEFAULT_COLOR color) const;
401 virtual const wchar_t*
402 getDefaultText(gui::EGUI_DEFAULT_TEXT text) const;
403 virtual gui::IGUIFont* getFont(gui::EGUI_DEFAULT_FONT which=
404 gui::EGDF_DEFAULT) const;
405 virtual u32 getIcon (gui::EGUI_DEFAULT_ICON icon) const;
406 virtual s32 getSize (gui::EGUI_DEFAULT_SIZE size) const;
407 const BoxRenderParams& getBoxRenderParams(const std::string &type);
408 virtual gui::IGUISpriteBank * getSpriteBank () const;
409 virtual void setColor (gui::EGUI_DEFAULT_COLOR which,
410 video::SColor newColor);
411 virtual void setDefaultText (gui::EGUI_DEFAULT_TEXT which,
412 const wchar_t* newText);
413 virtual void setFont (gui::IGUIFont *font,
414 gui::EGUI_DEFAULT_FONT which=gui::EGDF_DEFAULT);
415 virtual void setIcon (gui::EGUI_DEFAULT_ICON icon, u32 index);
416 virtual void setSize (gui::EGUI_DEFAULT_SIZE which, s32 size);
417 virtual void setSpriteBank (gui::IGUISpriteBank *bank);
418
419 void drawTooltips();
420 void drawMessage(SkinWidgetContainer* w, const core::recti &dest,
421 const std::string &type);
422
423 video::ITexture* getImage(const char* name);
424
425 gui::IGUISkin* getFallbackSkin() { return m_fallback_skin; }
426
427 bool hasIconTheme() const;
428
429 bool hasFont() const;
430
431 const std::vector<std::string>& getNormalTTF() const;
432
433 const std::vector<std::string>& getDigitTTF() const;
434
435 const std::string& getColorEmojiTTF() const;
436
437 std::string getThemedIcon(const std::string& relative_path) const;
438
439 float getScalingFactor(std::string params, float height);
440 }; // Skin
441} // guiengine
442
443namespace SkinConfig
444{
445 enum options {
446 MARGIN,
447 BORDER,
448 PADDING,
449 TOP,
450 BOTTOM,
451 LEFT,
452 RIGHT,
453 HORIZONTAL,
454 VERTICAL
455 };
456 float getVerticalInnerPadding(int wtype, GUIEngine::Widget* widget);
457 float getHorizontalInnerPadding(int wtype, GUIEngine::Widget* widget);
458 float getInnerPadding(int wtype, int rtype, int axis);
459 float getValue(int value_type, int widget_type, int ribbon_type, int axis);
460}
461#endif
class containing render params for the 'drawBoxFromStretchableTexture' function see Overview of GUI s...
Definition: skin.hpp:203
int areas
bitmap containing which areas to render
Definition: skin.hpp:219
video::ITexture * getImage()
Returns the image for this BoxRenderParams.
Definition: skin.hpp:259
BoxRenderParams()
load default values
Definition: skin.cpp:445
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:269
const BoxRenderParams & getBoxRenderParams(const std::string &type)
Returns the BoxRenderParams data structure for a given type.
Definition: skin.cpp:663
void drawRatingBar(Widget *w, const core::rect< s32 > &rect, const bool pressed, const bool focused)
Definition: skin.cpp:1131
void drawButton(Widget *w, const core::rect< s32 > &rect, const bool pressed, const bool focused)
Definition: skin.cpp:1003
void drawMessage(SkinWidgetContainer *w, const core::recti &dest, const std::string &type)
Draws a background box for an in-game notification message.
Definition: skin.cpp:675
void drawListSelection(const core::rect< s32 > &rect, Widget *widget, bool focused, const core::rect< s32 > *clip)
Definition: skin.cpp:2035
void renderSections(PtrVector< Widget > *within_vector=NULL)
recursive function to render all sections (recursion allows to easily traverse the tree of children a...
Definition: skin.cpp:2085
void drawCheckBox(const core::rect< s32 > &rect, Widget *widget, bool focused)
Definition: skin.cpp:1938
void drawListHeader(const core::rect< s32 > &rect, Widget *widget)
Definition: skin.cpp:2047
void drawProgress(Widget *w, const core::rect< s32 > &rect, const bool pressed, const bool focused)
Definition: skin.cpp:1075
void drawSpinnerBody(const core::rect< s32 > &rect, Widget *widget, const bool pressed, bool focused)
Definition: skin.cpp:1578
void drawSpinnerChild(const core::rect< s32 > &rect, Widget *widget, const bool pressed, bool focused)
Definition: skin.cpp:1763
void drawRibbonChild(const core::rect< s32 > &rect, Widget *widget, const bool pressed, bool focused)
Definition: skin.cpp:1222
void drawList(const core::rect< s32 > &rect, Widget *widget, bool focused)
Definition: skin.cpp:2022
void drawIconButton(const core::rect< s32 > &rect, Widget *widget, const bool pressed, bool focused)
Definition: skin.cpp:1806
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:143
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:57