GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_event.h File Reference

An (input) event layer. More...

#include <stdint.h>
#include <string.h>
#include <utils/gp_types.h>
#include <input/gp_types.h>
#include <input/gp_keys.h>
#include <input/gp_event_keys.h>

Go to the source code of this file.

Data Structures

struct  gp_ev_pos_rel
 A relative cursor position change. More...
 
struct  gp_ev_pos_abs
 An absolute cursor position. More...
 
struct  gp_ev_key
 A key press/release/repeat event. More...
 
struct  gp_ev_sys_resize
 A value for the GP_EV_SYS_RENDER_RESIZE event. More...
 
struct  gp_events_state
 An input events state. More...
 
struct  gp_event
 An input event. More...
 

Macros

#define gp_ev_any_key_pressed(ev, ...)
 Checks for any key from a set to be pressed.
 
#define gp_ev_all_keys_pressed(ev, ...)
 Checks for all key from a set to be pressed.
 

Enumerations

enum  gp_ev_type {
  GP_EV_KEY = 1 , GP_EV_REL = 2 , GP_EV_ABS = 3 , GP_EV_SYS = 4 ,
  GP_EV_TMR = 5 , GP_EV_FD = 6 , GP_EV_MAX = 6
}
 An event type. More...
 
enum  gp_ev_key_code { GP_EV_KEY_UP = 0 , GP_EV_KEY_DOWN = 1 , GP_EV_KEY_REPEAT = 2 }
 A key event type. More...
 
enum  gp_ev_rel_code { GP_EV_REL_POS = 0 , GP_EV_REL_WHEEL = 8 }
 A relative event type. More...
 
enum  gp_ev_abs_code { GP_EV_ABS_POS = 0 }
 An absolute event type. More...
 
enum  gp_ev_sys_code {
  GP_EV_SYS_QUIT = 0 , GP_EV_SYS_RENDER_RESIZE = 1 , GP_EV_SYS_CLIPBOARD = 2 , GP_EV_SYS_BACKLIGHT = 3 ,
  GP_EV_SYS_FOCUS = 4 , GP_EV_SYS_RENDER_STOP = 5 , GP_EV_SYS_RENDER_START = 6 , GP_EV_SYS_RENDER_PIXEL_TYPE = 7
}
 System events. More...
 
enum  gp_ev_sys_focus_val { GP_EV_SYS_FOCUS_OUT = 0 , GP_EV_SYS_FOCUS_IN = 1 }
 Values for the GP_EV_SYS_FOCUS event. More...
 

Functions

static int gp_ev_utf_is_ctrl (const gp_event *ev)
 Checks if a character is not printable.
 
static void gp_events_state_press (gp_events_state *self, uint32_t key)
 Helper to set key bit in the event state.
 
static int gp_events_state_pressed (const gp_events_state *self, uint32_t key)
 Helper to get key bit from the event state.
 
static void gp_events_state_release (gp_events_state *self, uint32_t key)
 Helper to reset key bit in the event state.
 
static void gp_events_state_release_all (gp_events_state *self)
 Helper to reset all key bits in the event state.
 
static int gp_ev_key_pressed (const gp_event *ev, uint32_t key)
 Checks if key is being pressed.
 
void gp_ev_dump (const gp_event *ev)
 Dumps event into a stdout.
 

Detailed Description

An (input) event layer.

Input events combine events from HID devices, such as keyboard or mouse as well as other types of events such as timers, window resize, clipboard, etc.

Definition in file gp_event.h.

Macro Definition Documentation

◆ gp_ev_all_keys_pressed

#define gp_ev_all_keys_pressed ( ev,
... )
Value:
gp_ev_all_keys_pressed_(ev, __VA_ARGS__, 0)

Checks for all key from a set to be pressed.

Parameters
evAn input event.
...A list of key values to check for.
Returns
True if all keys from a list are pressed.

Definition at line 359 of file gp_event.h.

◆ gp_ev_any_key_pressed

#define gp_ev_any_key_pressed ( ev,
... )
Value:
gp_ev_any_key_pressed_(ev, __VA_ARGS__, 0)

Checks for any key from a set to be pressed.

Parameters
evAn input event.
...A list of key values to check for.
Returns
True if any key from a list is pressed.

Definition at line 349 of file gp_event.h.

Referenced by gp_widget_key_mod_pressed().

Enumeration Type Documentation

◆ gp_ev_abs_code

An absolute event type.

Enumerator
GP_EV_ABS_POS 

An absolute position.

Definition at line 66 of file gp_event.h.

◆ gp_ev_key_code

A key event type.

Enumerator
GP_EV_KEY_UP 

Key released.

GP_EV_KEY_DOWN 

Key pressed.

GP_EV_KEY_REPEAT 

Key repeated.

Key is pressed for some time and repeat event is generated.

Definition at line 44 of file gp_event.h.

◆ gp_ev_rel_code

A relative event type.

Enumerator
GP_EV_REL_POS 

A relative position.

GP_EV_REL_WHEEL 

A mouse wheel.

Definition at line 58 of file gp_event.h.

◆ gp_ev_sys_code

System events.

Enumerator
GP_EV_SYS_QUIT 

User requested application to quit.

This event is usually generated when user clicks on the button to close an application window.

GP_EV_SYS_RENDER_RESIZE 

The backend was resized.

The rendering is stopped with GP_EV_SYS_RENDER_STOP and the gp_backend::pixmap is resized only after the rendering stop was acknowledged by the application by calling the gp_backend_render_stopped().

Once the gp_backend::pixmap has been resized the this event is send followed by GP_EV_SYS_RENDER_START.

GP_EV_SYS_CLIPBOARD 

Clipboard request is ready.

When application requests clipboard data by gp_backend_clipboard_request() the data are fetched and this event arrives to the appliction once the data are ready.

GP_EV_SYS_BACKLIGHT 

Backlight brightness change.

When backend brightness was changed the new brightness in percents is stored in the val.

GP_EV_SYS_FOCUS 

A focus in or focus out event.

The event val is set to enum gp_ev_sys_focus_val.

GP_EV_SYS_RENDER_STOP 

Stops rendering.

Application must stop rendering into the gp_backend::pixmap when it receives GP_EV_SYS_RENDER_STOP and acknowledge to the backend that rendering has been stopped by calling the gp_backend_render_stopped().

During the time rendering is stopped the gp_backend::pixmap pointer is NULL.

GP_EV_SYS_RENDER_START 

Starts rendering.

The gp_backend::pixmap pointer is valid again.

GP_EV_SYS_RENDER_PIXEL_TYPE 

Pixel type for the rendering.

This event is send before first GP_EV_SYS_RENDER_START so that application can prepare colors for the rendering.

Definition at line 72 of file gp_event.h.

◆ gp_ev_sys_focus_val

Values for the GP_EV_SYS_FOCUS event.

Application starts in focused out state and should expect to be notified when it gains focus.

Attention
Focus events may arrive when render is stopped with GP_EV_SYS_RENDER_STOP.
Enumerator
GP_EV_SYS_FOCUS_OUT 

Application was focused out.

GP_EV_SYS_FOCUS_IN 

Appliaction was focused in.

Definition at line 152 of file gp_event.h.

◆ gp_ev_type

enum gp_ev_type

An event type.

Enumerator
GP_EV_KEY 

A key or button press event.

GP_EV_REL 

A relative event, e.g. mouse cursor movement.

GP_EV_ABS 

An absolute event, e.g. touchscreen touch.

GP_EV_SYS 

A system events, window close, resize, etc.

GP_EV_TMR 

A timer expired.

GP_EV_FD 

A poll event on a filescriptor.

GP_EV_MAX 

Last used event type.

Definition at line 26 of file gp_event.h.

Function Documentation

◆ gp_ev_dump()

void gp_ev_dump ( const gp_event * ev)

Dumps event into a stdout.

Parameters
evA pointer to an input event.

◆ gp_ev_key_pressed()

static int gp_ev_key_pressed ( const gp_event * ev,
uint32_t key )
inlinestatic

Checks if key is being pressed.

Parameters
evAn input event.
keyA key value to check for.
Returns
True if key is being pressed.

Definition at line 333 of file gp_event.h.

References gp_events_state_pressed(), and gp_event::st.

◆ gp_ev_utf_is_ctrl()

static int gp_ev_utf_is_ctrl ( const gp_event * ev)
inlinestatic

Checks if a character is not printable.

Parameters
evA key input event.
Returns
True if utf character is a control character (non-printable).

Definition at line 263 of file gp_event.h.

References gp_event::key, and gp_ev_key::utf.

◆ gp_events_state_press()

static void gp_events_state_press ( gp_events_state * self,
uint32_t key )
inlinestatic

Helper to set key bit in the event state.

Parameters
selfAn event state.
keyA key value to press.

Definition at line 277 of file gp_event.h.

References gp_events_state::keys_pressed.

◆ gp_events_state_pressed()

static int gp_events_state_pressed ( const gp_events_state * self,
uint32_t key )
inlinestatic

Helper to get key bit from the event state.

Parameters
selfAn event state.
keyA key value to get the state for.
Returns
True if the key pressed bit is set in the state keys bitmap.

Definition at line 293 of file gp_event.h.

References gp_events_state::keys_pressed.

Referenced by gp_ev_key_pressed().

◆ gp_events_state_release()

static void gp_events_state_release ( gp_events_state * self,
uint32_t key )
inlinestatic

Helper to reset key bit in the event state.

Parameters
selfAn event state.
keyA key value to release.

Definition at line 307 of file gp_event.h.

References gp_events_state::keys_pressed.

◆ gp_events_state_release_all()

static void gp_events_state_release_all ( gp_events_state * self)
inlinestatic

Helper to reset all key bits in the event state.

Parameters
selfAn event state.

Definition at line 320 of file gp_event.h.

References gp_events_state::keys_pressed.