8 extern SDL_Event sdl_event;
10 static int pointer_x, pointer_y;
22 void set_mouse_bounds(const Rect &rect)
31 void process_mouse_event()
34 MouseMotionFuncType motion_callback = 0;
35 MouseButtonFuncType button_callback = 0;
38 if(!(top = wm->get_grab_window())) {
39 top = wm->get_window_at_pos(pointer_x, pointer_y);
41 wm->set_focused_window(top);
44 wm->set_focused_window(0);
48 switch(sdl_event.type) {
50 pointer_x = sdl_event.motion.x;
51 pointer_y = sdl_event.motion.y;
52 if(top && (motion_callback = top->get_mouse_motion_callback())) {
53 Rect rect = top->get_absolute_rect();
54 motion_callback(top, pointer_x - rect.x, pointer_y - rect.y);
58 case SDL_MOUSEBUTTONUP:
59 case SDL_MOUSEBUTTONDOWN:
60 bn = sdl_event.button.button - SDL_BUTTON_LEFT;
61 if(sdl_event.button.state == SDL_PRESSED) {
65 bnstate &= ~(1 << bn);
67 if(top && (button_callback = top->get_mouse_button_callback())) {
68 Rect rect = top->get_absolute_rect();
69 button_callback(top, bn, sdl_event.button.state, pointer_x - rect.x, pointer_y - rect.y);
74 void get_pointer_pos(int *x, int *y)
80 int get_button_state()
85 int get_button(int bn)
87 if(bn < 0 || bn >= 3) {
90 return (bnstate & (1 << bn)) != 0;