GraphicalUiElement as IWindow


FlatRedBall provides built-in logic which can be used for games that need cursor or touch-based UI. The three classes/interfaces providing this functionality are:

  • Cursor – an object providing cursor interaction like push, click, and hit testing with UI objects
  • GuiManager – a FlatRedBall manager which stores all live windows and drives every-frame logic like raising UI events
  • IWindow – an interface which allows an object to be managed by the GuiManager

Gum components implement the IWindow interface, and all component instances are automatically added to the GuiManager. In other words, if you have a component in your FlatRedBall screen, it can be used as an IWindow with no additional code.

Code Example – Dragging a Window

The following code shows how to grab and drag a Gum component instance with the mouse. Note that the following requirements must be met:

  1. On Windows the mouse must be visible
  2. The Gum object must be a component. Standard elements (such as ColoredRectangle instances) can also be moved with the mouse, but for simplicity this guide uses a component
  3. The component must have its Has Events value set to true. This is true by default for all components.

GuiManager Membership

Gum component instances which are added to a Gum screen in the Gum UI tool will automatically be added to the FlatRedBall GuiManager. Components which are created manually in code must be manually added to the GuiManager. Fortunately, calling AddToManagers is all that is needed. The following code is similar to the code above, except it manually creates a user control instance in code rather than using one created in a Gum screen.