1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3  *            event.h
4  *
5  *  Sun Oct  9 16:11:47 CEST 2011
6  *  Copyright 2011 Bent Bisballe Nyeng
7  *  deva@aasimon.org
8  ****************************************************************************/
9 
10 /*
11  *  This file is part of DrumGizmo.
12  *
13  *  DrumGizmo is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU Lesser General Public License as published by
15  *  the Free Software Foundation; either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  DrumGizmo is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU Lesser General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Lesser General Public License
24  *  along with DrumGizmo; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <list>
31 #include <memory>
32 
33 namespace GUI
34 {
35 
36 enum class EventType
37 {
38 	mouseMove,
39 	repaint,
40 	button,
41 	scroll,
42 	key,
43 	close,
44 	resize,
45 	move,
46 	mouseEnter,
47 	mouseLeave,
48 };
49 
50 class Event
51 {
52 public:
~Event()53 	virtual ~Event() {}
54 
55 	virtual EventType type() = 0;
56 };
57 
58 class MouseMoveEvent
59 	: public Event
60 {
61 public:
type()62 	EventType type() { return EventType::mouseMove; }
63 
64 	int x;
65 	int y;
66 };
67 
68 
69 enum class Direction
70 {
71 	up,
72 	down,
73 };
74 
75 enum class MouseButton
76 {
77 	right,
78 	middle,
79 	left,
80 };
81 
82 class ButtonEvent
83 	: public Event
84 {
85 public:
type()86 	EventType type() { return EventType::button; }
87 
88 	int x;
89 	int y;
90 
91 	Direction direction;
92 	MouseButton button;
93 
94 	bool doubleClick;
95 };
96 
97 class ScrollEvent
98 	: public Event
99 {
100 public:
type()101 	EventType type() { return EventType::scroll; }
102 
103 	int x;
104 	int y;
105 
106 	float delta;
107 };
108 
109 class RepaintEvent
110 	: public Event
111 {
112 public:
type()113 	EventType type() { return EventType::repaint; }
114 
115 	int x;
116 	int y;
117 	size_t width;
118 	size_t height;
119 };
120 
121 enum class Key
122 {
123 	unknown,
124 	left,
125 	right,
126 	up,
127 	down,
128 	deleteKey,
129 	backspace,
130 	home,
131 	end,
132 	pageDown,
133 	pageUp,
134 	enter,
135 	character, //!< The actual character is stored in KeyEvent::text
136 };
137 
138 class KeyEvent
139 	: public Event
140 {
141 public:
type()142 	EventType type() { return EventType::key; }
143 
144 	Direction direction;
145 
146 	Key keycode;
147 	std::string text;
148 };
149 
150 class CloseEvent
151 	: public Event
152 {
153 public:
type()154 	EventType type() { return EventType::close; }
155 };
156 
157 class ResizeEvent
158 	: public Event
159 {
160 public:
type()161 	EventType type() { return EventType::resize; }
162 
163 	size_t width;
164 	size_t height;
165 };
166 
167 class MoveEvent
168 	: public Event
169 {
170 public:
type()171 	EventType type() { return EventType::move; }
172 
173 	int x;
174 	int y;
175 };
176 
177 class MouseEnterEvent
178 	: public Event
179 {
180 public:
type()181 	EventType type() { return EventType::mouseEnter; }
182 
183 	int x;
184 	int y;
185 };
186 
187 class MouseLeaveEvent
188 	: public Event
189 {
190 public:
type()191 	EventType type() { return EventType::mouseLeave; }
192 
193 	int x;
194 	int y;
195 };
196 
197 using EventQueue = std::list<std::shared_ptr<Event>>;
198 
199 struct Rect
200 {
201 	std::size_t x1;
202 	std::size_t y1;
203 	std::size_t x2;
204 	std::size_t y2;
205 
emptyRect206 	bool empty() const
207 	{
208 		return x1 == x2 && y1 == y2;
209 	}
210 };
211 
212 } // GUI::
213