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::GKeyEvent Class Reference

Key event: event when a key is pressed/released or when text in entered. More...

Inheritance diagram for guit::GKeyEvent:
guit::GEvent

Public Member Functions

GEventState state () const
 Returns an ORed combination of buttons and modifiers; see GEvent::States.
 
GKeyCode key () const
 Returns the keycode of the key that was pressed or released. More...
 
GString const & text () const
 Returns the entered text (in UTF8). More...
 
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

Key event: event when a key is pressed/released or when text in entered.

Corresponding triggers: GTrigger::keydown, keyup, type.

Member Function Documentation

GKeyCode guit::GKeyEvent::key ( ) const
inline

Returns the keycode of the key that was pressed or released.

may return 0 for on::keytype events.

GString const& guit::GKeyEvent::text ( ) const
inline

Returns the entered text (in UTF8).

may return "" for on::keydown and on::keyup events or if a modifier was pressed (e.g. ctrl-K)

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

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 ( )
inlinevirtualinherited

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
inherited

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
inherited

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
inlineinherited

Returns the input channel.

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

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

Returns the timestamp.

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

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

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 &)>   
)
staticinherited

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)
staticinherited

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)
staticinherited

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
staticinherited

Keycodes of special keys.

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


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