libvisual  0.5.0
lv_event_c.cpp
1 #include "config.h"
2 #include "lv_event.h"
3 #include "lv_common.h"
4 
5 extern "C" {
6 
7 VisEventQueue* visual_event_queue_new ()
8 {
9  return new LV::EventQueue;
10 }
11 
12 void visual_event_queue_free (VisEventQueue *self)
13 {
14  delete self;
15 }
16 
17 void visual_event_queue_add (VisEventQueue *self, VisEvent *event)
18 {
19  visual_return_if_fail (self != nullptr);
20 
21  self->add (*event);
22  visual_event_free (event);
23 }
24 
25 int visual_event_queue_poll (VisEventQueue *self, VisEvent *event)
26 {
27  visual_return_val_if_fail (self != nullptr, FALSE);
28  visual_return_val_if_fail (self != nullptr, FALSE);
29 
30  return self->poll (*event);
31 }
32 
33 VisEvent* visual_event_new_keyboard (VisKey keysym, VisKeyMod keymod, VisKeyState state)
34 {
35  auto event = new LV::Event;
36 
37  if (state == VISUAL_KEY_DOWN)
38  event->type = VISUAL_EVENT_KEYDOWN;
39  else
40  event->type = VISUAL_EVENT_KEYUP;
41 
42  event->event.keyboard.keysym.sym = keysym;
43  event->event.keyboard.keysym.mod = keymod;
44 
45  return event;
46 }
47 
48 VisEvent* visual_event_new_mousemotion (int dx, int dy)
49 {
50  auto event = new LV::Event;
51 
52  event->type = VISUAL_EVENT_MOUSEMOTION;
53 
54  //event->event.mousemotion.state = eventqueue->mousestate;
55  event->event.mousemotion.x = dx;
56  event->event.mousemotion.y = dy;
57 
58  return event;
59 }
60 
61 VisEvent* visual_event_new_mousebutton (int button, VisMouseState state, int x, int y)
62 {
63  auto event = new LV::Event;
64 
65  if (state == VISUAL_MOUSE_DOWN)
66  event->type = VISUAL_EVENT_MOUSEBUTTONDOWN;
67  else
68  event->type = VISUAL_EVENT_MOUSEBUTTONUP;
69 
70  event->event.mousebutton.button = button;
71  event->event.mousebutton.state = state;
72 
73  event->event.mousebutton.x = x;
74  event->event.mousebutton.y = y;
75 
76  return event;
77 }
78 
79 VisEvent* visual_event_new_resize (int width, int height)
80 {
81  auto event = new LV::Event;
82 
83  event->type = VISUAL_EVENT_RESIZE;
84 
85  event->event.resize.width = width;
86  event->event.resize.height = height;
87 
88  return event;
89 }
90 
92 {
93  auto event = new LV::Event;
94 
95  event->type = VISUAL_EVENT_NEWSONG;
96 
97  /* FIXME refcounting */
98  event->event.newsong.songinfo = songinfo;
99 
100  return event;
101 }
102 
103 VisEvent* visual_event_new_param (void *param)
104 {
105  auto event = new LV::Event;
106 
107  event->type = VISUAL_EVENT_PARAM;
108 
109  /* FIXME ref count the param */
110  event->event.param.param = param;
111 
112  return event;
113 }
114 
116 {
117  auto event = new LV::Event;
118 
119  event->type = VISUAL_EVENT_QUIT;
120 
121  return event;
122 }
123 
124 VisEvent* visual_event_new_visibility (int is_visible)
125 {
126  auto event = new LV::Event;
127 
128  event->type = VISUAL_EVENT_VISIBILITY;
129  event->event.visibility.is_visible = is_visible;
130 
131  return event;
132 }
133 
134 VisEvent* visual_event_new_custom (int eid, int param_int, void *param_ptr)
135 {
136  auto event = new LV::Event;
137 
138  event->type = VISUAL_EVENT_CUSTOM;
139 
140  event->event.custom.event_id = eid;
141  event->event.custom.data_int = param_int;
142  event->event.custom.data_ptr = param_ptr;
143 
144  return event;
145 }
146 
147 void visual_event_copy (VisEvent *dest, VisEvent *src)
148 {
149  visual_return_if_fail (dest != nullptr);
150  visual_return_if_fail (src != nullptr);
151 
152  *dest = *src;
153 }
154 
155 void visual_event_free (VisEvent *event)
156 {
157  delete event;
158 }
159 
160 } // extern C
161