xyginext  0.2.0
Second generation of xygine game creation framework
Classes | Public Types | Public Member Functions | List of all members
xy::UISystem Class Referencefinal

Updates entities with UIHitBox components. Any entity with a UIHitBox component will be processed by this system, which detects user input and activates the appropriate callback as necessary. More...

#include <UISystem.hpp>

Inheritance diagram for xy::UISystem:
xy::System

Public Types

enum  Flags { RightMouse = 0x1, LeftMouse = 0x2, MiddleMouse = 0x4, Finger = 0x8 }
 Input flags. Use these with the callback bitmask to find which input triggered it.
 
using MouseButtonCallback = std::function< void(Entity, sf::Uint64 flags)>
 
using MovementCallback = std::function< void(Entity, sf::Vector2f)>
 
using MouseWheelCallback = std::function< void(Entity, bool, float)>
 
using KeyboardCallback = std::function< void(Entity, sf::Keyboard::Key)>
 
using SelectionChangedCallback = std::function< void(Entity)>
 
using ControllerCallback = std::function< void(Entity, sf::Uint32, sf::Uint32)>
 
- Public Types inherited from xy::System
using Ptr = std::unique_ptr< System >
 

Public Member Functions

 UISystem (MessageBus &)
 
void handleEvent (const sf::Event &)
 Used to pass in any events the system may be interested in.
 
void process (float) override
 Performs processing.
 
void handleMessage (const Message &) override
 Message handler.
 
std::uint32_t addMouseButtonCallback (const MouseButtonCallback &)
 Adds a mouse button event callback. More...
 
std::uint32_t addMouseMoveCallback (const MovementCallback &)
 Adds a mouse or touch input movement callback. This is similar to button even callbacks, only the movement delta is passed in as a parameter instead of a button ID. These are also used for mouse enter/exit events Note that a single callback ID may be assigned to multiple UIHitbox components.
 
std::uint32_t addMouseWheelCallback (const MouseWheelCallback &)
 Adds a mouse wheel input callback. Mouse wheel callbacks handle scroll events from the mouse wheel. Callback parameters are: Entity the current UI entity which triggered this callback bool true if the mouse wheel is vertical (most common) false if it is horizontal float delta - positive is up/left, negative is down/right. May be non-integral on some mice. More...
 
std::uint32_t addKeyCallback (const KeyboardCallback &)
 Adds a KeyEvent callback. More...
 
std::uint32_t addSelectionCallback (const SelectionChangedCallback &)
 Adds a selection changed callback. This is raised for each UIHitbox component as it either either selected or unselected. The callback function passes in the entity which is affected by the callback. Note that a single callback ID may be assigned to multiple UIHitbox components.
 
std::uint32_t addControllerCallback (const ControllerCallback &)
 Adds a Controller Button callback. The callback passes in the entity which is affects, as well as the controller ID and Button ID which triggered the event.
 
void selectInput (std::size_t)
 Selects the input at the given index if it exists. This is applied to the active group of components. More...
 
void setJoypadCursorActive (bool active)
 Enables controlling the mouse cursor with the controller connected to port 0. When this is enabled all mouse movement callbacks are executed as they would with a normal mouse move, controller button and mouse button callbacks remain unchanged. More...
 
void setActiveGroup (std::size_t)
 Sets the active group of UIHitbox components. By default all components are added to group 0. If a single UISystem handles multiple menus, for example, UIHitbox components can be grouped by a given index, one for each menu. This function will set the active group of UIHitbox components to recieve events. More...
 
- Public Member Functions inherited from xy::System
 System (MessageBus &mb, UniqueType t)
 Constructor. Pass in a reference to the concrete implementation to generate a unique type ID for this system.
 
UniqueType getType () const
 Returns the unique type ID of the system.
 
const std::vector< Entity > & getEntities () const
 Returns a list of entities that this system is currently interested in.
 
void addEntity (Entity)
 Adds an entity to the list to process.
 
void removeEntity (Entity)
 Removes an entity from the list to process.
 
const ComponentMask & getComponentMask () const
 Returns the component mask used to mask entities with corresponding components for this system to process.
 
bool isActive () const
 Returns true if the system is currently active. Systems can be activeated and deactivated with Scene::setSystemActive()
 
template<typename T >
void requireComponent ()
 
template<typename T >
T * postMessage (Message::ID id)
 

Additional Inherited Members

- Protected Member Functions inherited from xy::System
template<typename T >
void requireComponent ()
 Adds a component type to the list of components required by the system for it to be interested in a particular entity. This should only be used in the constructor of the System else types will not be registered.
 
std::vector< Entity > & getEntities ()
 
template<typename T >
T * postMessage (Message::ID id)
 Posts a message on the system wide message bus.
 
MessageBusgetMessageBus ()
 Returns a reference to the MessageBus.
 
void setScene (Scene &)
 
ScenegetScene ()
 Returns a pointer to the scene to which this system belongs.
 

Detailed Description

Updates entities with UIHitBox components. Any entity with a UIHitBox component will be processed by this system, which detects user input and activates the appropriate callback as necessary.

See also
UIHitBox

Member Function Documentation

◆ addKeyCallback()

std::uint32_t xy::UISystem::addKeyCallback ( const KeyboardCallback &  )

Adds a KeyEvent callback.

Parameters
callbackKeyboardCallback which provides the current entity and the SFML key which triggered the event
Returns
ID of the callback. This should be used to assigned the callback to the relative callback slot of a UIInput component. eg: auto id = system.addCallback(cb); component.callbacks[UIInput::KeyDown] = id; Note that a single callback ID may be assigned to multiple UIHitbox components

◆ addMouseButtonCallback()

std::uint32_t xy::UISystem::addMouseButtonCallback ( const MouseButtonCallback &  )

Adds a mouse button event callback.

Returns
ID of the callback. This should be used to assigned the callback to the relative callback slot of a UIInput component. eg: auto id = system.addCallback(cb); component.callbacks[UIInput::MouseDown] = id; Note that a single callback ID may be assigned to multiple UIHitbox components

◆ addMouseWheelCallback()

std::uint32_t xy::UISystem::addMouseWheelCallback ( const MouseWheelCallback &  )

Adds a mouse wheel input callback. Mouse wheel callbacks handle scroll events from the mouse wheel. Callback parameters are: Entity the current UI entity which triggered this callback bool true if the mouse wheel is vertical (most common) false if it is horizontal float delta - positive is up/left, negative is down/right. May be non-integral on some mice.

Returns
A callback ID which may be assigned to multiple UIHitboxes

◆ selectInput()

void xy::UISystem::selectInput ( std::size_t  )

Selects the input at the given index if it exists. This is applied to the active group of components.

See also
setActiveGroup()

◆ setActiveGroup()

void xy::UISystem::setActiveGroup ( std::size_t  )

Sets the active group of UIHitbox components. By default all components are added to group 0. If a single UISystem handles multiple menus, for example, UIHitbox components can be grouped by a given index, one for each menu. This function will set the active group of UIHitbox components to recieve events.

See also
UIHitbox::setGroup()

◆ setJoypadCursorActive()

void xy::UISystem::setJoypadCursorActive ( bool  active)

Enables controlling the mouse cursor with the controller connected to port 0. When this is enabled all mouse movement callbacks are executed as they would with a normal mouse move, controller button and mouse button callbacks remain unchanged.

Parameters
activeIf true enables controlling the mouse cursor with the controller