How to use DGui

Controls must be registered with an instance of DGuiManager. You must pass your game object and a SpriteBatch object to the DGuiManager:

DGuiManager guiManager = new DGuiManager(this, spriteBatch);


Call DGuiManager.Update() in your update method to enable input to your controls.
Call DGuiManager.Draw() in your draw method to draw the controls.


To add a form to your game:

DForm form = new DForm(guiManager, "MainForm", null);
form.Size = new Vector2(640, 480);
form.Position = new Vector2(10, 10);
form.Initialize();
guiManager.AddControl(form);



Or to add a panel, using constructor parameters for size and position:

DPanel panel = new DPanel (guiManager, 5, 5, 640, 480);
panel.Initialize();
guiManager.AddControl(panel);



You can add a control to a form or panel (or another control) like so:

DButton button = new DButton (guiManager, 5, 5, "Button"); // Button at 5,5 with text "Button"
button.Initialize();
form.AddPanel(button);



To register events for your gui elements, you can do something like the following:

button.OnClick += new ButtonEventHandler(handleClick); // Register the click listener



There are many other properties to enable/disable hover color events, child panel clipping, accept focus, etc. Check out the demo in the source code for more examples.

Last edited Jul 3, 2010 at 4:14 AM by spamdog, version 3

Comments

No comments yet.