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;
37 Window *top = wm->get_window_at_pos(pointer_x, pointer_y);
40 wm->set_focused_window(top);
43 wm->set_focused_window(0);
46 switch(sdl_event.type) {
48 pointer_x = sdl_event.motion.x;
49 pointer_y = sdl_event.motion.y;
50 if(top && (motion_callback = top->get_mouse_motion_callback())) {
51 Rect rect = top->get_absolute_rect();
52 motion_callback(top, pointer_x - rect.x, pointer_y - rect.y);
56 case SDL_MOUSEBUTTONUP:
57 case SDL_MOUSEBUTTONDOWN:
58 bn = sdl_event.button.button - SDL_BUTTON_LEFT;
59 if(sdl_event.button.state == SDL_PRESSED) {
63 bnstate &= ~(1 << bn);
65 if(top && (button_callback = top->get_mouse_button_callback())) {
66 Rect rect = top->get_absolute_rect();
67 button_callback(top, bn, sdl_event.button.state, pointer_x - rect.x, pointer_y - rect.y);
72 void get_pointer_pos(int *x, int *y)
78 int get_button_state()
83 int get_button(int bn)
85 if(bn < 0 || bn >= 3) {
88 return (bnstate & (1 << bn)) != 0;