1 // Copyright 2006-2012 Asger Feldthaus
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef _C_GUI_PANEL_H_
6 #define _C_GUI_PANEL_H_
7 
8 #include "IGUIElement.h"
9 #include "EGUIEditTypes.h"
10 
11 namespace irr
12 {
13 namespace gui
14 {
15 
16 class IGUIScrollBar;
17 class IGUITab;
18 
19 enum E_SCROLL_BAR_MODE
20 {
21 	//! The scrollbar will only show up when needed.
22 	ESBM_AUTOMATIC = 0,
23 
24 	//! The scrollbar will never be visible.
25 	ESBM_ALWAYS_INVISIBLE,
26 
27 	//! The scrollbar will always the visible.
28 	ESBM_ALWAYS_VISIBLE,
29 
30 	//! just a count of how many are in this enum
31 	ESBM_COUNT
32 };
33 
34 const c8* const GUIScrollBarModeNames[] =
35 {
36 	"automatic",
37 	"alwaysInvisible",
38 	"alwaysVisible",
39 	0
40 };
41 
42 class CGUIPanel : public IGUIElement
43 {
44 public:
45 	CGUIPanel( IGUIEnvironment* environment, IGUIElement* parent, s32 id=-1,
46 			const core::rect<s32>& rectangle = core::rect<s32>(0,0,100,100),
47 			bool border=false,
48 			E_SCROLL_BAR_MODE vMode=ESBM_AUTOMATIC,
49 			E_SCROLL_BAR_MODE hMode=ESBM_ALWAYS_INVISIBLE );
50 
51 	virtual ~CGUIPanel();
52 
53 	//! draws the panel and its children
54 	virtual void draw();
55 
56 	//! returns true if it has a border, false if not
57 	bool hasBorder() const;
58 
59 	//! sets whether the element draws a border
60 	void setBorder(bool enabled);
61 
62 	//! returns a pointer to the vertical scrollbar
63 	IGUIScrollBar* getVScrollBar() const;
64 
65 	//! returns a pointer to the horizontal scrollbar
66 	IGUIScrollBar* getHScrollBar() const;
67 
68 	//! returns the vertical scrollbar visibility rule
69 	E_SCROLL_BAR_MODE getVScrollBarMode() const;
70 
71 	//! sets the vertical scrollbar visibility rule
72 	void setVScrollBarMode(E_SCROLL_BAR_MODE mode);
73 
74 	//! returns the horizontal scrollbar visibility rule
75 	E_SCROLL_BAR_MODE getHScrollBarMode() const;
76 
77 	//! sets the horizontal scrollbar visibility rule
78 	void setHScrollBarMode(E_SCROLL_BAR_MODE mode);
79 
80 	//! returns the visible area inside the panel, excluding scrollbar and border
81 	core::rect<s32> getClientArea() const;
82 
83 	virtual bool OnEvent(const SEvent &event);
84 
85 	//! adds a child to the panel
86 	virtual void addChild(IGUIElement* child);
87 
88 	//! removes a child from the panel
89 	virtual void removeChild(IGUIElement* child);
90 
91 	//! updates the absolute position
92 	virtual void updateAbsolutePosition();
93 
94 	//! returns children of the inner pane
95 	virtual const core::list<IGUIElement*>& getChildren();
96 
97 	//! Returns the type name of the gui element.
getTypeName()98 	virtual const c8* getTypeName() const
99 	{
100 		return GUIEditElementTypeNames[EGUIEDIT_GUIPANEL];
101 	}
102 
103 	virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0);
104 	virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
105 
106 protected:
107 	void moveInnerPane();
108 	void resizeInnerPane();
109 	void calculateClientArea();
110 
111 private:
112 
113 	IGUIScrollBar*	VScrollBar;
114 	IGUIScrollBar*	HScrollBar;
115 	IGUITab*	ClipPane;
116 	IGUITab*	InnerPane;
117 
118 	E_SCROLL_BAR_MODE VScrollBarMode;
119 	E_SCROLL_BAR_MODE HScrollBarMode;
120 
121 	bool NeedsUpdate;
122 	bool Border;
123 };
124 
125 } // namespace gui
126 } // namespace irr
127 
128 #endif
129