1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __GUI_SKIN_H_INCLUDED__
\r
6 #define __GUI_SKIN_H_INCLUDED__
\r
8 #include "IrrCompileConfig.h"
\r
9 #ifdef _IRR_COMPILE_WITH_GUI_
\r
11 #include "IGUISkin.h"
\r
12 #include "irrString.h"
\r
14 #include "ITexture.h"
\r
24 class GUISkin : public IGUISkin
\r
27 GUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver *driver);
\r
32 //! returns default color
\r
33 virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const;
\r
35 //! sets a default color
\r
36 virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor);
\r
38 //! returns size for the given size type
\r
39 virtual s32 getSize(EGUI_DEFAULT_SIZE size) const;
\r
41 //! sets a default size
\r
42 virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
\r
44 //! returns the default font
\r
45 virtual IGUIFont *getFont(EGUI_DEFAULT_FONT which = EGDF_DEFAULT) const;
\r
47 //! sets a default font
\r
48 virtual void setFont(IGUIFont *font, EGUI_DEFAULT_FONT which = EGDF_DEFAULT);
\r
50 //! sets the sprite bank used for drawing icons
\r
51 virtual void setSpriteBank(IGUISpriteBank *bank);
\r
53 //! gets the sprite bank used for drawing icons
\r
54 virtual IGUISpriteBank *getSpriteBank() const;
\r
56 //! Returns a default icon
\r
57 /** Returns the sprite index within the sprite bank */
\r
58 virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const;
\r
60 //! Sets a default icon
\r
61 /** Sets the sprite index used for drawing icons like arrows,
\r
62 close buttons and ticks in checkboxes
\r
63 \param icon: Enum specifying which icon to change
\r
64 \param index: The sprite index used to draw this icon */
\r
65 virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index);
\r
67 //! Returns a default text.
\r
68 /** For example for Message box button captions:
\r
69 "OK", "Cancel", "Yes", "No" and so on. */
\r
70 virtual const wchar_t *getDefaultText(EGUI_DEFAULT_TEXT text) const;
\r
72 //! Sets a default text.
\r
73 /** For example for Message box button captions:
\r
74 "OK", "Cancel", "Yes", "No" and so on. */
\r
75 virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t *newText);
\r
77 //! draws a standard 3d button pane
\r
78 /** Used for drawing for example buttons in normal state.
\r
79 It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
\r
80 EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
\r
81 \param rect: Defining area where to draw.
\r
82 \param clip: Clip area.
\r
83 \param element: Pointer to the element which wishes to draw this. This parameter
\r
84 is usually not used by ISkin, but can be used for example by more complex
\r
85 implementations to find out how to draw the part exactly. */
\r
86 virtual void draw3DButtonPaneStandard(IGUIElement *element,
\r
87 const core::rect<s32> &rect, const core::rect<s32> *clip = 0)
\r
89 drawColored3DButtonPaneStandard(element, rect, clip);
\r
92 virtual void drawColored3DButtonPaneStandard(IGUIElement *element,
\r
93 const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
\r
94 const video::SColor *colors = 0);
\r
96 //! draws a pressed 3d button pane
\r
97 /** Used for drawing for example buttons in pressed state.
\r
98 It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
\r
99 EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
\r
100 \param rect: Defining area where to draw.
\r
101 \param clip: Clip area.
\r
102 \param element: Pointer to the element which wishes to draw this. This parameter
\r
103 is usually not used by ISkin, but can be used for example by more complex
\r
104 implementations to find out how to draw the part exactly. */
\r
105 virtual void draw3DButtonPanePressed(IGUIElement *element,
\r
106 const core::rect<s32> &rect, const core::rect<s32> *clip = 0)
\r
108 drawColored3DButtonPanePressed(element, rect, clip);
\r
111 virtual void drawColored3DButtonPanePressed(IGUIElement *element,
\r
112 const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
\r
113 const video::SColor *colors = 0);
\r
115 //! draws a sunken 3d pane
\r
116 /** Used for drawing the background of edit, combo or check boxes.
\r
117 \param element: Pointer to the element which wishes to draw this. This parameter
\r
118 is usually not used by ISkin, but can be used for example by more complex
\r
119 implementations to find out how to draw the part exactly.
\r
120 \param bgcolor: Background color.
\r
121 \param flat: Specifies if the sunken pane should be flat or displayed as sunken
\r
122 deep into the ground.
\r
123 \param rect: Defining area where to draw.
\r
124 \param clip: Clip area. */
\r
125 virtual void draw3DSunkenPane(IGUIElement *element, video::SColor bgcolor,
\r
126 bool flat, bool fillBackGround, const core::rect<s32> &rect,
\r
127 const core::rect<s32> *clip = 0)
\r
129 drawColored3DSunkenPane(
\r
130 element, bgcolor, flat, fillBackGround, rect, clip);
\r
133 virtual void drawColored3DSunkenPane(IGUIElement *element, video::SColor bgcolor,
\r
134 bool flat, bool fillBackGround, const core::rect<s32> &rect,
\r
135 const core::rect<s32> *clip = 0, const video::SColor *colors = 0);
\r
137 //! draws a window background
\r
138 /** Used for drawing the background of dialogs and windows.
\r
139 \param element: Pointer to the element which wishes to draw this. This parameter
\r
140 is usually not used by ISkin, but can be used for example by more complex
\r
141 implementations to find out how to draw the part exactly.
\r
142 \param titleBarColor: Title color.
\r
143 \param drawTitleBar: True to enable title drawing.
\r
144 \param rect: Defining area where to draw.
\r
145 \param clip: Clip area.
\r
146 \param checkClientArea: When set to non-null the function will not draw anything,
\r
147 but will instead return the clientArea which can be used for drawing by the
\r
148 calling window. That is the area without borders and without titlebar. \return
\r
149 Returns rect where it would be good to draw title bar text. This will work even
\r
150 when checkClientArea is set to a non-null value.*/
\r
151 virtual core::rect<s32> draw3DWindowBackground(IGUIElement *element,
\r
152 bool drawTitleBar, video::SColor titleBarColor,
\r
153 const core::rect<s32> &rect, const core::rect<s32> *clip,
\r
154 core::rect<s32> *checkClientArea)
\r
156 return drawColored3DWindowBackground(element, drawTitleBar, titleBarColor,
\r
157 rect, clip, checkClientArea);
\r
160 virtual core::rect<s32> drawColored3DWindowBackground(IGUIElement *element,
\r
161 bool drawTitleBar, video::SColor titleBarColor,
\r
162 const core::rect<s32> &rect, const core::rect<s32> *clip,
\r
163 core::rect<s32> *checkClientArea,
\r
164 const video::SColor *colors = 0);
\r
166 //! draws a standard 3d menu pane
\r
167 /** Used for drawing for menus and context menus.
\r
168 It uses the colors EGDC_3D_DARK_SHADOW, EGDC_3D_HIGH_LIGHT, EGDC_3D_SHADOW and
\r
169 EGDC_3D_FACE for this. See EGUI_DEFAULT_COLOR for details.
\r
170 \param element: Pointer to the element which wishes to draw this. This parameter
\r
171 is usually not used by ISkin, but can be used for example by more complex
\r
172 implementations to find out how to draw the part exactly.
\r
173 \param rect: Defining area where to draw.
\r
174 \param clip: Clip area. */
\r
175 virtual void draw3DMenuPane(IGUIElement *element, const core::rect<s32> &rect,
\r
176 const core::rect<s32> *clip = 0)
\r
178 drawColored3DMenuPane(element, rect, clip);
\r
181 virtual void drawColored3DMenuPane(IGUIElement *element,
\r
182 const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
\r
183 const video::SColor *colors = 0);
\r
185 //! draws a standard 3d tool bar
\r
186 /** Used for drawing for toolbars and menus.
\r
187 \param element: Pointer to the element which wishes to draw this. This parameter
\r
188 is usually not used by ISkin, but can be used for example by more complex
\r
189 implementations to find out how to draw the part exactly.
\r
190 \param rect: Defining area where to draw.
\r
191 \param clip: Clip area. */
\r
192 virtual void draw3DToolBar(IGUIElement *element, const core::rect<s32> &rect,
\r
193 const core::rect<s32> *clip = 0)
\r
195 drawColored3DToolBar(element, rect, clip);
\r
198 virtual void drawColored3DToolBar(IGUIElement *element,
\r
199 const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
\r
200 const video::SColor *colors = 0);
\r
202 //! draws a tab button
\r
203 /** Used for drawing for tab buttons on top of tabs.
\r
204 \param element: Pointer to the element which wishes to draw this. This parameter
\r
205 is usually not used by ISkin, but can be used for example by more complex
\r
206 implementations to find out how to draw the part exactly.
\r
207 \param active: Specifies if the tab is currently active.
\r
208 \param rect: Defining area where to draw.
\r
209 \param clip: Clip area. */
\r
210 virtual void draw3DTabButton(IGUIElement *element, bool active,
\r
211 const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
\r
212 EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT)
\r
214 drawColored3DTabButton(element, active, rect, clip, alignment);
\r
217 virtual void drawColored3DTabButton(IGUIElement *element, bool active,
\r
218 const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
\r
219 EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT,
\r
220 const video::SColor *colors = 0);
\r
222 //! draws a tab control body
\r
223 /** \param element: Pointer to the element which wishes to draw this. This
\r
224 parameter is usually not used by ISkin, but can be used for example by more
\r
225 complex implementations to find out how to draw the part exactly. \param border:
\r
226 Specifies if the border should be drawn. \param background: Specifies if the
\r
227 background should be drawn. \param rect: Defining area where to draw.
\r
228 \param clip: Clip area. */
\r
229 virtual void draw3DTabBody(IGUIElement *element, bool border, bool background,
\r
230 const core::rect<s32> &rect, const core::rect<s32> *clip = 0,
\r
231 s32 tabHeight = -1, EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT)
\r
233 drawColored3DTabBody(element, border, background, rect, clip, tabHeight,
\r
237 virtual void drawColored3DTabBody(IGUIElement *element, bool border,
\r
238 bool background, const core::rect<s32> &rect,
\r
239 const core::rect<s32> *clip = 0, s32 tabHeight = -1,
\r
240 EGUI_ALIGNMENT alignment = EGUIA_UPPERLEFT,
\r
241 const video::SColor *colors = 0);
\r
243 //! draws an icon, usually from the skin's sprite bank
\r
244 /** \param element: Pointer to the element which wishes to draw this icon.
\r
245 This parameter is usually not used by IGUISkin, but can be used for example
\r
246 by more complex implementations to find out how to draw the part exactly.
\r
247 \param icon: Specifies the icon to be drawn.
\r
248 \param position: The position to draw the icon
\r
249 \param starttime: The time at the start of the animation
\r
250 \param currenttime: The present time, used to calculate the frame number
\r
251 \param loop: Whether the animation should loop or not
\r
252 \param clip: Clip area. */
\r
253 virtual void drawIcon(IGUIElement *element, EGUI_DEFAULT_ICON icon,
\r
254 const core::position2di position, u32 starttime = 0,
\r
255 u32 currenttime = 0, bool loop = false,
\r
256 const core::rect<s32> *clip = 0)
\r
258 drawColoredIcon(element, icon, position, starttime, currenttime, loop,
\r
262 virtual void drawColoredIcon(IGUIElement *element, EGUI_DEFAULT_ICON icon,
\r
263 const core::position2di position, u32 starttime = 0,
\r
264 u32 currenttime = 0, bool loop = false,
\r
265 const core::rect<s32> *clip = 0, const video::SColor *colors = 0);
\r
267 //! draws a 2d rectangle.
\r
268 /** \param element: Pointer to the element which wishes to draw this icon.
\r
269 This parameter is usually not used by IGUISkin, but can be used for example
\r
270 by more complex implementations to find out how to draw the part exactly.
\r
271 \param color: Color of the rectangle to draw. The alpha component specifies how
\r
272 transparent the rectangle will be.
\r
273 \param pos: Position of the rectangle.
\r
274 \param clip: Pointer to rectangle against which the rectangle will be clipped.
\r
275 If the pointer is null, no clipping will be performed. */
\r
276 virtual void draw2DRectangle(IGUIElement *element, const video::SColor &color,
\r
277 const core::rect<s32> &pos, const core::rect<s32> *clip = 0);
\r
279 //! get the type of this skin
\r
280 virtual EGUI_SKIN_TYPE getType() const;
\r
282 //! Writes attributes of the object.
\r
283 //! Implement this to expose the attributes of your scene node animator for
\r
284 //! scripting languages, editors, debuggers or xml serialization purposes.
\r
285 virtual void serializeAttributes(io::IAttributes *out,
\r
286 io::SAttributeReadWriteOptions *options = 0) const;
\r
288 //! Reads attributes of the object.
\r
289 //! Implement this to set the attributes of your scene node animator for
\r
290 //! scripting languages, editors, debuggers or xml deserialization purposes.
\r
291 virtual void deserializeAttributes(
\r
292 io::IAttributes *in, io::SAttributeReadWriteOptions *options = 0);
\r
294 //! gets the colors
\r
295 virtual void getColors(video::SColor *colors); // ::PATCH:
\r
298 video::SColor Colors[EGDC_COUNT];
\r
299 s32 Sizes[EGDS_COUNT];
\r
300 u32 Icons[EGDI_COUNT];
\r
301 IGUIFont *Fonts[EGDF_COUNT];
\r
302 IGUISpriteBank *SpriteBank;
\r
303 core::stringw Texts[EGDT_COUNT];
\r
304 video::IVideoDriver *Driver;
\r
307 EGUI_SKIN_TYPE Type;
\r
310 #define set3DSkinColors(skin, button_color) \
\r
312 skin->setColor(EGDC_3D_FACE, button_color); \
\r
313 skin->setColor(EGDC_3D_DARK_SHADOW, button_color, 0.25f); \
\r
314 skin->setColor(EGDC_3D_SHADOW, button_color, 0.5f); \
\r
315 skin->setColor(EGDC_3D_LIGHT, button_color); \
\r
316 skin->setColor(EGDC_3D_HIGH_LIGHT, button_color, 1.5f); \
\r
319 #define getElementSkinColor(color) \
\r
322 IGUISkin *skin = Environment->getSkin(); \
\r
324 return skin->getColor(color); \
\r
326 return Colors[color]; \
\r
329 #define setElementSkinColor(which, newColor, shading) \
\r
332 Colors = new video::SColor[EGDC_COUNT]; \
\r
333 GUISkin *skin = (GUISkin *)Environment->getSkin(); \
\r
335 skin->getColors(Colors); \
\r
337 Colors[which] = newColor; \
\r
338 setShading(Colors[which], shading); \
\r
340 } // end namespace gui
\r
341 //! Sets the shading
\r
342 inline void setShading(video::SColor &color, f32 s) // :PATCH:
\r
345 color.setRed(color.getRed() * s);
\r
346 color.setGreen(color.getGreen() * s);
\r
347 color.setBlue(color.getBlue() * s);
\r
348 } else if (s > 1.0f) {
\r
351 color.setRed(color.getRed() + (255 - color.getRed()) * s);
\r
352 color.setGreen(color.getGreen() + (255 - color.getGreen()) * s);
\r
353 color.setBlue(color.getBlue() + (255 - color.getBlue()) * s);
\r
356 } // end namespace irr
\r
358 #endif // _IRR_COMPILE_WITH_GUI_
\r