wlmaker
Loading...
Searching...
No Matches
interactive.h
Go to the documentation of this file.
1/* ========================================================================= */
24#ifndef __INTERACTIVE_H__
25#define __INTERACTIVE_H__
26
27#include <libbase/libbase.h>
28
29#define WLR_USE_UNSTABLE
30#include <wlr/types/wlr_buffer.h>
31#include <wlr/types/wlr_pointer.h>
32#include <wlr/types/wlr_scene.h>
33#undef WLR_USE_UNSTABLE
34
37
38#include "cursor.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif // __cplusplus
43
45typedef struct {
47 void (*enter)(wlmaker_interactive_t *interactive_ptr);
49 void (*leave)(wlmaker_interactive_t *interactive_ptr);
51 void (*motion)(
52 wlmaker_interactive_t *interactive_ptr,
53 double x, double y);
55 void (*focus)(wlmaker_interactive_t *interactive_ptr);
59 void (*button)(
60 wlmaker_interactive_t *interactive_ptr,
61 double x, double y,
62 struct wlr_pointer_button_event *wlr_pointer_button_event_ptr);
64 void (*destroy)(wlmaker_interactive_t *interactive_ptr);
66
69 wlmaker_interactive_t *interactive_ptr,
70 void *data_ptr);
71
76
78 bs_avltree_node_t avlnode;
79
82
84 struct wlr_scene_buffer *wlr_scene_buffer_ptr;
86 int width;
88 int height;
89
92};
93
106 wlmaker_interactive_t *interactive_ptr,
107 const wlmaker_interactive_impl_t *impl_ptr,
108 struct wlr_scene_buffer *wlr_scene_buffer_ptr,
109 wlmaker_cursor_t *cursor_ptr,
110 struct wlr_buffer *initial_wlr_buffer_ptr);
111
119 wlmaker_interactive_t *interactive_ptr,
120 struct wlr_buffer *wlr_buffer_ptr);
121
132 const wlmaker_interactive_t *interactive_ptr,
133 double x, double y) {
134 return (0 <= x && x < interactive_ptr->width &&
135 0 <= y && y < interactive_ptr->height);
136}
137
143static inline void wlmaker_interactive_enter(
144 wlmaker_interactive_t *interactive_ptr) {
145 if (!interactive_ptr->focussed) return;
146 interactive_ptr->impl->enter(interactive_ptr);
147}
148
158static inline void wlmaker_interactive_focus(
159 wlmaker_interactive_t *interactive_ptr,
160 bool focussed) {
161 interactive_ptr->focussed = focussed;
162 if (interactive_ptr->impl->focus) {
163 interactive_ptr->impl->focus(interactive_ptr);
164 }
165}
166
172static inline void wlmaker_interactive_leave(
173 wlmaker_interactive_t *interactive_ptr) {
174 interactive_ptr->impl->leave(interactive_ptr);
175}
176
184static inline void wlmaker_interactive_motion(
185 wlmaker_interactive_t *interactive_ptr,
186 double x, double y) {
187 if (!interactive_ptr->focussed) return;
188 interactive_ptr->impl->motion(interactive_ptr, x, y);
189}
190
203static inline void wlmaker_interactive_button(
204 wlmaker_interactive_t *interactive_ptr,
205 double x, double y,
206 struct wlr_pointer_button_event *wlr_pointer_button_event_ptr) {
207 interactive_ptr->impl->button(
208 interactive_ptr, x, y, wlr_pointer_button_event_ptr);
209}
210
219int wlmaker_interactive_node_cmp(const bs_avltree_node_t *node_ptr,
220 const void *key_ptr);
221
227void wlmaker_interactive_node_destroy(bs_avltree_node_t *node_ptr);
228
237 bs_avltree_node_t *node_ptr);
238
239#ifdef __cplusplus
240} // extern "C"
241#endif // __cplusplus
242
243#endif /* __INTERACTIVE_H__ */
244/* == End of interactive.h ================================================= */
static void wlmaker_interactive_focus(wlmaker_interactive_t *interactive_ptr, bool focussed)
Definition interactive.h:158
void wlmaker_interactive_init(wlmaker_interactive_t *interactive_ptr, const wlmaker_interactive_impl_t *impl_ptr, struct wlr_scene_buffer *wlr_scene_buffer_ptr, wlmaker_cursor_t *cursor_ptr, struct wlr_buffer *initial_wlr_buffer_ptr)
Definition interactive.c:30
wlmaker_interactive_t * wlmaker_interactive_from_avlnode(bs_avltree_node_t *node_ptr)
Definition interactive.c:87
int wlmaker_interactive_node_cmp(const bs_avltree_node_t *node_ptr, const void *key_ptr)
Definition interactive.c:64
static void wlmaker_interactive_motion(wlmaker_interactive_t *interactive_ptr, double x, double y)
Definition interactive.h:184
void(* wlmaker_interactive_callback_t)(wlmaker_interactive_t *interactive_ptr, void *data_ptr)
Definition interactive.h:68
static void wlmaker_interactive_button(wlmaker_interactive_t *interactive_ptr, double x, double y, struct wlr_pointer_button_event *wlr_pointer_button_event_ptr)
Definition interactive.h:203
void wlmaker_interactive_node_destroy(bs_avltree_node_t *node_ptr)
Definition interactive.c:80
static void wlmaker_interactive_leave(wlmaker_interactive_t *interactive_ptr)
Definition interactive.h:172
static void wlmaker_interactive_enter(wlmaker_interactive_t *interactive_ptr)
Definition interactive.h:143
static bool wlmaker_interactive_contains(const wlmaker_interactive_t *interactive_ptr, double x, double y)
Definition interactive.h:131
void wlmaker_interactive_set_texture(wlmaker_interactive_t *interactive_ptr, struct wlr_buffer *wlr_buffer_ptr)
Definition interactive.c:48
Definition cursor.h:34
Definition interactive.h:73
wlmaker_cursor_t * cursor_ptr
Definition interactive.h:91
bool focussed
Definition interactive.h:81
const wlmaker_interactive_impl_t * impl
Definition interactive.h:75
struct wlr_scene_buffer * wlr_scene_buffer_ptr
Definition interactive.h:84
int height
Definition interactive.h:88
int width
Definition interactive.h:86
bs_avltree_node_t avlnode
Definition interactive.h:78
Definition interactive.h:45
void(* motion)(wlmaker_interactive_t *interactive_ptr, double x, double y)
Definition interactive.h:51
void(* leave)(wlmaker_interactive_t *interactive_ptr)
Definition interactive.h:49
void(* focus)(wlmaker_interactive_t *interactive_ptr)
Definition interactive.h:55
void(* button)(wlmaker_interactive_t *interactive_ptr, double x, double y, struct wlr_pointer_button_event *wlr_pointer_button_event_ptr)
Definition interactive.h:59
void(* enter)(wlmaker_interactive_t *interactive_ptr)
Definition interactive.h:47