sgl

annotate src/cb.c @ 19:12ce0cef7ebf

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