diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CGUITreeView.cpp | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CGUITreeView.cpp | 2202 |
1 files changed, 1101 insertions, 1101 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUITreeView.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUITreeView.cpp index 779b8cd..c81f2c1 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CGUITreeView.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUITreeView.cpp | |||
@@ -1,1101 +1,1101 @@ | |||
1 | // This file is part of the "Irrlicht Engine". | 1 | // This file is part of the "Irrlicht Engine". |
2 | // written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de | 2 | // written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de |
3 | // expaned by burningwater | 3 | // expaned by burningwater |
4 | 4 | ||
5 | #include "CGUITreeView.h" | 5 | #include "CGUITreeView.h" |
6 | 6 | ||
7 | #ifdef _IRR_COMPILE_WITH_GUI_ | 7 | #ifdef _IRR_COMPILE_WITH_GUI_ |
8 | 8 | ||
9 | #include "IGUISkin.h" | 9 | #include "IGUISkin.h" |
10 | #include "IGUIEnvironment.h" | 10 | #include "IGUIEnvironment.h" |
11 | #include "IVideoDriver.h" | 11 | #include "IVideoDriver.h" |
12 | #include "IGUIFont.h" | 12 | #include "IGUIFont.h" |
13 | #include "CGUIScrollBar.h" | 13 | #include "CGUIScrollBar.h" |
14 | #include "os.h" | 14 | #include "os.h" |
15 | 15 | ||
16 | namespace irr | 16 | namespace irr |
17 | { | 17 | { |
18 | namespace gui | 18 | namespace gui |
19 | { | 19 | { |
20 | 20 | ||
21 | CGUITreeViewNode::CGUITreeViewNode( CGUITreeView* owner, CGUITreeViewNode* parent ) | 21 | CGUITreeViewNode::CGUITreeViewNode( CGUITreeView* owner, CGUITreeViewNode* parent ) |
22 | : Owner(owner), Parent(parent), ImageIndex(-1), SelectedImageIndex(-1), | 22 | : Owner(owner), Parent(parent), ImageIndex(-1), SelectedImageIndex(-1), |
23 | Data(0), Data2(0), Expanded(false) | 23 | Data(0), Data2(0), Expanded(false) |
24 | { | 24 | { |
25 | #ifdef _DEBUG | 25 | #ifdef _DEBUG |
26 | setDebugName( "CGUITreeView" ); | 26 | setDebugName( "CGUITreeView" ); |
27 | #endif | 27 | #endif |
28 | } | 28 | } |
29 | 29 | ||
30 | CGUITreeViewNode::~CGUITreeViewNode() | 30 | CGUITreeViewNode::~CGUITreeViewNode() |
31 | { | 31 | { |
32 | if( Owner && this == Owner->getSelected() ) | 32 | if( Owner && this == Owner->getSelected() ) |
33 | { | 33 | { |
34 | setSelected( false ); | 34 | setSelected( false ); |
35 | } | 35 | } |
36 | 36 | ||
37 | clearChildren(); | 37 | clearChildren(); |
38 | 38 | ||
39 | if( Data2 ) | 39 | if( Data2 ) |
40 | { | 40 | { |
41 | Data2->drop(); | 41 | Data2->drop(); |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | IGUITreeView* CGUITreeViewNode::getOwner() const | 45 | IGUITreeView* CGUITreeViewNode::getOwner() const |
46 | { | 46 | { |
47 | return Owner; | 47 | return Owner; |
48 | } | 48 | } |
49 | 49 | ||
50 | IGUITreeViewNode* CGUITreeViewNode::getParent() const | 50 | IGUITreeViewNode* CGUITreeViewNode::getParent() const |
51 | { | 51 | { |
52 | return Parent; | 52 | return Parent; |
53 | } | 53 | } |
54 | 54 | ||
55 | void CGUITreeViewNode::setText( const wchar_t* text ) | 55 | void CGUITreeViewNode::setText( const wchar_t* text ) |
56 | { | 56 | { |
57 | Text = text; | 57 | Text = text; |
58 | } | 58 | } |
59 | 59 | ||
60 | void CGUITreeViewNode::setIcon( const wchar_t* icon ) | 60 | void CGUITreeViewNode::setIcon( const wchar_t* icon ) |
61 | { | 61 | { |
62 | Icon = icon; | 62 | Icon = icon; |
63 | } | 63 | } |
64 | 64 | ||
65 | void CGUITreeViewNode::clearChildren() | 65 | void CGUITreeViewNode::clearChildren() |
66 | { | 66 | { |
67 | core::list<CGUITreeViewNode*>::Iterator it; | 67 | core::list<CGUITreeViewNode*>::Iterator it; |
68 | 68 | ||
69 | for( it = Children.begin(); it != Children.end(); it++ ) | 69 | for( it = Children.begin(); it != Children.end(); it++ ) |
70 | { | 70 | { |
71 | ( *it )->drop(); | 71 | ( *it )->drop(); |
72 | } | 72 | } |
73 | Children.clear(); | 73 | Children.clear(); |
74 | } | 74 | } |
75 | 75 | ||
76 | IGUITreeViewNode* CGUITreeViewNode::addChildBack( | 76 | IGUITreeViewNode* CGUITreeViewNode::addChildBack( |
77 | const wchar_t* text, | 77 | const wchar_t* text, |
78 | const wchar_t* icon /*= 0*/, | 78 | const wchar_t* icon /*= 0*/, |
79 | s32 imageIndex /*= -1*/, | 79 | s32 imageIndex /*= -1*/, |
80 | s32 selectedImageIndex /*= -1*/, | 80 | s32 selectedImageIndex /*= -1*/, |
81 | void* data /*= 0*/, | 81 | void* data /*= 0*/, |
82 | IReferenceCounted* data2 /*= 0*/ ) | 82 | IReferenceCounted* data2 /*= 0*/ ) |
83 | { | 83 | { |
84 | CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this ); | 84 | CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this ); |
85 | 85 | ||
86 | Children.push_back( newChild ); | 86 | Children.push_back( newChild ); |
87 | newChild->Text = text; | 87 | newChild->Text = text; |
88 | newChild->Icon = icon; | 88 | newChild->Icon = icon; |
89 | newChild->ImageIndex = imageIndex; | 89 | newChild->ImageIndex = imageIndex; |
90 | newChild->SelectedImageIndex = selectedImageIndex; | 90 | newChild->SelectedImageIndex = selectedImageIndex; |
91 | newChild->Data = data; | 91 | newChild->Data = data; |
92 | newChild->Data2 = data2; | 92 | newChild->Data2 = data2; |
93 | if( data2 ) | 93 | if( data2 ) |
94 | { | 94 | { |
95 | data2->grab(); | 95 | data2->grab(); |
96 | } | 96 | } |
97 | return newChild; | 97 | return newChild; |
98 | } | 98 | } |
99 | 99 | ||
100 | IGUITreeViewNode* CGUITreeViewNode::addChildFront( | 100 | IGUITreeViewNode* CGUITreeViewNode::addChildFront( |
101 | const wchar_t* text, | 101 | const wchar_t* text, |
102 | const wchar_t* icon /*= 0*/, | 102 | const wchar_t* icon /*= 0*/, |
103 | s32 imageIndex /*= -1*/, | 103 | s32 imageIndex /*= -1*/, |
104 | s32 selectedImageIndex /*= -1*/, | 104 | s32 selectedImageIndex /*= -1*/, |
105 | void* data /*= 0*/, | 105 | void* data /*= 0*/, |
106 | IReferenceCounted* data2 /*= 0*/ ) | 106 | IReferenceCounted* data2 /*= 0*/ ) |
107 | { | 107 | { |
108 | CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this ); | 108 | CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this ); |
109 | 109 | ||
110 | Children.push_front( newChild ); | 110 | Children.push_front( newChild ); |
111 | newChild->Text = text; | 111 | newChild->Text = text; |
112 | newChild->Icon = icon; | 112 | newChild->Icon = icon; |
113 | newChild->ImageIndex = imageIndex; | 113 | newChild->ImageIndex = imageIndex; |
114 | newChild->SelectedImageIndex = selectedImageIndex; | 114 | newChild->SelectedImageIndex = selectedImageIndex; |
115 | newChild->Data = data; | 115 | newChild->Data = data; |
116 | newChild->Data2 = data2; | 116 | newChild->Data2 = data2; |
117 | if( data2 ) | 117 | if( data2 ) |
118 | { | 118 | { |
119 | data2->grab(); | 119 | data2->grab(); |
120 | } | 120 | } |
121 | return newChild; | 121 | return newChild; |
122 | } | 122 | } |
123 | 123 | ||
124 | IGUITreeViewNode* CGUITreeViewNode::insertChildAfter( | 124 | IGUITreeViewNode* CGUITreeViewNode::insertChildAfter( |
125 | IGUITreeViewNode* other, | 125 | IGUITreeViewNode* other, |
126 | const wchar_t* text, | 126 | const wchar_t* text, |
127 | const wchar_t* icon /*= 0*/, | 127 | const wchar_t* icon /*= 0*/, |
128 | s32 imageIndex /*= -1*/, | 128 | s32 imageIndex /*= -1*/, |
129 | s32 selectedImageIndex /*= -1*/, | 129 | s32 selectedImageIndex /*= -1*/, |
130 | void* data /*= 0*/, | 130 | void* data /*= 0*/, |
131 | IReferenceCounted* data2/* = 0*/ ) | 131 | IReferenceCounted* data2/* = 0*/ ) |
132 | { | 132 | { |
133 | core::list<CGUITreeViewNode*>::Iterator itOther; | 133 | core::list<CGUITreeViewNode*>::Iterator itOther; |
134 | CGUITreeViewNode* newChild = 0; | 134 | CGUITreeViewNode* newChild = 0; |
135 | 135 | ||
136 | for( itOther = Children.begin(); itOther != Children.end(); itOther++ ) | 136 | for( itOther = Children.begin(); itOther != Children.end(); itOther++ ) |
137 | { | 137 | { |
138 | if( other == *itOther ) | 138 | if( other == *itOther ) |
139 | { | 139 | { |
140 | newChild = new CGUITreeViewNode( Owner, this ); | 140 | newChild = new CGUITreeViewNode( Owner, this ); |
141 | newChild->Text = text; | 141 | newChild->Text = text; |
142 | newChild->Icon = icon; | 142 | newChild->Icon = icon; |
143 | newChild->ImageIndex = imageIndex; | 143 | newChild->ImageIndex = imageIndex; |
144 | newChild->SelectedImageIndex = selectedImageIndex; | 144 | newChild->SelectedImageIndex = selectedImageIndex; |
145 | newChild->Data = data; | 145 | newChild->Data = data; |
146 | newChild->Data2 = data2; | 146 | newChild->Data2 = data2; |
147 | if( data2 ) | 147 | if( data2 ) |
148 | { | 148 | { |
149 | data2->grab(); | 149 | data2->grab(); |
150 | } | 150 | } |
151 | Children.insert_after( itOther, newChild ); | 151 | Children.insert_after( itOther, newChild ); |
152 | break; | 152 | break; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | return newChild; | 155 | return newChild; |
156 | } | 156 | } |
157 | 157 | ||
158 | IGUITreeViewNode* CGUITreeViewNode::insertChildBefore( | 158 | IGUITreeViewNode* CGUITreeViewNode::insertChildBefore( |
159 | IGUITreeViewNode* other, | 159 | IGUITreeViewNode* other, |
160 | const wchar_t* text, | 160 | const wchar_t* text, |
161 | const wchar_t* icon /*= 0*/, | 161 | const wchar_t* icon /*= 0*/, |
162 | s32 imageIndex /*= -1*/, | 162 | s32 imageIndex /*= -1*/, |
163 | s32 selectedImageIndex /*= -1*/, | 163 | s32 selectedImageIndex /*= -1*/, |
164 | void* data /*= 0*/, | 164 | void* data /*= 0*/, |
165 | IReferenceCounted* data2/* = 0*/ ) | 165 | IReferenceCounted* data2/* = 0*/ ) |
166 | { | 166 | { |
167 | core::list<CGUITreeViewNode*>::Iterator itOther; | 167 | core::list<CGUITreeViewNode*>::Iterator itOther; |
168 | CGUITreeViewNode* newChild = 0; | 168 | CGUITreeViewNode* newChild = 0; |
169 | 169 | ||
170 | for( itOther = Children.begin(); itOther != Children.end(); itOther++ ) | 170 | for( itOther = Children.begin(); itOther != Children.end(); itOther++ ) |
171 | { | 171 | { |
172 | if( other == *itOther ) | 172 | if( other == *itOther ) |
173 | { | 173 | { |
174 | newChild = new CGUITreeViewNode( Owner, this ); | 174 | newChild = new CGUITreeViewNode( Owner, this ); |
175 | newChild->Text = text; | 175 | newChild->Text = text; |
176 | newChild->Icon = icon; | 176 | newChild->Icon = icon; |
177 | newChild->ImageIndex = imageIndex; | 177 | newChild->ImageIndex = imageIndex; |
178 | newChild->SelectedImageIndex = selectedImageIndex; | 178 | newChild->SelectedImageIndex = selectedImageIndex; |
179 | newChild->Data = data; | 179 | newChild->Data = data; |
180 | newChild->Data2 = data2; | 180 | newChild->Data2 = data2; |
181 | if( data2 ) | 181 | if( data2 ) |
182 | { | 182 | { |
183 | data2->grab(); | 183 | data2->grab(); |
184 | } | 184 | } |
185 | Children.insert_before( itOther, newChild ); | 185 | Children.insert_before( itOther, newChild ); |
186 | break; | 186 | break; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | return newChild; | 189 | return newChild; |
190 | } | 190 | } |
191 | 191 | ||
192 | IGUITreeViewNode* CGUITreeViewNode::getFirstChild() const | 192 | IGUITreeViewNode* CGUITreeViewNode::getFirstChild() const |
193 | { | 193 | { |
194 | if( Children.empty() ) | 194 | if( Children.empty() ) |
195 | { | 195 | { |
196 | return 0; | 196 | return 0; |
197 | } | 197 | } |
198 | else | 198 | else |
199 | { | 199 | { |
200 | return *( Children.begin() ); | 200 | return *( Children.begin() ); |
201 | } | 201 | } |
202 | } | 202 | } |
203 | 203 | ||
204 | IGUITreeViewNode* CGUITreeViewNode::getLastChild() const | 204 | IGUITreeViewNode* CGUITreeViewNode::getLastChild() const |
205 | { | 205 | { |
206 | if( Children.empty() ) | 206 | if( Children.empty() ) |
207 | { | 207 | { |
208 | return 0; | 208 | return 0; |
209 | } | 209 | } |
210 | else | 210 | else |
211 | { | 211 | { |
212 | return *( Children.getLast() ); | 212 | return *( Children.getLast() ); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | 215 | ||
216 | IGUITreeViewNode* CGUITreeViewNode::getPrevSibling() const | 216 | IGUITreeViewNode* CGUITreeViewNode::getPrevSibling() const |
217 | { | 217 | { |
218 | core::list<CGUITreeViewNode*>::Iterator itThis; | 218 | core::list<CGUITreeViewNode*>::Iterator itThis; |
219 | core::list<CGUITreeViewNode*>::Iterator itOther; | 219 | core::list<CGUITreeViewNode*>::Iterator itOther; |
220 | CGUITreeViewNode* other = 0; | 220 | CGUITreeViewNode* other = 0; |
221 | 221 | ||
222 | if( Parent ) | 222 | if( Parent ) |
223 | { | 223 | { |
224 | for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ ) | 224 | for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ ) |
225 | { | 225 | { |
226 | if( this == *itThis ) | 226 | if( this == *itThis ) |
227 | { | 227 | { |
228 | if( itThis != Parent->Children.begin() ) | 228 | if( itThis != Parent->Children.begin() ) |
229 | { | 229 | { |
230 | other = *itOther; | 230 | other = *itOther; |
231 | } | 231 | } |
232 | break; | 232 | break; |
233 | } | 233 | } |
234 | itOther = itThis; | 234 | itOther = itThis; |
235 | } | 235 | } |
236 | } | 236 | } |
237 | return other; | 237 | return other; |
238 | } | 238 | } |
239 | 239 | ||
240 | IGUITreeViewNode* CGUITreeViewNode::getNextSibling() const | 240 | IGUITreeViewNode* CGUITreeViewNode::getNextSibling() const |
241 | { | 241 | { |
242 | core::list<CGUITreeViewNode*>::Iterator itThis; | 242 | core::list<CGUITreeViewNode*>::Iterator itThis; |
243 | CGUITreeViewNode* other = 0; | 243 | CGUITreeViewNode* other = 0; |
244 | 244 | ||
245 | if( Parent ) | 245 | if( Parent ) |
246 | { | 246 | { |
247 | for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ ) | 247 | for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ ) |
248 | { | 248 | { |
249 | if( this == *itThis ) | 249 | if( this == *itThis ) |
250 | { | 250 | { |
251 | if( itThis != Parent->Children.getLast() ) | 251 | if( itThis != Parent->Children.getLast() ) |
252 | { | 252 | { |
253 | other = *( ++itThis ); | 253 | other = *( ++itThis ); |
254 | } | 254 | } |
255 | break; | 255 | break; |
256 | } | 256 | } |
257 | } | 257 | } |
258 | } | 258 | } |
259 | return other; | 259 | return other; |
260 | } | 260 | } |
261 | 261 | ||
262 | IGUITreeViewNode* CGUITreeViewNode::getNextVisible() const | 262 | IGUITreeViewNode* CGUITreeViewNode::getNextVisible() const |
263 | { | 263 | { |
264 | IGUITreeViewNode* next = 0; | 264 | IGUITreeViewNode* next = 0; |
265 | IGUITreeViewNode* node = 0; | 265 | IGUITreeViewNode* node = 0; |
266 | 266 | ||
267 | node = const_cast<CGUITreeViewNode*>( this ); | 267 | node = const_cast<CGUITreeViewNode*>( this ); |
268 | 268 | ||
269 | if( node->getExpanded() && node->hasChildren() ) | 269 | if( node->getExpanded() && node->hasChildren() ) |
270 | { | 270 | { |
271 | next = node->getFirstChild(); | 271 | next = node->getFirstChild(); |
272 | } | 272 | } |
273 | else | 273 | else |
274 | { | 274 | { |
275 | next = node->getNextSibling(); | 275 | next = node->getNextSibling(); |
276 | } | 276 | } |
277 | while( !next && node->getParent() ) | 277 | while( !next && node->getParent() ) |
278 | { | 278 | { |
279 | next = node->getParent()->getNextSibling(); | 279 | next = node->getParent()->getNextSibling(); |
280 | if( !next ) | 280 | if( !next ) |
281 | { | 281 | { |
282 | node = node->getParent(); | 282 | node = node->getParent(); |
283 | } | 283 | } |
284 | } | 284 | } |
285 | 285 | ||
286 | return next; | 286 | return next; |
287 | } | 287 | } |
288 | 288 | ||
289 | bool CGUITreeViewNode::deleteChild( IGUITreeViewNode* child ) | 289 | bool CGUITreeViewNode::deleteChild( IGUITreeViewNode* child ) |
290 | { | 290 | { |
291 | core::list<CGUITreeViewNode*>::Iterator itChild; | 291 | core::list<CGUITreeViewNode*>::Iterator itChild; |
292 | bool deleted = false; | 292 | bool deleted = false; |
293 | 293 | ||
294 | for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) | 294 | for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) |
295 | { | 295 | { |
296 | if( child == *itChild ) | 296 | if( child == *itChild ) |
297 | { | 297 | { |
298 | child->drop(); | 298 | child->drop(); |
299 | Children.erase( itChild ); | 299 | Children.erase( itChild ); |
300 | deleted = true; | 300 | deleted = true; |
301 | break; | 301 | break; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | return deleted; | 304 | return deleted; |
305 | } | 305 | } |
306 | 306 | ||
307 | bool CGUITreeViewNode::moveChildUp( IGUITreeViewNode* child ) | 307 | bool CGUITreeViewNode::moveChildUp( IGUITreeViewNode* child ) |
308 | { | 308 | { |
309 | core::list<CGUITreeViewNode*>::Iterator itChild; | 309 | core::list<CGUITreeViewNode*>::Iterator itChild; |
310 | core::list<CGUITreeViewNode*>::Iterator itOther; | 310 | core::list<CGUITreeViewNode*>::Iterator itOther; |
311 | CGUITreeViewNode* nodeTmp; | 311 | CGUITreeViewNode* nodeTmp; |
312 | bool moved = false; | 312 | bool moved = false; |
313 | 313 | ||
314 | for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) | 314 | for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) |
315 | { | 315 | { |
316 | if( child == *itChild ) | 316 | if( child == *itChild ) |
317 | { | 317 | { |
318 | if( itChild != Children.begin() ) | 318 | if( itChild != Children.begin() ) |
319 | { | 319 | { |
320 | nodeTmp = *itChild; | 320 | nodeTmp = *itChild; |
321 | *itChild = *itOther; | 321 | *itChild = *itOther; |
322 | *itOther = nodeTmp; | 322 | *itOther = nodeTmp; |
323 | moved = true; | 323 | moved = true; |
324 | } | 324 | } |
325 | break; | 325 | break; |
326 | } | 326 | } |
327 | itOther = itChild; | 327 | itOther = itChild; |
328 | } | 328 | } |
329 | return moved; | 329 | return moved; |
330 | } | 330 | } |
331 | 331 | ||
332 | bool CGUITreeViewNode::moveChildDown( IGUITreeViewNode* child ) | 332 | bool CGUITreeViewNode::moveChildDown( IGUITreeViewNode* child ) |
333 | { | 333 | { |
334 | core::list<CGUITreeViewNode*>::Iterator itChild; | 334 | core::list<CGUITreeViewNode*>::Iterator itChild; |
335 | core::list<CGUITreeViewNode*>::Iterator itOther; | 335 | core::list<CGUITreeViewNode*>::Iterator itOther; |
336 | CGUITreeViewNode* nodeTmp; | 336 | CGUITreeViewNode* nodeTmp; |
337 | bool moved = false; | 337 | bool moved = false; |
338 | 338 | ||
339 | for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) | 339 | for( itChild = Children.begin(); itChild != Children.end(); itChild++ ) |
340 | { | 340 | { |
341 | if( child == *itChild ) | 341 | if( child == *itChild ) |
342 | { | 342 | { |
343 | if( itChild != Children.getLast() ) | 343 | if( itChild != Children.getLast() ) |
344 | { | 344 | { |
345 | itOther = itChild; | 345 | itOther = itChild; |
346 | ++itOther; | 346 | ++itOther; |
347 | nodeTmp = *itChild; | 347 | nodeTmp = *itChild; |
348 | *itChild = *itOther; | 348 | *itChild = *itOther; |
349 | *itOther = nodeTmp; | 349 | *itOther = nodeTmp; |
350 | moved = true; | 350 | moved = true; |
351 | } | 351 | } |
352 | break; | 352 | break; |
353 | } | 353 | } |
354 | } | 354 | } |
355 | return moved; | 355 | return moved; |
356 | } | 356 | } |
357 | 357 | ||
358 | void CGUITreeViewNode::setExpanded( bool expanded ) | 358 | void CGUITreeViewNode::setExpanded( bool expanded ) |
359 | { | 359 | { |
360 | Expanded = expanded; | 360 | Expanded = expanded; |
361 | } | 361 | } |
362 | 362 | ||
363 | void CGUITreeViewNode::setSelected( bool selected ) | 363 | void CGUITreeViewNode::setSelected( bool selected ) |
364 | { | 364 | { |
365 | if( Owner ) | 365 | if( Owner ) |
366 | { | 366 | { |
367 | if( selected ) | 367 | if( selected ) |
368 | { | 368 | { |
369 | Owner->Selected = this; | 369 | Owner->Selected = this; |
370 | } | 370 | } |
371 | else | 371 | else |
372 | { | 372 | { |
373 | if( Owner->Selected == this ) | 373 | if( Owner->Selected == this ) |
374 | { | 374 | { |
375 | Owner->Selected = 0; | 375 | Owner->Selected = 0; |
376 | } | 376 | } |
377 | } | 377 | } |
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | bool CGUITreeViewNode::getSelected() const | 381 | bool CGUITreeViewNode::getSelected() const |
382 | { | 382 | { |
383 | if( Owner ) | 383 | if( Owner ) |
384 | { | 384 | { |
385 | return Owner->Selected == (IGUITreeViewNode*)this; | 385 | return Owner->Selected == (IGUITreeViewNode*)this; |
386 | } | 386 | } |
387 | else | 387 | else |
388 | { | 388 | { |
389 | return false; | 389 | return false; |
390 | } | 390 | } |
391 | } | 391 | } |
392 | 392 | ||
393 | bool CGUITreeViewNode::isRoot() const | 393 | bool CGUITreeViewNode::isRoot() const |
394 | { | 394 | { |
395 | return ( Owner && ( this == Owner->Root ) ); | 395 | return ( Owner && ( this == Owner->Root ) ); |
396 | } | 396 | } |
397 | 397 | ||
398 | s32 CGUITreeViewNode::getLevel() const | 398 | s32 CGUITreeViewNode::getLevel() const |
399 | { | 399 | { |
400 | if( Parent ) | 400 | if( Parent ) |
401 | { | 401 | { |
402 | return Parent->getLevel() + 1; | 402 | return Parent->getLevel() + 1; |
403 | } | 403 | } |
404 | else | 404 | else |
405 | { | 405 | { |
406 | return 0; | 406 | return 0; |
407 | } | 407 | } |
408 | } | 408 | } |
409 | 409 | ||
410 | bool CGUITreeViewNode::isVisible() const | 410 | bool CGUITreeViewNode::isVisible() const |
411 | { | 411 | { |
412 | if( Parent ) | 412 | if( Parent ) |
413 | { | 413 | { |
414 | return Parent->getExpanded() && Parent->isVisible(); | 414 | return Parent->getExpanded() && Parent->isVisible(); |
415 | } | 415 | } |
416 | else | 416 | else |
417 | { | 417 | { |
418 | return true; | 418 | return true; |
419 | } | 419 | } |
420 | } | 420 | } |
421 | 421 | ||
422 | 422 | ||
423 | //! constructor | 423 | //! constructor |
424 | CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent, | 424 | CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent, |
425 | s32 id, core::rect<s32> rectangle, bool clip, | 425 | s32 id, core::rect<s32> rectangle, bool clip, |
426 | bool drawBack,bool scrollBarVertical, bool scrollBarHorizontal) | 426 | bool drawBack,bool scrollBarVertical, bool scrollBarHorizontal) |
427 | : IGUITreeView( environment, parent, id, rectangle ), | 427 | : IGUITreeView( environment, parent, id, rectangle ), |
428 | Root(0), Selected(0), | 428 | Root(0), Selected(0), |
429 | ItemHeight( 0 ), | 429 | ItemHeight( 0 ), |
430 | IndentWidth( 0 ), | 430 | IndentWidth( 0 ), |
431 | TotalItemHeight( 0 ), | 431 | TotalItemHeight( 0 ), |
432 | TotalItemWidth ( 0 ), | 432 | TotalItemWidth ( 0 ), |
433 | Font( 0 ), | 433 | Font( 0 ), |
434 | IconFont( 0 ), | 434 | IconFont( 0 ), |
435 | ScrollBarH( 0 ), | 435 | ScrollBarH( 0 ), |
436 | ScrollBarV( 0 ), | 436 | ScrollBarV( 0 ), |
437 | ImageList( 0 ), | 437 | ImageList( 0 ), |
438 | LastEventNode( 0 ), | 438 | LastEventNode( 0 ), |
439 | LinesVisible( true ), | 439 | LinesVisible( true ), |
440 | Selecting( false ), | 440 | Selecting( false ), |
441 | Clip( clip ), | 441 | Clip( clip ), |
442 | DrawBack( drawBack ), | 442 | DrawBack( drawBack ), |
443 | ImageLeftOfIcon( true ) | 443 | ImageLeftOfIcon( true ) |
444 | { | 444 | { |
445 | #ifdef _DEBUG | 445 | #ifdef _DEBUG |
446 | setDebugName( "CGUITreeView" ); | 446 | setDebugName( "CGUITreeView" ); |
447 | #endif | 447 | #endif |
448 | 448 | ||
449 | IGUISkin* skin = Environment->getSkin(); | 449 | IGUISkin* skin = Environment->getSkin(); |
450 | s32 s = skin->getSize( EGDS_SCROLLBAR_SIZE ); | 450 | s32 s = skin->getSize( EGDS_SCROLLBAR_SIZE ); |
451 | 451 | ||
452 | if ( scrollBarVertical ) | 452 | if ( scrollBarVertical ) |
453 | { | 453 | { |
454 | ScrollBarV = new CGUIScrollBar( false, Environment, this, 0, | 454 | ScrollBarV = new CGUIScrollBar( false, Environment, this, 0, |
455 | core::rect<s32>( RelativeRect.getWidth() - s, | 455 | core::rect<s32>( RelativeRect.getWidth() - s, |
456 | 0, | 456 | 0, |
457 | RelativeRect.getWidth(), | 457 | RelativeRect.getWidth(), |
458 | RelativeRect.getHeight() - (scrollBarHorizontal ? s : 0 ) | 458 | RelativeRect.getHeight() - (scrollBarHorizontal ? s : 0 ) |
459 | ), | 459 | ), |
460 | !clip ); | 460 | !clip ); |
461 | ScrollBarV->drop(); | 461 | ScrollBarV->drop(); |
462 | 462 | ||
463 | ScrollBarV->setSubElement(true); | 463 | ScrollBarV->setSubElement(true); |
464 | ScrollBarV->setPos( 0 ); | 464 | ScrollBarV->setPos( 0 ); |
465 | ScrollBarV->grab(); | 465 | ScrollBarV->grab(); |
466 | } | 466 | } |
467 | 467 | ||
468 | if ( scrollBarHorizontal ) | 468 | if ( scrollBarHorizontal ) |
469 | { | 469 | { |
470 | ScrollBarH = new CGUIScrollBar( true, Environment, this, 1, | 470 | ScrollBarH = new CGUIScrollBar( true, Environment, this, 1, |
471 | core::rect<s32>( 0, RelativeRect.getHeight() - s, RelativeRect.getWidth() - s, RelativeRect.getHeight() ), | 471 | core::rect<s32>( 0, RelativeRect.getHeight() - s, RelativeRect.getWidth() - s, RelativeRect.getHeight() ), |
472 | !clip ); | 472 | !clip ); |
473 | ScrollBarH->drop(); | 473 | ScrollBarH->drop(); |
474 | 474 | ||
475 | ScrollBarH->setSubElement(true); | 475 | ScrollBarH->setSubElement(true); |
476 | ScrollBarH->setPos( 0 ); | 476 | ScrollBarH->setPos( 0 ); |
477 | ScrollBarH->grab(); | 477 | ScrollBarH->grab(); |
478 | } | 478 | } |
479 | 479 | ||
480 | Root = new CGUITreeViewNode( this, 0 ); | 480 | Root = new CGUITreeViewNode( this, 0 ); |
481 | Root->Expanded = true; | 481 | Root->Expanded = true; |
482 | 482 | ||
483 | recalculateItemHeight(); | 483 | recalculateItemHeight(); |
484 | } | 484 | } |
485 | 485 | ||
486 | 486 | ||
487 | //! destructor | 487 | //! destructor |
488 | CGUITreeView::~CGUITreeView() | 488 | CGUITreeView::~CGUITreeView() |
489 | { | 489 | { |
490 | if( ScrollBarV ) | 490 | if( ScrollBarV ) |
491 | { | 491 | { |
492 | ScrollBarV->drop(); | 492 | ScrollBarV->drop(); |
493 | } | 493 | } |
494 | 494 | ||
495 | if( ScrollBarH ) | 495 | if( ScrollBarH ) |
496 | { | 496 | { |
497 | ScrollBarH->drop(); | 497 | ScrollBarH->drop(); |
498 | } | 498 | } |
499 | 499 | ||
500 | if( Font ) | 500 | if( Font ) |
501 | { | 501 | { |
502 | Font->drop(); | 502 | Font->drop(); |
503 | } | 503 | } |
504 | 504 | ||
505 | if( IconFont ) | 505 | if( IconFont ) |
506 | { | 506 | { |
507 | IconFont->drop(); | 507 | IconFont->drop(); |
508 | } | 508 | } |
509 | 509 | ||
510 | if( ImageList ) | 510 | if( ImageList ) |
511 | { | 511 | { |
512 | ImageList->drop(); | 512 | ImageList->drop(); |
513 | } | 513 | } |
514 | 514 | ||
515 | if( Root ) | 515 | if( Root ) |
516 | { | 516 | { |
517 | Root->drop(); | 517 | Root->drop(); |
518 | } | 518 | } |
519 | } | 519 | } |
520 | 520 | ||
521 | void CGUITreeView::recalculateItemHeight() | 521 | void CGUITreeView::recalculateItemHeight() |
522 | { | 522 | { |
523 | IGUISkin* skin = Environment->getSkin(); | 523 | IGUISkin* skin = Environment->getSkin(); |
524 | IGUITreeViewNode* node; | 524 | IGUITreeViewNode* node; |
525 | 525 | ||
526 | if( Font != skin->getFont() ) | 526 | if( Font != skin->getFont() ) |
527 | { | 527 | { |
528 | if( Font ) | 528 | if( Font ) |
529 | { | 529 | { |
530 | Font->drop(); | 530 | Font->drop(); |
531 | } | 531 | } |
532 | 532 | ||
533 | Font = skin->getFont(); | 533 | Font = skin->getFont(); |
534 | ItemHeight = 0; | 534 | ItemHeight = 0; |
535 | 535 | ||
536 | if( Font ) | 536 | if( Font ) |
537 | { | 537 | { |
538 | ItemHeight = Font->getDimension( L"A" ).Height + 4; | 538 | ItemHeight = Font->getDimension( L"A" ).Height + 4; |
539 | Font->grab(); | 539 | Font->grab(); |
540 | } | 540 | } |
541 | 541 | ||
542 | if( IconFont ) | 542 | if( IconFont ) |
543 | { | 543 | { |
544 | s32 height = IconFont->getDimension( L" " ).Height; | 544 | s32 height = IconFont->getDimension( L" " ).Height; |
545 | if( height > ItemHeight ) | 545 | if( height > ItemHeight ) |
546 | { | 546 | { |
547 | ItemHeight = height; | 547 | ItemHeight = height; |
548 | } | 548 | } |
549 | } | 549 | } |
550 | if( ImageList ) | 550 | if( ImageList ) |
551 | { | 551 | { |
552 | if( ImageList->getImageSize().Height + 1 > ItemHeight ) | 552 | if( ImageList->getImageSize().Height + 1 > ItemHeight ) |
553 | { | 553 | { |
554 | ItemHeight = ImageList->getImageSize().Height + 1; | 554 | ItemHeight = ImageList->getImageSize().Height + 1; |
555 | } | 555 | } |
556 | } | 556 | } |
557 | } | 557 | } |
558 | 558 | ||
559 | IndentWidth = ItemHeight; | 559 | IndentWidth = ItemHeight; |
560 | if( IndentWidth < 9 ) | 560 | if( IndentWidth < 9 ) |
561 | { | 561 | { |
562 | IndentWidth = 9; | 562 | IndentWidth = 9; |
563 | } | 563 | } |
564 | else if( IndentWidth > 15 ) | 564 | else if( IndentWidth > 15 ) |
565 | { | 565 | { |
566 | IndentWidth = 15; | 566 | IndentWidth = 15; |
567 | } | 567 | } |
568 | else | 568 | else |
569 | { | 569 | { |
570 | if( ( ( IndentWidth >> 1 ) << 1 ) - IndentWidth == 0 ) | 570 | if( ( ( IndentWidth >> 1 ) << 1 ) - IndentWidth == 0 ) |
571 | { | 571 | { |
572 | --IndentWidth; | 572 | --IndentWidth; |
573 | } | 573 | } |
574 | } | 574 | } |
575 | 575 | ||
576 | TotalItemHeight = 0; | 576 | TotalItemHeight = 0; |
577 | TotalItemWidth = AbsoluteRect.getWidth() * 2; | 577 | TotalItemWidth = AbsoluteRect.getWidth() * 2; |
578 | node = Root->getFirstChild(); | 578 | node = Root->getFirstChild(); |
579 | while( node ) | 579 | while( node ) |
580 | { | 580 | { |
581 | TotalItemHeight += ItemHeight; | 581 | TotalItemHeight += ItemHeight; |
582 | node = node->getNextVisible(); | 582 | node = node->getNextVisible(); |
583 | } | 583 | } |
584 | 584 | ||
585 | if ( ScrollBarV ) | 585 | if ( ScrollBarV ) |
586 | ScrollBarV->setMax( core::max_(0,TotalItemHeight - AbsoluteRect.getHeight()) ); | 586 | ScrollBarV->setMax( core::max_(0,TotalItemHeight - AbsoluteRect.getHeight()) ); |
587 | 587 | ||
588 | if ( ScrollBarH ) | 588 | if ( ScrollBarH ) |
589 | ScrollBarH->setMax( core::max_(0, TotalItemWidth - AbsoluteRect.getWidth()) ); | 589 | ScrollBarH->setMax( core::max_(0, TotalItemWidth - AbsoluteRect.getWidth()) ); |
590 | 590 | ||
591 | } | 591 | } |
592 | 592 | ||
593 | //! called if an event happened. | 593 | //! called if an event happened. |
594 | bool CGUITreeView::OnEvent( const SEvent &event ) | 594 | bool CGUITreeView::OnEvent( const SEvent &event ) |
595 | { | 595 | { |
596 | if ( isEnabled() ) | 596 | if ( isEnabled() ) |
597 | { | 597 | { |
598 | switch( event.EventType ) | 598 | switch( event.EventType ) |
599 | { | 599 | { |
600 | case EET_GUI_EVENT: | 600 | case EET_GUI_EVENT: |
601 | switch( event.GUIEvent.EventType ) | 601 | switch( event.GUIEvent.EventType ) |
602 | { | 602 | { |
603 | case gui::EGET_SCROLL_BAR_CHANGED: | 603 | case gui::EGET_SCROLL_BAR_CHANGED: |
604 | if( event.GUIEvent.Caller == ScrollBarV || event.GUIEvent.Caller == ScrollBarH ) | 604 | if( event.GUIEvent.Caller == ScrollBarV || event.GUIEvent.Caller == ScrollBarH ) |
605 | { | 605 | { |
606 | //s32 pos = ( ( gui::IGUIScrollBar* )event.GUIEvent.Caller )->getPos(); | 606 | //s32 pos = ( ( gui::IGUIScrollBar* )event.GUIEvent.Caller )->getPos(); |
607 | return true; | 607 | return true; |
608 | } | 608 | } |
609 | break; | 609 | break; |
610 | case gui::EGET_ELEMENT_FOCUS_LOST: | 610 | case gui::EGET_ELEMENT_FOCUS_LOST: |
611 | { | 611 | { |
612 | Selecting = false; | 612 | Selecting = false; |
613 | return false; | 613 | return false; |
614 | } | 614 | } |
615 | break; | 615 | break; |
616 | default: | 616 | default: |
617 | break; | 617 | break; |
618 | } | 618 | } |
619 | break; | 619 | break; |
620 | case EET_MOUSE_INPUT_EVENT: | 620 | case EET_MOUSE_INPUT_EVENT: |
621 | { | 621 | { |
622 | core::position2d<s32> p( event.MouseInput.X, event.MouseInput.Y ); | 622 | core::position2d<s32> p( event.MouseInput.X, event.MouseInput.Y ); |
623 | 623 | ||
624 | switch( event.MouseInput.Event ) | 624 | switch( event.MouseInput.Event ) |
625 | { | 625 | { |
626 | case EMIE_MOUSE_WHEEL: | 626 | case EMIE_MOUSE_WHEEL: |
627 | if ( ScrollBarV ) | 627 | if ( ScrollBarV ) |
628 | ScrollBarV->setPos( ScrollBarV->getPos() + (event.MouseInput.Wheel < 0 ? -1 : 1) * -10 ); | 628 | ScrollBarV->setPos( ScrollBarV->getPos() + (event.MouseInput.Wheel < 0 ? -1 : 1) * -10 ); |
629 | return true; | 629 | return true; |
630 | break; | 630 | break; |
631 | 631 | ||
632 | case EMIE_LMOUSE_PRESSED_DOWN: | 632 | case EMIE_LMOUSE_PRESSED_DOWN: |
633 | 633 | ||
634 | if (Environment->hasFocus(this) && !AbsoluteClippingRect.isPointInside(p) ) | 634 | if (Environment->hasFocus(this) && !AbsoluteClippingRect.isPointInside(p) ) |
635 | { | 635 | { |
636 | Environment->removeFocus(this); | 636 | Environment->removeFocus(this); |
637 | return false; | 637 | return false; |
638 | } | 638 | } |
639 | 639 | ||
640 | if( Environment->hasFocus( this ) && | 640 | if( Environment->hasFocus( this ) && |
641 | ( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) || | 641 | ( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) || |
642 | ( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) ) | 642 | ( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) ) |
643 | ) | 643 | ) |
644 | ) | 644 | ) |
645 | { | 645 | { |
646 | return true; | 646 | return true; |
647 | } | 647 | } |
648 | 648 | ||
649 | Selecting = true; | 649 | Selecting = true; |
650 | Environment->setFocus( this ); | 650 | Environment->setFocus( this ); |
651 | return true; | 651 | return true; |
652 | break; | 652 | break; |
653 | 653 | ||
654 | case EMIE_LMOUSE_LEFT_UP: | 654 | case EMIE_LMOUSE_LEFT_UP: |
655 | if( Environment->hasFocus( this ) && | 655 | if( Environment->hasFocus( this ) && |
656 | ( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) || | 656 | ( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) || |
657 | ( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) ) | 657 | ( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) ) |
658 | ) | 658 | ) |
659 | ) | 659 | ) |
660 | { | 660 | { |
661 | return true; | 661 | return true; |
662 | } | 662 | } |
663 | 663 | ||
664 | Selecting = false; | 664 | Selecting = false; |
665 | Environment->removeFocus( this ); | 665 | Environment->removeFocus( this ); |
666 | mouseAction( event.MouseInput.X, event.MouseInput.Y ); | 666 | mouseAction( event.MouseInput.X, event.MouseInput.Y ); |
667 | return true; | 667 | return true; |
668 | break; | 668 | break; |
669 | 669 | ||
670 | case EMIE_MOUSE_MOVED: | 670 | case EMIE_MOUSE_MOVED: |
671 | if( Selecting ) | 671 | if( Selecting ) |
672 | { | 672 | { |
673 | if( getAbsolutePosition().isPointInside( p ) ) | 673 | if( getAbsolutePosition().isPointInside( p ) ) |
674 | { | 674 | { |
675 | mouseAction( event.MouseInput.X, event.MouseInput.Y, true ); | 675 | mouseAction( event.MouseInput.X, event.MouseInput.Y, true ); |
676 | return true; | 676 | return true; |
677 | } | 677 | } |
678 | } | 678 | } |
679 | break; | 679 | break; |
680 | default: | 680 | default: |
681 | break; | 681 | break; |
682 | } | 682 | } |
683 | } | 683 | } |
684 | break; | 684 | break; |
685 | default: | 685 | default: |
686 | break; | 686 | break; |
687 | } | 687 | } |
688 | } | 688 | } |
689 | 689 | ||
690 | return Parent ? Parent->OnEvent( event ) : false; | 690 | return Parent ? Parent->OnEvent( event ) : false; |
691 | } | 691 | } |
692 | 692 | ||
693 | /*! | 693 | /*! |
694 | */ | 694 | */ |
695 | void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ ) | 695 | void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ ) |
696 | { | 696 | { |
697 | IGUITreeViewNode* oldSelected = Selected; | 697 | IGUITreeViewNode* oldSelected = Selected; |
698 | IGUITreeViewNode* hitNode = 0; | 698 | IGUITreeViewNode* hitNode = 0; |
699 | s32 selIdx=-1; | 699 | s32 selIdx=-1; |
700 | s32 n; | 700 | s32 n; |
701 | IGUITreeViewNode* node; | 701 | IGUITreeViewNode* node; |
702 | SEvent event; | 702 | SEvent event; |
703 | 703 | ||
704 | event.EventType = EET_GUI_EVENT; | 704 | event.EventType = EET_GUI_EVENT; |
705 | event.GUIEvent.Caller = this; | 705 | event.GUIEvent.Caller = this; |
706 | event.GUIEvent.Element = 0; | 706 | event.GUIEvent.Element = 0; |
707 | 707 | ||
708 | xpos -= AbsoluteRect.UpperLeftCorner.X; | 708 | xpos -= AbsoluteRect.UpperLeftCorner.X; |
709 | ypos -= AbsoluteRect.UpperLeftCorner.Y; | 709 | ypos -= AbsoluteRect.UpperLeftCorner.Y; |
710 | 710 | ||
711 | // find new selected item. | 711 | // find new selected item. |
712 | if( ItemHeight != 0 && ScrollBarV ) | 712 | if( ItemHeight != 0 && ScrollBarV ) |
713 | { | 713 | { |
714 | selIdx = ( ( ypos - 1 ) + ScrollBarV->getPos() ) / ItemHeight; | 714 | selIdx = ( ( ypos - 1 ) + ScrollBarV->getPos() ) / ItemHeight; |
715 | } | 715 | } |
716 | 716 | ||
717 | hitNode = 0; | 717 | hitNode = 0; |
718 | node = Root->getFirstChild(); | 718 | node = Root->getFirstChild(); |
719 | n = 0; | 719 | n = 0; |
720 | while( node ) | 720 | while( node ) |
721 | { | 721 | { |
722 | if( selIdx == n ) | 722 | if( selIdx == n ) |
723 | { | 723 | { |
724 | hitNode = node; | 724 | hitNode = node; |
725 | break; | 725 | break; |
726 | } | 726 | } |
727 | node = node->getNextVisible(); | 727 | node = node->getNextVisible(); |
728 | ++n; | 728 | ++n; |
729 | } | 729 | } |
730 | 730 | ||
731 | if( hitNode && xpos > hitNode->getLevel() * IndentWidth ) | 731 | if( hitNode && xpos > hitNode->getLevel() * IndentWidth ) |
732 | { | 732 | { |
733 | Selected = hitNode; | 733 | Selected = hitNode; |
734 | } | 734 | } |
735 | 735 | ||
736 | if( hitNode && !onlyHover | 736 | if( hitNode && !onlyHover |
737 | && xpos < hitNode->getLevel() * IndentWidth | 737 | && xpos < hitNode->getLevel() * IndentWidth |
738 | && xpos > ( hitNode->getLevel() - 1 ) * IndentWidth | 738 | && xpos > ( hitNode->getLevel() - 1 ) * IndentWidth |
739 | && hitNode->hasChildren() ) | 739 | && hitNode->hasChildren() ) |
740 | { | 740 | { |
741 | hitNode->setExpanded( !hitNode->getExpanded() ); | 741 | hitNode->setExpanded( !hitNode->getExpanded() ); |
742 | 742 | ||
743 | // post expand/collaps news | 743 | // post expand/collaps news |
744 | if( hitNode->getExpanded() ) | 744 | if( hitNode->getExpanded() ) |
745 | { | 745 | { |
746 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_EXPAND; | 746 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_EXPAND; |
747 | } | 747 | } |
748 | else | 748 | else |
749 | { | 749 | { |
750 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_COLLAPS; | 750 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_COLLAPS; |
751 | } | 751 | } |
752 | LastEventNode = hitNode; | 752 | LastEventNode = hitNode; |
753 | Parent->OnEvent( event ); | 753 | Parent->OnEvent( event ); |
754 | LastEventNode = 0; | 754 | LastEventNode = 0; |
755 | } | 755 | } |
756 | 756 | ||
757 | if( Selected && !Selected->isVisible() ) | 757 | if( Selected && !Selected->isVisible() ) |
758 | { | 758 | { |
759 | Selected = 0; | 759 | Selected = 0; |
760 | } | 760 | } |
761 | 761 | ||
762 | // post selection news | 762 | // post selection news |
763 | 763 | ||
764 | if( Parent && !onlyHover && Selected != oldSelected ) | 764 | if( Parent && !onlyHover && Selected != oldSelected ) |
765 | { | 765 | { |
766 | if( oldSelected ) | 766 | if( oldSelected ) |
767 | { | 767 | { |
768 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_DESELECT; | 768 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_DESELECT; |
769 | LastEventNode = oldSelected; | 769 | LastEventNode = oldSelected; |
770 | Parent->OnEvent( event ); | 770 | Parent->OnEvent( event ); |
771 | LastEventNode = 0; | 771 | LastEventNode = 0; |
772 | } | 772 | } |
773 | if( Selected ) | 773 | if( Selected ) |
774 | { | 774 | { |
775 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_SELECT; | 775 | event.GUIEvent.EventType = EGET_TREEVIEW_NODE_SELECT; |
776 | LastEventNode = Selected; | 776 | LastEventNode = Selected; |
777 | Parent->OnEvent( event ); | 777 | Parent->OnEvent( event ); |
778 | LastEventNode = 0; | 778 | LastEventNode = 0; |
779 | } | 779 | } |
780 | } | 780 | } |
781 | } | 781 | } |
782 | 782 | ||
783 | 783 | ||
784 | //! draws the element and its children | 784 | //! draws the element and its children |
785 | void CGUITreeView::draw() | 785 | void CGUITreeView::draw() |
786 | { | 786 | { |
787 | if( !IsVisible ) | 787 | if( !IsVisible ) |
788 | { | 788 | { |
789 | return; | 789 | return; |
790 | } | 790 | } |
791 | 791 | ||
792 | recalculateItemHeight(); // if the font changed | 792 | recalculateItemHeight(); // if the font changed |
793 | 793 | ||
794 | IGUISkin* skin = Environment->getSkin(); | 794 | IGUISkin* skin = Environment->getSkin(); |
795 | irr::video::IVideoDriver* driver = Environment->getVideoDriver(); | 795 | irr::video::IVideoDriver* driver = Environment->getVideoDriver(); |
796 | 796 | ||
797 | core::rect<s32>* clipRect = 0; | 797 | core::rect<s32>* clipRect = 0; |
798 | if( Clip ) | 798 | if( Clip ) |
799 | { | 799 | { |
800 | clipRect = &AbsoluteClippingRect; | 800 | clipRect = &AbsoluteClippingRect; |
801 | } | 801 | } |
802 | 802 | ||
803 | // draw background | 803 | // draw background |
804 | core::rect<s32> frameRect( AbsoluteRect ); | 804 | core::rect<s32> frameRect( AbsoluteRect ); |
805 | 805 | ||
806 | if( DrawBack ) | 806 | if( DrawBack ) |
807 | { | 807 | { |
808 | driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, | 808 | driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, |
809 | clipRect ); | 809 | clipRect ); |
810 | } | 810 | } |
811 | 811 | ||
812 | // draw the border | 812 | // draw the border |
813 | frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + 1; | 813 | frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + 1; |
814 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, | 814 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, |
815 | clipRect ); | 815 | clipRect ); |
816 | 816 | ||
817 | frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; | 817 | frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; |
818 | frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + 1; | 818 | frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + 1; |
819 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, | 819 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, |
820 | clipRect ); | 820 | clipRect ); |
821 | 821 | ||
822 | frameRect = AbsoluteRect; | 822 | frameRect = AbsoluteRect; |
823 | frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 1; | 823 | frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 1; |
824 | driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, | 824 | driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, |
825 | clipRect ); | 825 | clipRect ); |
826 | 826 | ||
827 | frameRect = AbsoluteRect; | 827 | frameRect = AbsoluteRect; |
828 | frameRect.UpperLeftCorner.Y = AbsoluteRect.LowerRightCorner.Y - 1; | 828 | frameRect.UpperLeftCorner.Y = AbsoluteRect.LowerRightCorner.Y - 1; |
829 | frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; | 829 | frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; |
830 | driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, | 830 | driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, |
831 | clipRect ); | 831 | clipRect ); |
832 | 832 | ||
833 | 833 | ||
834 | // draw items | 834 | // draw items |
835 | 835 | ||
836 | core::rect<s32> clientClip( AbsoluteRect ); | 836 | core::rect<s32> clientClip( AbsoluteRect ); |
837 | clientClip.UpperLeftCorner.Y += 1; | 837 | clientClip.UpperLeftCorner.Y += 1; |
838 | clientClip.UpperLeftCorner.X += 1; | 838 | clientClip.UpperLeftCorner.X += 1; |
839 | clientClip.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X; | 839 | clientClip.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X; |
840 | clientClip.LowerRightCorner.Y -= 1; | 840 | clientClip.LowerRightCorner.Y -= 1; |
841 | 841 | ||
842 | if ( ScrollBarV ) | 842 | if ( ScrollBarV ) |
843 | clientClip.LowerRightCorner.X -= skin->getSize( EGDS_SCROLLBAR_SIZE ); | 843 | clientClip.LowerRightCorner.X -= skin->getSize( EGDS_SCROLLBAR_SIZE ); |
844 | if ( ScrollBarH ) | 844 | if ( ScrollBarH ) |
845 | clientClip.LowerRightCorner.Y -= skin->getSize( EGDS_SCROLLBAR_SIZE ); | 845 | clientClip.LowerRightCorner.Y -= skin->getSize( EGDS_SCROLLBAR_SIZE ); |
846 | 846 | ||
847 | if( clipRect ) | 847 | if( clipRect ) |
848 | { | 848 | { |
849 | clientClip.clipAgainst( *clipRect ); | 849 | clientClip.clipAgainst( *clipRect ); |
850 | } | 850 | } |
851 | 851 | ||
852 | frameRect = AbsoluteRect; | 852 | frameRect = AbsoluteRect; |
853 | frameRect.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X - skin->getSize( EGDS_SCROLLBAR_SIZE ); | 853 | frameRect.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X - skin->getSize( EGDS_SCROLLBAR_SIZE ); |
854 | frameRect.LowerRightCorner.Y = AbsoluteRect.UpperLeftCorner.Y + ItemHeight; | 854 | frameRect.LowerRightCorner.Y = AbsoluteRect.UpperLeftCorner.Y + ItemHeight; |
855 | 855 | ||
856 | if ( ScrollBarV ) | 856 | if ( ScrollBarV ) |
857 | { | 857 | { |
858 | frameRect.UpperLeftCorner.Y -= ScrollBarV->getPos(); | 858 | frameRect.UpperLeftCorner.Y -= ScrollBarV->getPos(); |
859 | frameRect.LowerRightCorner.Y -= ScrollBarV->getPos(); | 859 | frameRect.LowerRightCorner.Y -= ScrollBarV->getPos(); |
860 | } | 860 | } |
861 | 861 | ||
862 | if ( ScrollBarH ) | 862 | if ( ScrollBarH ) |
863 | { | 863 | { |
864 | frameRect.UpperLeftCorner.X -= ScrollBarH->getPos(); | 864 | frameRect.UpperLeftCorner.X -= ScrollBarH->getPos(); |
865 | frameRect.LowerRightCorner.X -= ScrollBarH->getPos(); | 865 | frameRect.LowerRightCorner.X -= ScrollBarH->getPos(); |
866 | } | 866 | } |
867 | 867 | ||
868 | IGUITreeViewNode* node = Root->getFirstChild(); | 868 | IGUITreeViewNode* node = Root->getFirstChild(); |
869 | while( node ) | 869 | while( node ) |
870 | { | 870 | { |
871 | frameRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + 1 + node->getLevel() * IndentWidth; | 871 | frameRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + 1 + node->getLevel() * IndentWidth; |
872 | 872 | ||
873 | if( frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y | 873 | if( frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y |
874 | && frameRect.UpperLeftCorner.Y <= AbsoluteRect.LowerRightCorner.Y ) | 874 | && frameRect.UpperLeftCorner.Y <= AbsoluteRect.LowerRightCorner.Y ) |
875 | { | 875 | { |
876 | if( node == Selected ) | 876 | if( node == Selected ) |
877 | { | 877 | { |
878 | driver->draw2DRectangle( skin->getColor( EGDC_HIGH_LIGHT ), frameRect, &clientClip ); | 878 | driver->draw2DRectangle( skin->getColor( EGDC_HIGH_LIGHT ), frameRect, &clientClip ); |
879 | } | 879 | } |
880 | 880 | ||
881 | if( node->hasChildren() ) | 881 | if( node->hasChildren() ) |
882 | { | 882 | { |
883 | core::rect<s32> rc; | 883 | core::rect<s32> rc; |
884 | core::rect<s32> expanderRect; | 884 | core::rect<s32> expanderRect; |
885 | 885 | ||
886 | expanderRect.UpperLeftCorner.X = frameRect.UpperLeftCorner.X - IndentWidth + 2; | 886 | expanderRect.UpperLeftCorner.X = frameRect.UpperLeftCorner.X - IndentWidth + 2; |
887 | expanderRect.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y + ( ( frameRect.getHeight() - ( IndentWidth - 4 ) ) >> 1 ); | 887 | expanderRect.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y + ( ( frameRect.getHeight() - ( IndentWidth - 4 ) ) >> 1 ); |
888 | expanderRect.LowerRightCorner.X = expanderRect.UpperLeftCorner.X + IndentWidth - 4; | 888 | expanderRect.LowerRightCorner.X = expanderRect.UpperLeftCorner.X + IndentWidth - 4; |
889 | expanderRect.LowerRightCorner.Y = expanderRect.UpperLeftCorner.Y + IndentWidth - 4; | 889 | expanderRect.LowerRightCorner.Y = expanderRect.UpperLeftCorner.Y + IndentWidth - 4; |
890 | 890 | ||
891 | // box upper line | 891 | // box upper line |
892 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; | 892 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; |
893 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; | 893 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; |
894 | rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X; | 894 | rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X; |
895 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; | 895 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; |
896 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, | 896 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, |
897 | clipRect ); | 897 | clipRect ); |
898 | 898 | ||
899 | // box left line | 899 | // box left line |
900 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; | 900 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; |
901 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; | 901 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; |
902 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; | 902 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; |
903 | rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y; | 903 | rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y; |
904 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, | 904 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, |
905 | clipRect ); | 905 | clipRect ); |
906 | 906 | ||
907 | // box right line | 907 | // box right line |
908 | rc.UpperLeftCorner.X = expanderRect.LowerRightCorner.X - 1; | 908 | rc.UpperLeftCorner.X = expanderRect.LowerRightCorner.X - 1; |
909 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; | 909 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; |
910 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; | 910 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; |
911 | rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y; | 911 | rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y; |
912 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, | 912 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, |
913 | clipRect ); | 913 | clipRect ); |
914 | 914 | ||
915 | // box bottom line | 915 | // box bottom line |
916 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; | 916 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; |
917 | rc.UpperLeftCorner.Y = expanderRect.LowerRightCorner.Y - 1; | 917 | rc.UpperLeftCorner.Y = expanderRect.LowerRightCorner.Y - 1; |
918 | rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X; | 918 | rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X; |
919 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; | 919 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; |
920 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, | 920 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, |
921 | clipRect ); | 921 | clipRect ); |
922 | 922 | ||
923 | // horizontal '-' line | 923 | // horizontal '-' line |
924 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X + 2; | 924 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X + 2; |
925 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + ( expanderRect.getHeight() >> 1 ); | 925 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + ( expanderRect.getHeight() >> 1 ); |
926 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + expanderRect.getWidth() - 4; | 926 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + expanderRect.getWidth() - 4; |
927 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; | 927 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; |
928 | driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, | 928 | driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, |
929 | clipRect ); | 929 | clipRect ); |
930 | 930 | ||
931 | if( !node->getExpanded() ) | 931 | if( !node->getExpanded() ) |
932 | { | 932 | { |
933 | // vertical '+' line | 933 | // vertical '+' line |
934 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X + ( expanderRect.getWidth() >> 1 ); | 934 | rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X + ( expanderRect.getWidth() >> 1 ); |
935 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + 2; | 935 | rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + 2; |
936 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; | 936 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; |
937 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + expanderRect.getHeight() - 4; | 937 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + expanderRect.getHeight() - 4; |
938 | driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, | 938 | driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, |
939 | clipRect ); | 939 | clipRect ); |
940 | } | 940 | } |
941 | } | 941 | } |
942 | 942 | ||
943 | core::rect<s32> textRect = frameRect; | 943 | core::rect<s32> textRect = frameRect; |
944 | 944 | ||
945 | if( Font ) | 945 | if( Font ) |
946 | { | 946 | { |
947 | EGUI_DEFAULT_COLOR textCol = EGDC_GRAY_TEXT; | 947 | EGUI_DEFAULT_COLOR textCol = EGDC_GRAY_TEXT; |
948 | if ( isEnabled() ) | 948 | if ( isEnabled() ) |
949 | textCol = ( node == Selected ) ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT; | 949 | textCol = ( node == Selected ) ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT; |
950 | 950 | ||
951 | s32 iconWidth = 0; | 951 | s32 iconWidth = 0; |
952 | for( s32 n = 0; n < 2; ++n ) | 952 | for( s32 n = 0; n < 2; ++n ) |
953 | { | 953 | { |
954 | s32 index = node->getImageIndex(); | 954 | s32 index = node->getImageIndex(); |
955 | if( ( ImageList && index >= 0 ) | 955 | if( ( ImageList && index >= 0 ) |
956 | && ( ( ImageLeftOfIcon && n == 0 ) | 956 | && ( ( ImageLeftOfIcon && n == 0 ) |
957 | || ( !ImageLeftOfIcon && n == 1 ) ) ) | 957 | || ( !ImageLeftOfIcon && n == 1 ) ) ) |
958 | { | 958 | { |
959 | index = node->getSelectedImageIndex(); | 959 | index = node->getSelectedImageIndex(); |
960 | if( node != Selected || index < 0 ) | 960 | if( node != Selected || index < 0 ) |
961 | { | 961 | { |
962 | index = node->getImageIndex(); | 962 | index = node->getImageIndex(); |
963 | } | 963 | } |
964 | ImageList->draw( | 964 | ImageList->draw( |
965 | index, | 965 | index, |
966 | core::position2d<s32>( | 966 | core::position2d<s32>( |
967 | textRect.UpperLeftCorner.X, | 967 | textRect.UpperLeftCorner.X, |
968 | textRect.UpperLeftCorner.Y + ( ( textRect.getHeight() - ImageList->getImageSize().Height ) >> 1 ) ), | 968 | textRect.UpperLeftCorner.Y + ( ( textRect.getHeight() - ImageList->getImageSize().Height ) >> 1 ) ), |
969 | &clientClip ); | 969 | &clientClip ); |
970 | iconWidth += ImageList->getImageSize().Width + 3; | 970 | iconWidth += ImageList->getImageSize().Width + 3; |
971 | textRect.UpperLeftCorner.X += ImageList->getImageSize().Width + 3; | 971 | textRect.UpperLeftCorner.X += ImageList->getImageSize().Width + 3; |
972 | } | 972 | } |
973 | else if( ( IconFont && reinterpret_cast<CGUITreeViewNode*>( node )->Icon.size() ) | 973 | else if( ( IconFont && reinterpret_cast<CGUITreeViewNode*>( node )->Icon.size() ) |
974 | && ( ( ImageLeftOfIcon && n == 1 ) | 974 | && ( ( ImageLeftOfIcon && n == 1 ) |
975 | || ( !ImageLeftOfIcon && n == 0 ) ) ) | 975 | || ( !ImageLeftOfIcon && n == 0 ) ) ) |
976 | { | 976 | { |
977 | IconFont->draw( node->getIcon(), textRect, skin->getColor(textCol), false, true, &clientClip ); | 977 | IconFont->draw( node->getIcon(), textRect, skin->getColor(textCol), false, true, &clientClip ); |
978 | iconWidth += IconFont->getDimension( node->getIcon() ).Width + 3; | 978 | iconWidth += IconFont->getDimension( node->getIcon() ).Width + 3; |
979 | textRect.UpperLeftCorner.X += IconFont->getDimension( node->getIcon() ).Width + 3; | 979 | textRect.UpperLeftCorner.X += IconFont->getDimension( node->getIcon() ).Width + 3; |
980 | } | 980 | } |
981 | } | 981 | } |
982 | 982 | ||
983 | Font->draw( node->getText(), textRect, skin->getColor(textCol), false, true, &clientClip ); | 983 | Font->draw( node->getText(), textRect, skin->getColor(textCol), false, true, &clientClip ); |
984 | 984 | ||
985 | textRect.UpperLeftCorner.X -= iconWidth; | 985 | textRect.UpperLeftCorner.X -= iconWidth; |
986 | } | 986 | } |
987 | 987 | ||
988 | // draw the lines if neccessary | 988 | // draw the lines if neccessary |
989 | if( LinesVisible ) | 989 | if( LinesVisible ) |
990 | { | 990 | { |
991 | core::rect<s32> rc; | 991 | core::rect<s32> rc; |
992 | 992 | ||
993 | // horizontal line | 993 | // horizontal line |
994 | rc.UpperLeftCorner.X = frameRect.UpperLeftCorner.X - IndentWidth - ( IndentWidth >> 1 ) - 1; | 994 | rc.UpperLeftCorner.X = frameRect.UpperLeftCorner.X - IndentWidth - ( IndentWidth >> 1 ) - 1; |
995 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y + ( ( frameRect.getHeight() ) >> 1 ); | 995 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y + ( ( frameRect.getHeight() ) >> 1 ); |
996 | if( node->hasChildren() ) | 996 | if( node->hasChildren() ) |
997 | { | 997 | { |
998 | rc.LowerRightCorner.X = frameRect.UpperLeftCorner.X - IndentWidth; | 998 | rc.LowerRightCorner.X = frameRect.UpperLeftCorner.X - IndentWidth; |
999 | } | 999 | } |
1000 | else | 1000 | else |
1001 | { | 1001 | { |
1002 | rc.LowerRightCorner.X = frameRect.UpperLeftCorner.X - 2; | 1002 | rc.LowerRightCorner.X = frameRect.UpperLeftCorner.X - 2; |
1003 | } | 1003 | } |
1004 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; | 1004 | rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; |
1005 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, | 1005 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, |
1006 | clipRect ); | 1006 | clipRect ); |
1007 | 1007 | ||
1008 | if( node->getParent() != Root ) | 1008 | if( node->getParent() != Root ) |
1009 | { | 1009 | { |
1010 | // vertical line | 1010 | // vertical line |
1011 | if( node == node->getParent()->getFirstChild() ) | 1011 | if( node == node->getParent()->getFirstChild() ) |
1012 | { | 1012 | { |
1013 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( ( frameRect.getHeight() - IndentWidth ) >> 1 ); | 1013 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( ( frameRect.getHeight() - IndentWidth ) >> 1 ); |
1014 | } | 1014 | } |
1015 | else | 1015 | else |
1016 | { | 1016 | { |
1017 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( frameRect.getHeight() >> 1 ); | 1017 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( frameRect.getHeight() >> 1 ); |
1018 | } | 1018 | } |
1019 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; | 1019 | rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; |
1020 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, | 1020 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, |
1021 | clipRect ); | 1021 | clipRect ); |
1022 | 1022 | ||
1023 | // the vertical lines of all parents | 1023 | // the vertical lines of all parents |
1024 | IGUITreeViewNode* nodeTmp = node->getParent(); | 1024 | IGUITreeViewNode* nodeTmp = node->getParent(); |
1025 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( frameRect.getHeight() >> 1 ); | 1025 | rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( frameRect.getHeight() >> 1 ); |
1026 | for( s32 n = 0; n < node->getLevel() - 2; ++n ) | 1026 | for( s32 n = 0; n < node->getLevel() - 2; ++n ) |
1027 | { | 1027 | { |
1028 | rc.UpperLeftCorner.X -= IndentWidth; | 1028 | rc.UpperLeftCorner.X -= IndentWidth; |
1029 | rc.LowerRightCorner.X -= IndentWidth; | 1029 | rc.LowerRightCorner.X -= IndentWidth; |
1030 | if( nodeTmp != nodeTmp->getParent()->getLastChild() ) | 1030 | if( nodeTmp != nodeTmp->getParent()->getLastChild() ) |
1031 | { | 1031 | { |
1032 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, | 1032 | driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, |
1033 | clipRect ); | 1033 | clipRect ); |
1034 | } | 1034 | } |
1035 | nodeTmp = nodeTmp->getParent(); | 1035 | nodeTmp = nodeTmp->getParent(); |
1036 | } | 1036 | } |
1037 | } | 1037 | } |
1038 | } | 1038 | } |
1039 | } | 1039 | } |
1040 | 1040 | ||
1041 | frameRect.UpperLeftCorner.Y += ItemHeight; | 1041 | frameRect.UpperLeftCorner.Y += ItemHeight; |
1042 | frameRect.LowerRightCorner.Y += ItemHeight; | 1042 | frameRect.LowerRightCorner.Y += ItemHeight; |
1043 | 1043 | ||
1044 | node = node->getNextVisible(); | 1044 | node = node->getNextVisible(); |
1045 | } | 1045 | } |
1046 | 1046 | ||
1047 | IGUIElement::draw(); | 1047 | IGUIElement::draw(); |
1048 | } | 1048 | } |
1049 | 1049 | ||
1050 | //! Sets the font which should be used as icon font. This font is set to the Irrlicht engine | 1050 | //! Sets the font which should be used as icon font. This font is set to the Irrlicht engine |
1051 | //! built-in-font by default. Icons can be displayed in front of every list item. | 1051 | //! built-in-font by default. Icons can be displayed in front of every list item. |
1052 | //! An icon is a string, displayed with the icon font. When using the build-in-font of the | 1052 | //! An icon is a string, displayed with the icon font. When using the build-in-font of the |
1053 | //! Irrlicht engine as icon font, the icon strings defined in GUIIcons.h can be used. | 1053 | //! Irrlicht engine as icon font, the icon strings defined in GUIIcons.h can be used. |
1054 | void CGUITreeView::setIconFont( IGUIFont* font ) | 1054 | void CGUITreeView::setIconFont( IGUIFont* font ) |
1055 | { | 1055 | { |
1056 | s32 height; | 1056 | s32 height; |
1057 | 1057 | ||
1058 | if ( font ) | 1058 | if ( font ) |
1059 | font->grab(); | 1059 | font->grab(); |
1060 | if ( IconFont ) | 1060 | if ( IconFont ) |
1061 | { | 1061 | { |
1062 | IconFont->drop(); | 1062 | IconFont->drop(); |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | IconFont = font; | 1065 | IconFont = font; |
1066 | if( IconFont ) | 1066 | if( IconFont ) |
1067 | { | 1067 | { |
1068 | height = IconFont->getDimension( L" " ).Height; | 1068 | height = IconFont->getDimension( L" " ).Height; |
1069 | if( height > ItemHeight ) | 1069 | if( height > ItemHeight ) |
1070 | { | 1070 | { |
1071 | ItemHeight = height; | 1071 | ItemHeight = height; |
1072 | } | 1072 | } |
1073 | } | 1073 | } |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | //! Sets the image list which should be used for the image and selected image of every node. | 1076 | //! Sets the image list which should be used for the image and selected image of every node. |
1077 | //! The default is 0 (no images). | 1077 | //! The default is 0 (no images). |
1078 | void CGUITreeView::setImageList( IGUIImageList* imageList ) | 1078 | void CGUITreeView::setImageList( IGUIImageList* imageList ) |
1079 | { | 1079 | { |
1080 | if (imageList ) | 1080 | if (imageList ) |
1081 | imageList->grab(); | 1081 | imageList->grab(); |
1082 | if( ImageList ) | 1082 | if( ImageList ) |
1083 | { | 1083 | { |
1084 | ImageList->drop(); | 1084 | ImageList->drop(); |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | ImageList = imageList; | 1087 | ImageList = imageList; |
1088 | if( ImageList ) | 1088 | if( ImageList ) |
1089 | { | 1089 | { |
1090 | if( ImageList->getImageSize().Height + 1 > ItemHeight ) | 1090 | if( ImageList->getImageSize().Height + 1 > ItemHeight ) |
1091 | { | 1091 | { |
1092 | ItemHeight = ImageList->getImageSize().Height + 1; | 1092 | ItemHeight = ImageList->getImageSize().Height + 1; |
1093 | } | 1093 | } |
1094 | } | 1094 | } |
1095 | } | 1095 | } |
1096 | 1096 | ||
1097 | } // end namespace gui | 1097 | } // end namespace gui |
1098 | } // end namespace irr | 1098 | } // end namespace irr |
1099 | 1099 | ||
1100 | 1100 | ||
1101 | #endif // _IRR_COMPILE_WITH_GUI_ | 1101 | #endif // _IRR_COMPILE_WITH_GUI_ |