User Interface Events

// Generates user interface events. Predefined user interface controls are not provided, Use UIEvents with 
// visual overlay components to build custom user interface elements.
class RVAPI UIEvents
{
public:
    // Generated event.
    enum class Event
    {
        NONE, MOUSEDOWN, MOUSEUP, SINGLECLICK, DOUBLECLICK, TRIPLECLICK, WHEELUP,
        WHEELDOWN, STARTDRAG, DRAG, ENDDRAG, ROP, KEY, CHAR, RESIZE, CLOSE
    };

    // Input state.
    enum class State
    {
        DISABLED, NORMAL, HOVERED, HIGHLIGHTED, CLICKED, STATIC
    };

    // Control attributes.
    enum Attribs
    {
        WHEEL = 1, DRAGGABLE = 2, STATIC = 4
    };

    // Check if state change.
    bool IsStateChange() const;

    // Check if selected.
    bool IsSelected() const;

    // Check if disabled.
    bool IsDisabled() const;

    // Get character from character event.
    wchar GetChar() const;

    // Get mouse click position.
    S2i GetMseClickPos() const;

    // Get state.
    State GetState() const;

    // Get state color.
    Color GetStateColor() const;

    // Get focused host entity.
    Event GetEvent() const;

    // Get focused host entity.
    static EntKey GetFocused();

    // Get clicked host entity.
    static EntKey GetClicked();

    // Get dragged host entity.
    static EntKey GetDragged();

    // Get dropped host entity.
    static EntKey GetDropped();

    // Update events inside parent rectangle.
    Event Update(const B2i &pRect);

    // Set disabled.
    void SetDisabled(bool disabled = true);

    // Set selected.
    void SetSelected(bool selected = true);

    // Set this events object to receive keyboard events.
    void SetFocus();

    // Clear keyboard focus.
    static void ClearFocus();

    // Clear all pending events.
    static void ClearEvents();

    // Internal.
    void *operator () () const { return (void *)wobj; }

    // Construct UI events object. [host] is the entity that contains this element. [stateColors] 
    // allows overriding the colors used for showing element state, or pass 0 for the defaults. 
    // [attribs] is a combination of the RVUIEAttribs flags or 0. [maxClicks] is the maximum number of 
    // mouse clicks the element will wait for. Default is 1.
    UIEvents(EntKey host, Color *stateColors = 0, uint attribs = 0, uint maxClicks = 1);

    // Destructor.
    ~UIEvents();

private:
    byte wobj[128];
};