Treeview Control (GUI)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Veylon
Posts: 7
Joined: Wed Nov 15, 2006 7:21 pm

Treeview Control (GUI)

Post by Veylon »

I noticed that the one control the gui interface is missing is the tree control. For those who don't know what I'm talking about, look here:
Image
It basically does all the things the Windows one does. Click on the squares to show/hide the list. It's a work in progress, but it's looking pretty good so far. (By the way, it works for any font. Just so you know you aren't stuck with Xenotron.)

Get the code here: http://www.geocities.com/veylon_ii/TreeCtrl.zip

I'll add support for the event receiver so that you can know when something gets clicked and support for little icons, drag and drop, and all that jazz.
Rambus
Posts: 96
Joined: Thu Nov 24, 2005 4:56 pm
Location: Canada
Contact:

Post by Rambus »

Nifty, looks good!
goaty
Posts: 46
Joined: Wed Oct 25, 2006 3:06 pm

Post by goaty »

That's the biz. Excellent work there! :D
Veylon
Posts: 7
Joined: Wed Nov 15, 2006 7:21 pm

Post by Veylon »

Here's the new update version of the tree control: http://www.geocities.com/veylon_ii/TreeCtrl2.zip

Now it does work with the event receiver, just like all the other controls. A sample program is included to show how to use it. Also, it does the override font (like other controls) and supports an icon font, so the plus signs can be folders or something and have different icons for different nodes.

Try it out.
veegun
Posts: 59
Joined: Mon May 29, 2006 1:58 am

Post by veegun »

Shouldn't this be in the Project Announcement? :?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, it's a new GUI element you could easily add to your local Irrlicht library. Such code fragments are found in the snippets forum.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Looks nice !!! ;)
But there is a minor bug...
If you scroll to the side, the text will go outside the treeview:Image

And 2 cosmetic issues:
it would be nicer if the intern size of the treeview changes when tree nodes are opened or closed...
I mean if all nodes are closed, now the box has still the space to show all nodes...

And if you scroll up/down by using the mouse wheel, the scrollbar should also scroll up/down...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Veylon
Posts: 7
Joined: Wed Nov 15, 2006 7:21 pm

Post by Veylon »

Eck! It shouldn't do that!

I'll have to at least fix it to stay inside it's box. No 1 rule of GUI objects: no going outside of the box!

I'll probably need to have it update overall height/width internal sizes whenever a node gets opened or closed. I'll get back on this for Irrlicht 1.3.
mhack
Posts: 38
Joined: Sun Apr 01, 2007 2:13 am
Location: Montana, USA

Post by mhack »

Eck! It shouldn't do that!

I'll have to at least fix it to stay inside it's box. No 1 rule of GUI objects: no going outside of the box!
Here is a patch to fix the drawing outside of the box:

Code: Select all

--- orig/CGUITreeCtrl.cpp	Sun Jun 17 21:25:19 2007
+++ CGUITreeCtrl.cpp	Mon Jun 18 08:06:15 2007
@@ -374,6 +374,8 @@
 				{
 					MyClip = &clientClip;
 				}
+				// this seems to fix the horizontal clipping problem
+				MyClip = &clientClip;
 				s32 IconWidth = 0;
 				// Get Origin
 				// = ItemWidth to the left of the text
@@ -448,7 +450,8 @@
 					{
 						wchar_t Txt[2] = {node->Open ? node->IconOpen : node->IconClosed, L'\0'};
 						IconWidth = IconFont->getDimension(Txt).Width+1;
-						IconFont->draw(Txt, core::rect<s32>(Origin, Origin + core::position2d<s32>(IconWidth, ItemHeight)), col, false, true, MyClip);
+						// Use EGDC_BUTTON_TEXT color (colblk) for everything except selected text, otherwise it doesn't show properly against certain background colors
+						IconFont->draw(Txt, core::rect<s32>(Origin, Origin + core::position2d<s32>(IconWidth, ItemHeight)), colblk, false, true, MyClip);
 					}
 					else
 					{
@@ -467,17 +470,17 @@
 							// Horizontal
 							DrawHorizontalLine(
 								Origin + core::position2d<s32>(Frac18, Frac12),
-								SqSize, col, MyClip);
+								SqSize, colblk, MyClip);
 							// Vertical
 							DrawVerticalLine(
 								Origin + core::position2d<s32>(Frac12, Frac18),
-								SqSize, col, MyClip);
+								SqSize, colblk, MyClip);
 						}
 						// Draw Square (After, so it covers up and looks nice
-						DrawVerticalLine(UpperLeft, SqSize, col, MyClip);
-						DrawHorizontalLine(UpperLeft, SqSize, col, MyClip);
-						DrawVerticalLine(UpperRight, SqSize, col, MyClip);
-						DrawHorizontalLine(LowerLeft, SqSize, col, MyClip);
+						DrawVerticalLine(UpperLeft, SqSize, colblk, MyClip);
+						DrawHorizontalLine(UpperLeft, SqSize, colblk, MyClip);
+						DrawVerticalLine(UpperRight, SqSize, colblk, MyClip);
+						DrawHorizontalLine(LowerLeft, SqSize, colblk, MyClip);
 						IconWidth = ItemHeight;
 					}				
 				}
@@ -495,7 +498,8 @@
 					IconWidth = IconFont->getDimension(Txt).Width+1;
 				}
 				if(node == Selected)
-					video->draw2DRectangle(skin->getColor(gui::EGDC_3D_HIGH_LIGHT),core::rect<s32>(Origin + core::position2d<s32>(IconWidth,0), Origin + core::position2d<s32>(ItemHeight + Font->getDimension(node->Text.c_str()).Width+IconWidth-ItemHeight+1,ItemHeight)), &clientClip);
+//					video->draw2DRectangle(skin->getColor(gui::EGDC_3D_HIGH_LIGHT),core::rect<s32>(Origin + core::position2d<s32>(IconWidth,0), Origin + core::position2d<s32>(ItemHeight + Font->getDimension(node->Text.c_str()).Width+IconWidth-ItemHeight+1,ItemHeight)), &clientClip);
+					video->draw2DRectangle(skin->getColor(gui::EGDC_HIGH_LIGHT),core::rect<s32>(Origin + core::position2d<s32>(IconWidth,0), Origin + core::position2d<s32>(ItemHeight + Font->getDimension(node->Text.c_str()).Width+IconWidth-ItemHeight+1,ItemHeight)), &clientClip);
 				Font->draw(node->Text.c_str(),
 					core::rect<s32>
 					(	AbsoluteRect.UpperLeftCorner.X + (Indent-1)*ItemHeight + IconWidth + 2,
@@ -557,7 +561,12 @@
 	// Line can't be draw here
 	if(ClipRect)
 	{
-		if(!ClipRect->isPointInside(start))
+// this fixes the 'missing vert lines in top row' prob
+//		if(!ClipRect->isPointInside(start))
+//			return false;
+		rect<s32> ExpClipRect(	ClipRect->UpperLeftCorner - position2d<s32>(1,1), 
+								ClipRect->LowerRightCorner + position2d<s32>(1,1));
+		if(!ExpClipRect.isPointInside(start))
 			return;
 		if(start.Y + length > ClipRect->LowerRightCorner.Y)
 			length = ClipRect->LowerRightCorner.Y - start.Y;
@@ -901,3 +910,4 @@
 {
 	return OverrideFont;
 }
+
Post Reply