10 struct imtk_state st = {
11 1, 1, /* scr_width/scr_height */
12 0, 0, 0, 0, 0, /* mousex/mousey, prevx, prevy, mouse_bnmask */
13 -1, -1, -1, -1 /* active, hot, input, prev_active */
16 static struct key_node *key_list, *key_tail;
20 void imtk_inp_key(int key, int state)
22 if(state == IMTK_DOWN) {
23 struct key_node *node;
25 if(!(node = malloc(sizeof *node))) {
32 key_tail->next = node;
35 key_list = key_tail = node;
39 imtk_post_redisplay();
42 void imtk_inp_mouse(int bn, int state)
44 if(state == IMTK_DOWN) {
45 st.mouse_bnmask |= 1 << bn;
47 st.mouse_bnmask &= ~(1 << bn);
49 imtk_post_redisplay();
52 void imtk_inp_motion(int x, int y)
57 imtk_post_redisplay();
60 void imtk_set_viewport(int x, int y)
66 void imtk_get_viewport(int *width, int *height)
68 if(width) *width = st.scr_width;
69 if(height) *height = st.scr_height;
73 void imtk_set_active(int id)
75 if(id == -1 || st.hot == id) {
76 st.prev_active = st.active;
81 int imtk_is_active(int id)
83 return st.active == id;
86 int imtk_set_hot(int id)
95 int imtk_is_hot(int id)
100 void imtk_set_focus(int id)
105 int imtk_has_focus(int id)
107 return st.input == id;
110 int imtk_hit_test(int x, int y, int w, int h)
112 return st.mousex >= x && st.mousex < (x + w) &&
113 st.mousey >= y && st.mousey < (y + h);
116 void imtk_get_mouse(int *xptr, int *yptr)
118 if(xptr) *xptr = st.mousex;
119 if(yptr) *yptr = st.mousey;
122 void imtk_set_prev_mouse(int x, int y)
128 void imtk_get_prev_mouse(int *xptr, int *yptr)
130 if(xptr) *xptr = st.prevx;
131 if(yptr) *yptr = st.prevy;
134 int imtk_button_state(int bn)
136 return st.mouse_bnmask & (1 << bn);
140 int imtk_get_key(void)
143 struct key_node *node = key_list;
147 key_list = node->next;