Game Development Community

dev|Pro Game Development Curriculum

GuiArray2Ctrl - A new simple control for working w/ large arrays of controls

by Orion Elenzil · 09/15/2006 (2:31 pm) · 15 comments

Download Code File

from the .h included in the .zip:
Quote:
// This control's purpose is to create a regular array of a [large] number
// of controls of the same type. For example, if you wanted to display 100 GuiButtonCtrls
// in a regular array which was 7 cells high and however many cells wide.
//
// Script Usage:
//
// 1. Instanciate the GuiArray2Ctrl. eg "new GuiArray2Ctrl(myGuiArray2Ctrl){....}".
//
// 2. Set the following member variables:
// * ChildrenClassName - this is the class of the child controls you want. eg "GuiButtonCtrl".
// * ChildrenExtent - each child will be made this size. eg "100 50".
// * Spacing - the number of pixels between each child and its neighbors. eg "5".
// * InRows - whether we're arranging things in rows or columns. eg "false".
// * NumRowsOrCols - sets the number or rows or the number of cols, depending on InRows. eg "4".
// The above example settings are for an array of GuiButtonCtrls, each one 100x50, with 5 pixels
// between each one, arranged in 4 columns. the number of rows will vary w/ the next calls..
//
// 3. Call setNumChildren(). eg "myGuiArray2Ctrl.setNumChildren(100);".
// Together with the above example settings, this will get you 4 columns and 25 rows.
//
// 4. Optional but highly desirable:
// For each child created, the engine will call the "onCreatedChild()" method of the GuiArray2Ctrl.
// In that callback, you have the opportunity to customize the child control,
// for example setting the text, adding additional sub-controls, resizing, etc, etc.
// An example callback could look like this:
// function myGuiArray2Ctrl::onCreatedChild(%this, %child)
// {
// %child.setText("I'm child number" SPC %this.getCount());
// }
//
//
// Other Notes:
// * You probably want to put the Gui2ArrayCtrl inside a GuiScrollCtrl.
// In fact it's near-useless without that, but each to his own.
// * GuiControls are well-behaved w/r/t rendering only if they're actually visible,
// thus it can be reasonable to create a 4 x 100 array of controls
// even if only maybe twenty at a time are actually visible.
// * When saved to file (eg from the Gui Editor), GuiArray2Ctrl does not saves its children.
// * you can reseat the children via reseatChildren().

From the readme included in the .zip:
Quote:
1. Put guiArray2Ctrl.cc and .h in the folder engine/gui.
2. Add the two files to your compiler project.
3. Recompile.

Demo of 1,000 buttons:
4. Copy array2ctldemo.gui to client/. (as a sibling of PlayGui.gui).
5. Edit client/init.cs and right after this line:
exec("./playGui.gui");
insert this line:
exec("./array2ctldemo.gui");
6. rerun starter.fps !

#1
09/18/2006 (9:25 am)
img168.imageshack.us/img168/1285/guiarray2ctrldemovz8.jpganother snapshot
#2
09/18/2006 (2:25 pm)
I'm trying to think of what I could use this control for.... What are you using it for?
#3
09/18/2006 (2:35 pm)
good q!

you could use it as part of an inventory system or a character selection system,
or whenever you've got a large number of thumbnails.

in particular, i'm using it for clothing selection. See the snapshot w/ the 4 girls ? It's actually the exact same girl 4 times, but with a different shirt in each view. That's the idea. It should be rolled out as part of The Lounge sometime in october.
#4
09/25/2006 (12:24 pm)
Nice work
#5
10/19/2006 (7:30 pm)
The full glory of this control combined with GuiObjectView combined with dynamic mesh hiding combined with the multi-texturing resources can now be checked out in the "closet" portion of the beta 6 release of the lounge.
#6
10/24/2006 (12:10 am)
thanks for your resource!

by the way, how did you make chat balloons in the lounge?
it looks really nice and want to implement it.
can you give me some advice?
#7
11/07/2006 (12:01 am)
I get the following two errors compiling with TGE 1.5, using VS2005 Express.
These are the only errors:
(Edit: I did change the #include lines at the top of GuiArray2Ctrl.cc to reflect the new gui file structure. Nothing else was changed)
--------------------------
guiArray2Ctrl.obj : error LNK2001: unresolved external symbol "public: virtual class AbstractClassRep * __thiscall GuiArray2Ctrl::getClassRep(void)const " (?getClassRep@GuiArray2Ctrl@@UBEPAVAbstractClassRep@@XZ)
----------------------------
guiArray2Ctrl.obj : error LNK2019: unresolved external symbol "void __cdecl writeTabs(class Stream &,unsigned int)" (?writeTabs@@YAXAAVStream@@I@Z) referenced in function "public: virtual void __thiscall GuiArray2Ctrl::write(class Stream &,unsigned int,unsigned int)" (?write@GuiArray2Ctrl@@UAEXAAVStream@@II@Z)
#8
11/07/2006 (11:46 pm)
Hi Jesse -

hmm, sounds pretty weird.
i haven't got 1.5 yet, but i probably will in the next week or so.
i'll update the resource with how to compile in 1.5 as soon as i can!

edit: maybe try a build clean ?

thanks for the info.
#9
11/19/2006 (7:09 pm)
Ok, the fix for 1.5:

go into GuiArray2Ctrl.h, and add "void writeTabs(Stream &, U32);" with the other function declarations.
next, go into the cpp file, and at the end of the file, add:

AbstractClassRep* GuiArray2Ctrl::getClassRep() const
{
   return NULL;
}

void GuiArray2Ctrl::writeTabs(Stream &, U32)
{

}

recompile and all should be joyus.
#10
11/19/2006 (8:32 pm)
awesome, thanks for posting Jeff !
#11
12/24/2006 (6:17 pm)
Why would I get
starter.fps/client/ui/DragDropGui.gui (1710): Unable to instantiate non-conobject class GuiArray2Ctrl.


on the tge 1.5 head?
#12
12/24/2006 (6:55 pm)
ok, someone made an opps when coding this for 1.5.

At the top of GuiArray2Ctrl.cc right after the #includes, put

#include "console/console.h"
#include "console/consoleTypes.h"
#include "guiArray2Ctrl.h"




//-----------------------------------------------------------------------------
[b]IMPLEMENT_CONOBJECT( GuiArray2Ctrl );[/b]

and get rid of
/-----------------------------------------------------------------------------
//AbstractClassRep* GuiArray2Ctrl::getClassRep() const
//{
//   return NULL;
//}
#13
01/08/2007 (7:16 pm)
Ah, thanks guys, took me a bit to get back to this.

After the combination of Jeff and Vince's fixes, this works perfectly for me in 1.5

Thank you for this resource.
#14
02/07/2007 (7:45 am)
This is a great resource!
#15
10/23/2008 (11:42 pm)
have just learned there is a memory leak in this control:
when the number of children is reduced, for some reason i neglected to delete the no-longer-needed children.
i haven't yet updated the resource, but the fix is pretty darned simple.

that aside, this has proved to be a pretty robust and very useful control. we use it regularly with arrays of several hundred controls, and the performance is great.