1 // Copyright (C) 2007 Ole Laursen
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #ifndef GUI_INPUT_HELPERS_H
19 #define GUI_INPUT_HELPERS_H
21 #include "input-events.h"
23 inline MouseButtonEvent to_input_event(GdkEventButton *e)
26 m.pos = make_vector(int(e->x), int(e->y));
29 m.button = MouseButtonEvent::LEFT_BUTTON;
30 else if (e->button == 3)
31 m.button = MouseButtonEvent::RIGHT_BUTTON;
32 else if (e->button == 4)
33 m.button = MouseButtonEvent::WHEEL_UP;
34 else if (e->button == 5)
35 m.button = MouseButtonEvent::WHEEL_DOWN;
37 m.button = MouseButtonEvent::MIDDLE_BUTTON;
39 if (e->type == GDK_BUTTON_PRESS)
40 m.state = MouseButtonEvent::PRESSED;
41 else if (e->type == GDK_BUTTON_RELEASE)
42 m.state = MouseButtonEvent::RELEASED;
47 inline MouseMotionEvent to_input_event(GdkEventMotion *e)
50 m.pos = make_vector(int(e->x), int(e->y));
52 m.pressed[MouseMotionEvent::LEFT_BUTTON] = e->state & GDK_BUTTON1_MASK;
53 m.pressed[MouseMotionEvent::MIDDLE_BUTTON] = e->state & GDK_BUTTON2_MASK;
54 m.pressed[MouseMotionEvent::RIGHT_BUTTON] = e->state & GDK_BUTTON3_MASK;