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

Mouse event: event when the mouse is pressed, released, dragged or moved. More...

Inheritance diagram for guit::GMouseEvent:
guit::GEvent

Public Member Functions

GMouseEventasMouseEvent () override
 Returns the event casted to the specified event subclass. More...
 
GMouseEventtoMouseEvent () override
 Returns the event casted to the specified event subclass. More...
 
int button () const
 Returns the button that was just pressed or released. More...
 
int clickCount () const
 Returns the number of mouse clicks on click events. More...
 
GEventState state () const
 Returns an ORed combination of buttons and modifiers; see GEvent::States. More...
 
void redirectEvent (Gadget &to_gadget)
 Redirects the event to this gadget. 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.
 
GPoint pos () const
 Returns the position relative to the sender().
 
const GPointwpos () const
 Returns the position relative to the window().
 
float dx () const
 Returns the displacement from last GMouseEvent. More...
 
bool shiftPressed () const
 Returns the modifier keys that are currently pressed.
 
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

Mouse event: event when the mouse is pressed, released, dragged or moved.

Corresponding triggers: GTrigger::mousedown, mouseup, mousedrag, mousemove

Member Function Documentation

GMouseEvent& guit::GMouseEvent::asMouseEvent ( )
inlineoverridevirtual

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 from guit::GEvent.

GMouseEvent* guit::GMouseEvent::toMouseEvent ( )
inlineoverridevirtual

Returns the event casted to the specified event subclass.

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

Reimplemented from guit::GEvent.

float guit::GMouseEvent::dx ( ) const
inline

Returns the displacement from last GMouseEvent.

int guit::GMouseEvent::button ( ) const
inline

Returns the button that was just pressed or released.

Returns an int that is > 0 for mousedown and mouseup events (see GTrigger) and 0 otherwise. 1 indicates the left mouse button, 2 the right button, 3 the middle button, etc.

Note
Returns 0 for mousemove and mousedrag events.
Use state() to get the buttons that were previously pressed (if any).
int guit::GMouseEvent::clickCount ( ) const
inline

Returns the number of mouse clicks on click events.

The returned value should only be used for click events (see GTrigger).

GEventState guit::GMouseEvent::state ( ) const
inline

Returns an ORed combination of buttons and modifiers; see GEvent::States.

for on::mousedown events the button that was just pressed is not included in the state.

void guit::GMouseEvent::redirectEvent ( Gadget to_gadget)

Redirects the event to this gadget.

Useful when creating gadgets interactively: typically the event is fisrt caught by a drawing panel, a gadget can then be created on this panel and the event can redirected to this gadget as if it received the event. This allows resizing or moving the gadget interactively it it has a GDragSize or a GDragPos prop.

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 files: