sgl
view src/cb.c @ 15:a16b34ac3f2a
bah
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 17 May 2011 11:21:09 +0300 |
parents | 0570e27e5ebc |
children |
line source
1 #include <stdlib.h>
2 #include <string.h>
3 #include "sgl.h"
4 #include "wsys.h"
6 struct cbnode {
7 void (*func[SGL_NUM_CALLBACKS])();
8 struct cbnode *next;
9 };
11 static void notify_wsys(void);
13 struct cbnode first_cbnode;
14 struct cbnode *cb = &first_cbnode;
16 int sgl_push_callbacks(void)
17 {
18 struct cbnode *node;
20 if(!(node = malloc(sizeof *node))) {
21 return -1;
22 }
23 node->next = cb;
24 cb = node;
25 sgl_clear_callbacks();
26 return 0;
27 }
29 int sgl_pop_callbacks(void)
30 {
31 struct cbnode *node;
33 if(!cb->next) {
34 return -1;
35 }
37 node = cb;
38 cb = cb->next;
39 free(node);
41 notify_wsys();
42 return 0;
43 }
45 void sgl_clear_callbacks(void)
46 {
47 memset(cb->func, 0, sizeof cb->func);
48 notify_wsys();
49 }
51 void sgl_set_callback(int idx, void (*func)())
52 {
53 struct wsys_module *ws;
55 cb->func[idx] = func;
57 if((ws = sgl_wsys_module())) {
58 ws->set_event(idx, func != 0);
59 }
60 }
62 void (*sgl_get_callback(int idx))()
63 {
64 return cb->func[idx];
65 }
68 void sgl_create_callback(sgl_create_callback_t func)
69 {
70 sgl_set_callback(SGL_CREATE, func);
71 }
73 void sgl_close_callback(sgl_close_callback_t func)
74 {
75 sgl_set_callback(SGL_CLOSE, func);
76 }
78 void sgl_display_callback(sgl_display_callback_t func)
79 {
80 sgl_set_callback(SGL_DISPLAY, func);
81 }
83 void sgl_reshape_callback(sgl_reshape_callback_t func)
84 {
85 sgl_set_callback(SGL_RESHAPE, func);
86 }
88 void sgl_keyboard_callback(sgl_keyboard_callback_t func)
89 {
90 sgl_set_callback(SGL_KEYBOARD, func);
91 }
93 void sgl_mouse_callback(sgl_mouse_callback_t func)
94 {
95 sgl_set_callback(SGL_MOUSE, func);
96 }
98 void sgl_motion_callback(sgl_motion_callback_t func)
99 {
100 sgl_set_callback(SGL_MOTION, func);
101 }
103 void sgl_passive_callback(sgl_passive_callback_t func)
104 {
105 sgl_set_callback(SGL_PASSIVE, func);
106 }
108 void sgl_idle_callback(sgl_idle_callback_t func)
109 {
110 sgl_set_callback(SGL_IDLE, func);
111 }
114 /* notify the window system module as to which events are active */
115 static void notify_wsys(void)
116 {
117 int i;
118 struct wsys_module *ws;
120 if((ws = sgl_wsys_module())) {
121 for(i=0; i<SGL_NUM_CALLBACKS; i++) {
122 ws->set_event(i, cb->func[i] != 0);
123 }
124 }
125 }