guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
guit::GEvent Class Reference

GUI Event: base of all events. More...

Inheritance diagram for guit::GEvent:
guit::GGestureEvent guit::GKeyEvent guit::GMouseEvent guit::GTouchEvent

Public Member Functions

Gadgetchosen () const
 Returns the checked child of a box that enforces exclusive selection. More...
 
GWindowwindow () const
 Returns the window where this event occured.
 
GTrigger const & trigger () const
 Returns the trigger that fired this event.
 
GEventType eventMask () const
 Returns the event mask.
 
int channel () const
 Returns the input channel. More...
 
GTime time () const
 Returns the timestamp. More...
 
void postFire (std::function< void(GEvent &)> const &todo_after)
 Sets a function that is called after firing all callbacks trigerred by a same event.
 
int matches (GTrigger const &trigger, int channel) const
 Returns a non-zero value if this trigger matches this event.
 
virtual GMouseEventasMouseEvent ()
 Returns the event casted to the specified event subclass. More...
 
virtual GMouseEventtoMouseEvent ()
 Returns the event casted to the specified event subclass. More...
 
Gadgetfrom () const
 Returns where this event occured. More...
 
GObjecttag () const
 Changes/returns the event tag. More...
 

Static Public Member Functions

static GEventState buttonToState (int mouse_button)
 Converts a mouse button number into an event state. More...
 
static GEventState modifierToState (GKeyCode modifier_key)
 Converts a modifier keycode intoto an event state.
 
static GEventState modifiersToStates (GString const &modifiers)
 Converts a combination of modifier names to ORed modifier states. More...
 
static void setMouseButtonHandler (int channel, std::function< bool(class GMouseEvent &)>)
 Sets a global handler that intercepts all the the events of the specified type. More...
 
static GString keyToName (GKeyCode key)
 Converts a key code into a key name and vice-versa.
 

Static Public Attributes

static const GKeyCode EscapeKey = SDLK_ESCAPE
 Keycodes of special keys. More...
 

Detailed Description

GUI Event: base of all events.

GUI events are produced when a trigger is fired, see GTrigger.

See Also
subclasses GMouseEvent, GKeyEvent, etc.

Member Function Documentation

GMouseEvent & guit::GEvent::asMouseEvent ( )
virtual

Returns the event casted to the specified event subclass.

Throws an exception that resets the event loop if the event does not derive from this subclass.

Reimplemented in guit::GMouseEvent.

virtual GMouseEvent* guit::GEvent::toMouseEvent ( )
inlinevirtual

Returns the event casted to the specified event subclass.

Returns null if if the event does not derive from this subclass.

Reimplemented in guit::GMouseEvent.

Gadget & guit::GEvent::from ( ) const

Returns where this event occured.

  • If the source is a Gadget, from() returns this gadget
  • If the source is a GBox gadget, fromBox() returns from() casted to GBox
  • If the source is a GProp, fromProp() returns this prop A GFatalError exception is thrown if the source is not from the expected type, which will quit all callback functions and restart the event loop.
    auto& txt = TextField()
    << [](GEvent& e){ std::cout << e.from().text(); };
Gadget * guit::GEvent::chosen ( ) const

Returns the checked child of a box that enforces exclusive selection.

Returns null if N/A, and the same value as GChoiceBox::chosen() otherwise.

auto& list = ListBox()
<< "one"
<< "two"
<< "three"
<< [](GEvent& e){ if (e.chosen()) std::cout << e.chosen()->text(); };
int guit::GEvent::channel ( ) const
inline

Returns the input channel.

Return 0 for system events, a value > 0 for other input channels (see GChannel).

GTime guit::GEvent::time ( ) const
inline

Returns the timestamp.

The timestamp is only defined for mouse/finger/key events.

GObject* guit::GEvent::tag ( ) const
inline

Changes/returns the event tag.

Can be useful when redirecting events (see GMouseEvent::redirectEvent) so that the gadget that redirects the event can pass data to the final receiver.

void guit::GEvent::setMouseButtonHandler ( int  channel,
std::function< bool(class GMouseEvent &)>   
)
static

Sets a global handler that intercepts all the the events of the specified type.

Events will then processed normally if the handler returns true, and ignored otherwise. Only one handler can be set for a given event type. Passing nullptr removes the corresponding handler.

GEventState guit::GEvent::buttonToState ( int  mouse_button)
static

Converts a mouse button number into an event state.

mouse_button = 1 returns GEventState::Button1 (left button), 2 returns Button 2 (right button), 3 returns Button3 (middle button), etc.

GEventState guit::GEvent::modifiersToStates ( GString const &  modifiers)
static

Converts a combination of modifier names to ORed modifier states.

Valid modifier names are: ctrl, shift, meta/cmd, alt, altgr, caps, num. They can be combined by adding a - or a + between them, e.g. ctrl-shift

Member Data Documentation

const GKeyCode guit::GEvent::EscapeKey = SDLK_ESCAPE
static

Keycodes of special keys.

GKeyEvent has a key() method that returns the keycode.


The documentation for this class was generated from the following files: