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