1 // Copyright (C) 2007 Ole Laursen
2 //
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.
7 //
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.
12 //
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
16 // 02110-1301, USA.
17
18 #pragma once
19 #ifndef GUI_INPUT_HELPERS_H
20 #define GUI_INPUT_HELPERS_H
21
22 #include "input-events.h"
23
to_input_event(GdkEventButton * e)24 inline MouseButtonEvent to_input_event(GdkEventButton *e)
25 {
26 MouseButtonEvent m;
27 m.pos = make_vector(int(e->x), int(e->y));
28
29 if (e->button == 1)
30 m.button = MouseButtonEvent::LEFT_BUTTON;
31 else if (e->button == 3)
32 m.button = MouseButtonEvent::RIGHT_BUTTON;
33 else if (e->button == 4)
34 m.button = MouseButtonEvent::WHEEL_UP;
35 else if (e->button == 5)
36 m.button = MouseButtonEvent::WHEEL_DOWN;
37 else
38 m.button = MouseButtonEvent::MIDDLE_BUTTON;
39
40 if (e->type == GDK_BUTTON_PRESS)
41 m.state = MouseButtonEvent::PRESSED;
42 else if (e->type == GDK_BUTTON_RELEASE)
43 m.state = MouseButtonEvent::RELEASED;
44
45 return m;
46 }
47
to_input_event(GdkEventMotion * e)48 inline MouseMotionEvent to_input_event(GdkEventMotion *e)
49 {
50 MouseMotionEvent m;
51 m.pos = make_vector(int(e->x), int(e->y));
52
53 m.pressed[MouseMotionEvent::LEFT_BUTTON] = e->state & GDK_BUTTON1_MASK;
54 m.pressed[MouseMotionEvent::MIDDLE_BUTTON] = e->state & GDK_BUTTON2_MASK;
55 m.pressed[MouseMotionEvent::RIGHT_BUTTON] = e->state & GDK_BUTTON3_MASK;
56
57 return m;
58 }
59
60 #endif
61