libvisual  0.5.0
lv_event.h
1 #ifndef _LV_EVENT_H
2 #define _LV_EVENT_H
3 
4 #include <libvisual/lv_songinfo.h>
5 #include <libvisual/lv_keysym.h>
6 
15 typedef enum {
28 } VisEventType;
29 
33 typedef enum {
36 } VisKeyState;
37 
41 typedef enum {
45 
46 typedef struct _VisEventKeyboard VisEventKeyboard;
47 typedef struct _VisEventMouseMotion VisEventMouseMotion;
48 typedef struct _VisEventMouseButton VisEventMouseButton;
49 typedef struct _VisEventResize VisEventResize;
50 typedef struct _VisEventNewSong VisEventNewSong;
51 typedef struct _VisEventQuit VisEventQuit;
52 typedef struct _VisEventVisibility VisEventVisibility;
53 typedef struct _VisEventParam VisEventParam;
54 typedef struct _VisEventCustom VisEventCustom;
55 typedef struct _VisEvent VisEvent;
56 
63  VisKeySym keysym;
64 };
65 
73  int x;
74  int y;
75  int xrel;
76  int yrel;
77 };
78 
86  int button;
87  int x;
88  int y;
89 };
90 
97  int width;
98  int height;
99 };
100 
108 };
109 
115 struct _VisEventQuit {};
116 
123  int is_visible;
124 };
125 
134  // FIXME: Have to use void* as there is a circular dependency
135  // between lv_event.h and lv_param.h
136 
137  void *param;
138 };
139 
148  int event_id;
149  int data_int;
150  void *data_ptr;
151 };
152 
158 struct _VisEvent
159 {
160  VisEventType type;
161 
162  union {
163  VisEventKeyboard keyboard;
164  VisEventMouseMotion mousemotion;
165  VisEventMouseButton mousebutton;
166  VisEventResize resize;
167  VisEventNewSong newsong;
168  VisEventQuit quit;
169  VisEventVisibility visibility;
170  VisEventCustom custom;
171  VisEventParam param;
172  } event;
173 };
174 
175 #ifdef __cplusplus
176 
177 #include <memory>
178 
179 namespace LV {
180 
181  typedef VisEvent Event;
182 
183  class LV_API EventQueue
184  {
185  public:
186 
187  EventQueue ();
188 
189  EventQueue (EventQueue const&) = delete;
190 
191  ~EventQueue ();
192 
193  EventQueue& operator= (EventQueue const&) = delete;
194 
204  bool poll (Event& event);
205 
212  void add (Event const& event);
213 
214  private:
215 
216  class Impl;
217  const std::unique_ptr<Impl> m_impl;
218  };
219 
220 } // LV namespace
221 
222 #endif /* __cplusplus */
223 
224 #ifdef __cplusplus
226 #else
227 typedef struct _VisEventQueue VisEventQueue;
228 struct _VisEventQueue;
229 #endif
230 
231 LV_BEGIN_DECLS
232 
240 LV_API VisEvent *visual_event_new_keyboard (VisKey keysym, VisKeyMod keymod, VisKeyState state);
241 
250 LV_API VisEvent *visual_event_new_mousemotion (int dx, int dy);
251 
262 LV_API VisEvent *visual_event_new_mousebutton (int button, VisMouseState state, int x, int y);
263 
272 LV_API VisEvent *visual_event_new_resize (int width, int height);
273 
281 LV_API VisEvent *visual_event_new_newsong (VisSongInfo *songinfo);
282 
290 LV_API VisEvent *visual_event_new_param (void *param);
291 
297 LV_API VisEvent *visual_event_new_quit (void);
298 
306 LV_API VisEvent *visual_event_new_visibility (int is_visible);
307 
314 LV_API void visual_event_copy (VisEvent *dest, VisEvent *src);
315 
321 LV_API void visual_event_free (VisEvent* event);
322 
332 LV_API VisEvent *visual_event_new_custom (int eid, int param_int, void *param_ptr);
333 
334 LV_API VisEventQueue *visual_event_queue_new (void);
335 LV_API void visual_event_queue_free (VisEventQueue *eventqueue);
336 
337 LV_API void visual_event_queue_add (VisEventQueue *eventqueue, VisEvent *event);
338 LV_API int visual_event_queue_poll (VisEventQueue *eventqueue, VisEvent *event);
339 
340 
341 LV_END_DECLS
342 
347 #endif /* _LV_EVENT_H */