1 // This file is part of the "Irrlicht Engine".
\r
2 // written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de
\r
4 #ifndef __C_GUI_TREE_VIEW_H_INCLUDED__
\r
5 #define __C_GUI_TREE_VIEW_H_INCLUDED__
\r
7 #include "IGUITreeView.h"
\r
15 // forward declarations
\r
17 class IGUIScrollBar;
\r
20 //! Node for gui tree view
\r
21 class CGUITreeViewNode : public IGUITreeViewNode
\r
23 friend class CGUITreeView;
\r
27 CGUITreeViewNode( CGUITreeView* owner, CGUITreeViewNode* parent );
\r
30 ~CGUITreeViewNode();
\r
32 //! returns the owner (tree view) of this node
\r
33 virtual IGUITreeView* getOwner() const _IRR_OVERRIDE_;
\r
35 //! Returns the parent node of this node.
\r
36 virtual IGUITreeViewNode* getParent() const _IRR_OVERRIDE_;
\r
38 //! returns the text of the node
\r
39 virtual const wchar_t* getText() const _IRR_OVERRIDE_
\r
40 { return Text.c_str(); }
\r
42 //! sets the text of the node
\r
43 virtual void setText( const wchar_t* text ) _IRR_OVERRIDE_;
\r
45 //! returns the icon text of the node
\r
46 virtual const wchar_t* getIcon() const _IRR_OVERRIDE_
\r
47 { return Icon.c_str(); }
\r
49 //! sets the icon text of the node
\r
50 virtual void setIcon( const wchar_t* icon ) _IRR_OVERRIDE_;
\r
52 //! returns the image index of the node
\r
53 virtual u32 getImageIndex() const _IRR_OVERRIDE_
\r
54 { return ImageIndex; }
\r
56 //! sets the image index of the node
\r
57 virtual void setImageIndex( u32 imageIndex ) _IRR_OVERRIDE_
\r
58 { ImageIndex = imageIndex; }
\r
60 //! returns the image index of the node
\r
61 virtual u32 getSelectedImageIndex() const _IRR_OVERRIDE_
\r
62 { return SelectedImageIndex; }
\r
64 //! sets the image index of the node
\r
65 virtual void setSelectedImageIndex( u32 imageIndex ) _IRR_OVERRIDE_
\r
66 { SelectedImageIndex = imageIndex; }
\r
68 //! returns the user data (void*) of this node
\r
69 virtual void* getData() const _IRR_OVERRIDE_
\r
72 //! sets the user data (void*) of this node
\r
73 virtual void setData( void* data ) _IRR_OVERRIDE_
\r
76 //! returns the user data2 (IReferenceCounted) of this node
\r
77 virtual IReferenceCounted* getData2() const _IRR_OVERRIDE_
\r
80 //! sets the user data2 (IReferenceCounted) of this node
\r
81 virtual void setData2( IReferenceCounted* data ) _IRR_OVERRIDE_
\r
94 //! returns the child item count
\r
95 virtual u32 getChildCount() const _IRR_OVERRIDE_
\r
96 { return Children.getSize(); }
\r
98 //! removes all children (recursive) from this node
\r
99 virtual void clearChildren() _IRR_OVERRIDE_;
\r
101 //! returns true if this node has child nodes
\r
102 virtual bool hasChildren() const _IRR_OVERRIDE_
\r
103 { return !Children.empty(); }
\r
105 //! Adds a new node behind the last child node.
\r
106 //! \param text text of the new node
\r
107 //! \param icon icon text of the new node
\r
108 //! \param imageIndex index of the image for the new node (-1 = none)
\r
109 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
\r
110 //! \param data user data (void*) of the new node
\r
111 //! \param data2 user data2 (IReferenceCounted*) of the new node
\r
113 //! returns the new node
\r
114 virtual IGUITreeViewNode* addChildBack(
\r
115 const wchar_t* text,
\r
116 const wchar_t* icon = 0,
\r
117 s32 imageIndex = -1,
\r
118 s32 selectedImageIndex = -1,
\r
120 IReferenceCounted* data2 = 0) _IRR_OVERRIDE_;
\r
122 //! Adds a new node before the first child node.
\r
123 //! \param text text of the new node
\r
124 //! \param icon icon text of the new node
\r
125 //! \param imageIndex index of the image for the new node (-1 = none)
\r
126 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
\r
127 //! \param data user data (void*) of the new node
\r
128 //! \param data2 user data2 (IReferenceCounted*) of the new node
\r
130 //! returns the new node
\r
131 virtual IGUITreeViewNode* addChildFront(
\r
132 const wchar_t* text,
\r
133 const wchar_t* icon = 0,
\r
134 s32 imageIndex = -1,
\r
135 s32 selectedImageIndex = -1,
\r
137 IReferenceCounted* data2 = 0 ) _IRR_OVERRIDE_;
\r
139 //! Adds a new node behind the other node.
\r
140 //! The other node has also te be a child node from this node.
\r
141 //! \param text text of the new node
\r
142 //! \param icon icon text of the new node
\r
143 //! \param imageIndex index of the image for the new node (-1 = none)
\r
144 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
\r
145 //! \param data user data (void*) of the new node
\r
146 //! \param data2 user data2 (IReferenceCounted*) of the new node
\r
148 //! returns the new node or 0 if other is no child node from this
\r
149 virtual IGUITreeViewNode* insertChildAfter(
\r
150 IGUITreeViewNode* other,
\r
151 const wchar_t* text,
\r
152 const wchar_t* icon = 0,
\r
153 s32 imageIndex = -1,
\r
154 s32 selectedImageIndex = -1,
\r
156 IReferenceCounted* data2 = 0 ) _IRR_OVERRIDE_;
\r
158 //! Adds a new node before the other node.
\r
159 //! The other node has also te be a child node from this node.
\r
160 //! \param text text of the new node
\r
161 //! \param icon icon text of the new node
\r
162 //! \param imageIndex index of the image for the new node (-1 = none)
\r
163 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
\r
164 //! \param data user data (void*) of the new node
\r
165 //! \param data2 user data2 (IReferenceCounted*) of the new node
\r
167 //! returns the new node or 0 if other is no child node from this
\r
168 virtual IGUITreeViewNode* insertChildBefore(
\r
169 IGUITreeViewNode* other,
\r
170 const wchar_t* text,
\r
171 const wchar_t* icon = 0,
\r
172 s32 imageIndex = -1,
\r
173 s32 selectedImageIndex = -1,
\r
175 IReferenceCounted* data2 = 0 ) _IRR_OVERRIDE_;
\r
177 //! Return the first child note from this node.
\r
178 virtual IGUITreeViewNode* getFirstChild() const _IRR_OVERRIDE_;
\r
180 //! Return the last child note from this node.
\r
181 virtual IGUITreeViewNode* getLastChild() const _IRR_OVERRIDE_;
\r
183 //! Returns the preverse sibling node from this node.
\r
184 virtual IGUITreeViewNode* getPrevSibling() const _IRR_OVERRIDE_;
\r
186 //! Returns the next sibling node from this node.
\r
187 virtual IGUITreeViewNode* getNextSibling() const _IRR_OVERRIDE_;
\r
189 //! Returns the next visible (expanded, may be out of scrolling) node from this node.
\r
190 virtual IGUITreeViewNode* getNextVisible() const _IRR_OVERRIDE_;
\r
192 //! Deletes a child node.
\r
193 virtual bool deleteChild( IGUITreeViewNode* child ) _IRR_OVERRIDE_;
\r
195 //! Moves a child node one position up.
\r
196 virtual bool moveChildUp( IGUITreeViewNode* child ) _IRR_OVERRIDE_;
\r
198 //! Moves a child node one position down.
\r
199 virtual bool moveChildDown( IGUITreeViewNode* child ) _IRR_OVERRIDE_;
\r
201 //! Returns true if the node is expanded (children are visible).
\r
202 virtual bool getExpanded() const _IRR_OVERRIDE_
\r
203 { return Expanded; }
\r
205 //! Sets if the node is expanded.
\r
206 virtual void setExpanded( bool expanded ) _IRR_OVERRIDE_;
\r
208 //! Returns true if the node is currently selected.
\r
209 virtual bool getSelected() const _IRR_OVERRIDE_;
\r
211 //! Sets this node as selected.
\r
212 virtual void setSelected( bool selected ) _IRR_OVERRIDE_;
\r
214 //! Returns true if this node is the root node.
\r
215 virtual bool isRoot() const _IRR_OVERRIDE_;
\r
217 //! Returns the level of this node.
\r
218 virtual s32 getLevel() const _IRR_OVERRIDE_;
\r
220 //! Returns true if this node is visible (all parents are expanded).
\r
221 virtual bool isVisible() const _IRR_OVERRIDE_;
\r
225 CGUITreeView* Owner;
\r
226 CGUITreeViewNode* Parent;
\r
227 core::stringw Text;
\r
228 core::stringw Icon;
\r
230 s32 SelectedImageIndex;
\r
232 IReferenceCounted* Data2;
\r
234 core::list<CGUITreeViewNode*> Children;
\r
238 //! Default tree view GUI element.
\r
239 class CGUITreeView : public IGUITreeView
\r
241 friend class CGUITreeViewNode;
\r
245 CGUITreeView( IGUIEnvironment* environment, IGUIElement* parent,
\r
246 s32 id, core::rect<s32> rectangle, bool clip = true,
\r
247 bool drawBack = false, bool scrollBarVertical = true, bool scrollBarHorizontal = true );
\r
250 virtual ~CGUITreeView();
\r
252 //! returns the root node (not visible) from the tree.
\r
253 virtual IGUITreeViewNode* getRoot() const _IRR_OVERRIDE_
\r
256 //! returns the selected node of the tree or 0 if none is selected
\r
257 virtual IGUITreeViewNode* getSelected() const _IRR_OVERRIDE_
\r
258 { return Selected; }
\r
260 //! returns true if the tree lines are visible
\r
261 virtual bool getLinesVisible() const _IRR_OVERRIDE_
\r
262 { return LinesVisible; }
\r
264 //! sets if the tree lines are visible
\r
265 virtual void setLinesVisible( bool visible ) _IRR_OVERRIDE_
\r
266 { LinesVisible = visible; }
\r
268 //! called if an event happened.
\r
269 virtual bool OnEvent( const SEvent &event ) _IRR_OVERRIDE_;
\r
271 //! draws the element and its children
\r
272 virtual void draw() _IRR_OVERRIDE_;
\r
274 //! Sets the font which should be used as icon font. This font is set to the Irrlicht engine
\r
275 //! built-in-font by default. Icons can be displayed in front of every list item.
\r
276 //! An icon is a string, displayed with the icon font. When using the build-in-font of the
\r
277 //! Irrlicht engine as icon font, the icon strings defined in GUIIcons.h can be used.
\r
278 virtual void setIconFont( IGUIFont* font ) _IRR_OVERRIDE_;
\r
280 //! Sets a skin independent font.
\r
281 /** \param font: New font to set or 0 to use the skin-font. */
\r
282 virtual void setOverrideFont(IGUIFont* font=0) _IRR_OVERRIDE_;
\r
284 //! Gets the override font (if any)
\r
285 /** \return The override font (may be 0) */
\r
286 virtual IGUIFont* getOverrideFont(void) const _IRR_OVERRIDE_;
\r
288 //! Get the font which is used for drawing
\r
289 /** This is the override font when one is set and the
\r
290 font of the skin otherwise. */
\r
291 virtual IGUIFont* getActiveFont() const _IRR_OVERRIDE_;
\r
293 //! Sets the image list which should be used for the image and selected image of every node.
\r
294 //! The default is 0 (no images).
\r
295 virtual void setImageList( IGUIImageList* imageList ) _IRR_OVERRIDE_;
\r
297 //! Returns the image list which is used for the nodes.
\r
298 virtual IGUIImageList* getImageList() const _IRR_OVERRIDE_
\r
299 { return ImageList; }
\r
301 //! Sets if the image is left of the icon. Default is true.
\r
302 virtual void setImageLeftOfIcon( bool bLeftOf ) _IRR_OVERRIDE_
\r
303 { ImageLeftOfIcon = bLeftOf; }
\r
305 //! Returns if the Image is left of the icon. Default is true.
\r
306 virtual bool getImageLeftOfIcon() const _IRR_OVERRIDE_
\r
307 { return ImageLeftOfIcon; }
\r
309 //! Returns the node which is associated to the last event.
\r
310 virtual IGUITreeViewNode* getLastEventNode() const _IRR_OVERRIDE_
\r
311 { return LastEventNode; }
\r
313 //! Access the vertical scrollbar
\r
314 virtual IGUIScrollBar* getVerticalScrollBar() const _IRR_OVERRIDE_;
\r
316 //! Access the horizontal scrollbar
\r
317 virtual IGUIScrollBar* getHorizontalScrollBar() const _IRR_OVERRIDE_;
\r
320 //! calculates the heigth of an node and of all visible nodes.
\r
321 void recalculateItemHeight();
\r
323 //! Resize scrollbars when their size in the skin has changed
\r
324 void updateScrollBarSize(s32 size);
\r
326 //! executes an mouse action (like selectNew of CGUIListBox)
\r
327 void mouseAction( s32 xpos, s32 ypos, bool onlyHover = false );
\r
329 CGUITreeViewNode* Root;
\r
330 IGUITreeViewNode* Selected;
\r
333 s32 TotalItemHeight;
\r
334 s32 TotalItemWidth;
\r
337 gui::IGUIFont* OverrideFont;
\r
338 IGUIFont* IconFont;
\r
339 IGUIScrollBar* ScrollBarH;
\r
340 IGUIScrollBar* ScrollBarV;
\r
341 IGUIImageList* ImageList;
\r
342 IGUITreeViewNode* LastEventNode;
\r
347 bool ImageLeftOfIcon;
\r
351 } // end namespace gui
\r
352 } // end namespace irr
\r