Game Development Community

Finding a GUIButton object....

by Anthony Ayers · in Torque X 2D · 05/28/2008 (11:12 am) · 4 replies

Could someone instruct me on how to use FindObject to locate a GUIButton??? This is what I have.....
//inside Game.cs
GUIButton guiButton = new guiButton();
TorqueObjectType button = TorqueObjectDatabase.Instance.GetObjectType("button");
guiButton.ObjectType +=button
guiButton.Style = buttonStyle;
guiButton.Size = new Vector2(50, 25);
guiButton.Position = new Vector2(20, offset);
int number = i + 1;
guiButton.ButtonText = number.ToString();
guiButton.Name = number.ToString();
guiButton.Folder = _inventoryCtrl;
guiButton.OnSelectedDelegate = GuiButtonSelected;
 guiButton.Bounds = new RectangleF(new Vector2(20, offset), new Vector2(50, 25));
guiButton.Active = true;
offset += 40;

//on mouse-click
List<ISceneContainerObject> foundGUI = new List<ISceneContainerObject>();
TorqueObjectType button = TorqueObjectDatabase.Instance.GetObjectType("button");
T2DSceneGraph mySceneGraph = (T2DSceneGraph)TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph");
mySceneGraph.FindObjects(coords, 1.0f, button, 0xFFFFFFFF, foundGUI);

                        if (foundGUI.Count > 0)
                        {
                            //do something here....
                        }


...my buttons are displayed to the screen, but the only thing I ever pull back is the T2dTileLayer????
PLEASE HELP!

#1
05/28/2008 (11:46 am)
I don't actually use TorqueX much, but I'm betting you don't want to look for gui objects in your sceneGraph. Use the method you used to find the sceneGraph, with the object database, to find your gui controls. If you need ones at a particular location on screen I don't know how to do that, but keep in mind you probably need to use screenSpace positions when doing that and not scene/world Space.
#2
05/28/2008 (2:43 pm)
Thats not true, I am pretty sure you can use the TorqueObjectDatabase to find GUIs
#3
05/28/2008 (3:21 pm)
That's what I said, right?

"Use the method you used to find the sceneGraph, with the object database, to find your gui controls."
#4
05/29/2008 (2:22 pm)
So, I figured out a way to determine whether or not a GUIButton is being clicked....
//try GUI button clicking
GUIButton btn = (GUIButton)TorqueObjectDatabase.Instance.FindObject("superbutton");
RectangleF btnLoc = new RectangleF(btn.Position, btn.Size);
MouseState m = Mouse.GetState();
RectangleF clickLoc = new RectangleF(new Vector2(m.X, m.Y), new Vector2(5, 5));
if (clickLoc.IntersectsWith(btnLoc))
{
    btn.ButtonText = "CLICK!";
}
...but now I am running into a "position" issue w/ the GUIButtons in the specific GUIControls. For instance,
I currently have a root GUIControl, which has another control in its folder which contains my GUIButton. I set the position of my GUIButton to 20,20, but that position is not 20,20 in screen coords? Does this make sense? So, unless I set my root folder position to zero, my sub-folder position to zero, and my GUIButons position to zero,I cant get my button click. Is there some way to reference the folders?? Any thoughts???