guiSkin.h 14 KB

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