Disabling GUIButton
by Zvi Effron · in Torque X 2D · 03/27/2007 (4:44 pm) · 5 replies
I've been working with the control GUIButton (after finally figuring out how most of it works, with the image mapping at least). I've been able to create a demo program that shows the difference in the ButtonStates selected, normal, and pushed. However, I cannot get the button to be in the disabled state. I also have no idea what the hilight state is used for or how to set it. The only thing I can think of for hilight would be a mouse hovering over the button, but I can't figure out how to get hilighting to trigger.
#2
05/22/2008 (12:48 pm)
Anyone mind giving me a quick rundown as to how to get mouse-clicking on a GUIButton?
#3
05/26/2008 (8:03 am)
I think you can just set the button's active property to false to disable it. Then it sets it to the disabled color. So if you give the button a style defined as below then any button that's set to inactive will be grey.buttonStyle = new GUIButtonStyle();
buttonStyle.TextColor[CustomColor.ColorBase] = Color.Black;
buttonStyle.TextColor[CustomColor.ColorHL] = Color.Blue;
buttonStyle.TextColor[CustomColor.ColorNA] = Color.Gray;
buttonStyle.TextColor[CustomColor.ColorSEL] = Color.Gold;
buttonStyle.Focusable = true;
buttonStyle.FontType = "Arial22";
#4
05/26/2008 (8:08 am)
I don't think there's any way already in to check for mouse click on something. I just check for mouse position when its clicked and then check if there's a button under it.
#5
05/28/2008 (9:54 am)
Yeah, that makes sense - but my problem is how to find the GUIButton object??? I know how to use the findObect method, but am having a hard time returning a GUIButton object.//sample code
//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....
}thx
Torque 3D Owner Robert Blanchet Jr.