Posted By


xterminhate on 03/09/13

Tagged


Statistics


Viewed 58 times
Favorited by 0 user(s)

CGUIAdvancedWindow.h


/ Published in: C++
Save to your folder(s)

A new custom GUI Element, based on the Irrlicht GUI Window, with these features :
- Close behavior (nothing, remove, set visible false),
- Configurable system buttons,
- Minimize button,
- Double click on minimized window maximizes it,
- Restore button shows up when window is minimized,
- Pinned button, to prevent moving the window,
- Programmable user buttons, with attributes (show/hide for each window state) and user sprite bank, posting event catched by the user defined EventReceiver,
- Double click on window bar hides window client area,
- Window frame renderer using cursor coordinates as light source) and default/user skin.
- Configurable minimized window position,
- Flag preventing window minimizing,
- Notification system, making the tittle bar to blink.


Copy this code and paste it in your HTML
  1. // Xterminhate
  2.  
  3. #ifndef __C_GUI_WINDOW_H_INCLUDED__
  4. #define __C_GUI_WINDOW_H_INCLUDED__
  5.  
  6. #include "IrrCompileConfig.h"
  7. //#ifdef _IRR_COMPILE_WITH_GUI_
  8.  
  9. #include "IGUIWindow.h"
  10. #include "IGUISkin.h"
  11. #include "ICursorControl.h"
  12.  
  13. namespace irr
  14. {
  15. namespace gui
  16. {
  17. //! Window button types
  18. enum EWINDOW_BUTTON_TYPE
  19. {
  20. //! close button
  21. EWBT_CLOSE,
  22.  
  23. //! maximize button
  24. EWBT_MINIMIZE,
  25.  
  26. //! pin button
  27. EWBT_PIN,
  28.  
  29. //! user defined button
  30. EWBT_USER_DEFINED
  31. };
  32. //! Window Close behavior.
  33. //! Default is EWC_REMOVE
  34. enum EWINDOW_CLOSE
  35. {
  36. //! do nothing - window stays open
  37. EWC_IGNORE = 0,
  38.  
  39. //! remove the gui element
  40. EWC_REMOVE = 1,
  41.  
  42. //! call setVisible(false)
  43. EWC_HIDE = 2
  44.  
  45. // next is 4
  46. };
  47.  
  48. class IGUIButton;
  49.  
  50. class CGUIAdvancedWindow : public IGUIElement //: public IGUIWindow
  51. {
  52. public:
  53.  
  54. //!
  55. struct buttoninfo
  56. {
  57. EWINDOW_BUTTON_TYPE Type;
  58. IGUISpriteBank* Sprite; //! Button Icon
  59. s32 SpriteIndex; //! Button Icon
  60. bool VisibleWhenNormal; //! Button is visible when window is in normal state
  61. bool VisibleWhenBar; //! Button is visible when window is in bar state
  62. bool VisibleWhenMinimized; //! Button is visible when window is in minimized state
  63. s32 UserEventId; //! ID sent to user event receiver
  64. const wchar_t* Name; //! Button Text
  65. const wchar_t* ToolTipText; //! Button Tooltip Text
  66. };
  67.  
  68. //! constructor
  69. CGUIAdvancedWindow(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle,
  70. const core::array<buttoninfo>& buttons, EWINDOW_CLOSE close, const core::position2di& minimized,
  71. ICursorControl* cursor = 0 );
  72.  
  73. //! destructor
  74. virtual ~CGUIAdvancedWindow();
  75.  
  76. //! called if an event happened.
  77. virtual bool OnEvent(const SEvent& event);
  78.  
  79. //! update absolute position
  80. virtual void updateAbsolutePosition();
  81.  
  82. //! draws the element and its children
  83. virtual void draw();
  84.  
  85. //! Returns true if the window is minimized, false if not
  86. virtual bool isMinimized() const;
  87.  
  88. //! Sets whether the window is minimized
  89. virtual void setMinimized(bool minimize);
  90.  
  91. //! Sets whether the window is minimizable
  92. virtual void setMinimizable(bool allow);
  93.  
  94. //! Returns true if the window is draggable, false if not
  95. virtual bool isDraggable() const;
  96.  
  97. //! Sets whether the window is draggable
  98. virtual void setDraggable(bool draggable);
  99.  
  100. //! Set if the window background will be drawn
  101. virtual void setDrawBackground(bool draw);
  102.  
  103. //! Get if the window background will be drawn
  104. virtual bool getDrawBackground() const;
  105.  
  106. //! Set if the window titlebar will be drawn
  107. //! Note: If the background is not drawn, then the titlebar is automatically also not drawn
  108. virtual void setDrawTitlebar(bool draw);
  109.  
  110. //! Get if the window titlebar will be drawn
  111. virtual bool getDrawTitlebar() const;
  112.  
  113. //! Returns the rectangle of the drawable area (without border and without titlebar)
  114. virtual core::rect<s32> getClientRect() const;
  115.  
  116. //! Makes the tittle bar to blink
  117. /// Force = false ==> if window is minimized or bar
  118. /// Force = true ==> in any window state
  119. virtual void notify(bool force);
  120.  
  121. virtual void OnPostRender(u32 timeMs);
  122.  
  123. protected:
  124.  
  125. void updateClientRect();
  126. void refreshSprites();
  127.  
  128. //! Refresh button visibility and position according state (normal, bar, minimized)
  129. void refreshButtons(); //! ADDED
  130.  
  131. //! Implementation of window close behavior
  132. void close(); //! ADDED
  133.  
  134. //! Implementation of window draw with cursor lightning
  135. core::rect<s32> draw3DWindowBackgroundMouseLightning(IGUIElement* element,
  136. bool drawTitleBar, video::SColor titleBarColor,
  137. const core::rect<s32>& r,
  138. const core::rect<s32>* clip=0,
  139. core::rect<s32>* checkClientArea=0); //! ADDED
  140.  
  141. //! Default skin management
  142. IGUISkin* Skin; //! ADDED
  143. IGUISpriteBank* DefaultSprites; //! ADDED
  144. video::SColor CurrentIconColor;
  145.  
  146. //! Button management
  147. core::array<buttoninfo> ButtonInfo; //! ADDED
  148. core::array<core::rect<s32> > ButtonRectangles; //! ADDED
  149. core::array<IGUIButton*> Buttons;
  150.  
  151. core::rect<s32> ClientRect;
  152.  
  153. //! States and events management
  154. core::position2d<s32> DragStart;
  155. bool Dragging;
  156. bool IsDraggable;
  157. bool DrawBackground;
  158. bool DrawTitlebar;
  159. bool IsActive;
  160. bool IsMinimized;//! ADDED
  161. bool IsBar; //! ADDED
  162. bool IsMinimizable;//! ADDED
  163.  
  164. //! Close button handling
  165. EWINDOW_CLOSE CloseHandling; //! ADDED
  166.  
  167. //! Window position for each window state
  168. core::rect<s32> NormalRectangle; //! ADDED
  169. core::rect<s32> MinimizedRectangle; //! ADDED
  170. core::rect<s32> BarRectangle; //! ADDED
  171.  
  172. //! Draw data
  173. bool UseGradient; /// ADDED clone Skin private member data
  174. ICursorControl* Cursor; //! ADDED
  175.  
  176. //! Notification data
  177. bool IsNotifying; //! ADDED
  178. u32 NotifyTimer; //! ADDED
  179. bool NotifyState; //! ADDED
  180. };
  181.  
  182. } // end namespace gui
  183. } // end namespace irr
  184.  
  185. //#endif // _IRR_COMPILE_WITH_GUI_
  186.  
  187. #endif

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.