All pages
Powered by GitBook
1 of 5

Loading...

Loading...

Loading...

Loading...

Loading...

CallClick

Introduction

The CallClick method forces the implementing IWindow to raise its Click event. This can be used to test clicking events or to allow other input or logic to simulate a button click.

Code Example

The following calls click when the space bar is pressed.

IWindow

Introduction

The IWindow interface is an interface that enables objects to be added to the GuiManager. Once an object is added to the GuiManager it will automatically be tested for Cursor events. The IWindow interface can be used to simplify the implementation of buttons, check boxes, and any other types of UI elements which may need to interact with the cursor.

IWindow and Glue

Although IWindow can be implemented manually in code, the IWindow interface is most typically implemented by Glue in generated code. For more information on IWindow in Glue, see this page.

bool wasSpacePushed = InputManager.Keyboard.KeyPushed(Keys.Space);

if(wasKeyPushed)
{
   WindowInstance.CallClick();
}

ReceiveInput

The ReceiveInput function is called every frame by the FlatRedBall Engine on the current IInputReceiver. This function can be used by objects implementing the IIputReceiver interface to handle input and to clear it after processing it.

ReceiveInput is ultimately called when the Keyboard's state is updated inside the FlatRedBall Engine. This means that this method is called *before* any Screen or Entity activity if using Glue. If not using Glue, and if all of your custom code is written *after* FlatRedBallServices.Update (which is called in your Game class) then the ReceiveInput will also be called before any of your custom code. This is useful because it allows the current IInputReceiver to receive and clear input before any other custom game logic is performed. In other words, no game code will need to be modified to prevent double-input from happening if the IInputReceiver calls the Keyboard's Clear function after processing input.

IInputReceiver

Introduction

The IInputReceiver interface provides methods and properties common to all UI elements which can receive input from devices such as the Keyboard or Xbox360GamePads. Any object which implements the IInputReceiver can be assigned to the InputManager's InputReceiver.

Only one instance can be assigned as the InputManager.InputReceiver property. If assigned, this instance has a number of methods called upon being assigned as well as in response to input. Its OnFocusUpdate is also called every frame automatically.

OnFocusUpdate and FlatRedBall.Forms

FlatRedBall.Forms elements typically receive input in one of two ways:

  1. In response to Cursor clicks. These events are ultimately raised by the underlying Gum objects (GraphicalUiElement)

  2. In response to changes in a keyboard state or Xbox360GamePad which is polled every-frame.

Forms elements which need to poll input every frame should do so by implementing IInputReceiver and checking input in the OnFocusUpdate.

For example, the following code could be used to perform custom actions whenever the A button is pressed on a Forms control which implements IInputReceiver:

For a full example of implementation, see the ListBox implementation:

Preventing multiple objects from receiving input

The IInputReceiver interface is designed to prevent multiple objects from receiving input. The most common way to do this is to have the IInputReceiver process input in its ReceiveInput method, then clear the input. For example, the following code can be used to move an object and clear the input.

This method is especially effective because ReceiveInput is called prior to the game's activity. For more information, see .

TakingInput

IInputReceivers automatically receive input from the keyboard when they have focus. To prevent this from occurring the TakingInput property can be set to false:

https://github.com/vchelaru/FlatRedBall/blob/NetStandard/Engines/Forms/FlatRedBall.Forms/FlatRedBall.Forms.Shared/Controls/ListBox.cs
the ReceiveInput page
public void OnFocusUpdate()
{
    var gamepads = GuiManager.GamePadsForUiControl;
    
    for (int i = 0; i < xboxGamepads.Count; i++)
    {
        var gamepad = xboxGamepads[i];
        if(gamepad.ButtonPushed(Button.A))
        {
            // perform logic here
        }
    }
}
// This assumes that the code exists in an object (such as a FlatRedBall Entity)
// which implements IInputReceiver
public void ReceiveInput()
{
   // First let's process the input:
   // This assumes that MovementSpeed is a valid variable - like a variable defined on an Entity in Glue
   Keyboard keyboard = InputManager.Keyboard;
   if(keyboard.KeyDown(Keys.Left))
   {
       this.XVelocity = -MovementSpeed;
   }
   else if(keyboard.KeyDown(Keys.Right))
   {
       this.XVelocity = MovementSpeed;
   }
   else
   {
       this.XVelocity = 0;
   }
   // Prevents anything else from getting keyboard input this frame
   keyboard.Clear();
}
// assuming the receiver is a valid receiver
receiver.TakingInput = false; // Will not be able to take input from the keyboard

Enabled

The Enabled property determines whether a UI element will react to input events, such as being clicked. IWindow instances which have their Enabled value set to false will be skipped over by the Cursor when performing UI checks; these instances will never be assigned to the Cursor.WindowOver property.