-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
208 lines (172 loc) · 5.38 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "Supernova.h"
using namespace Supernova;
void onUpdate();
void onCharInput(wchar_t);
void onViewLoaded();
void onKeyDown(int key, bool repeat, int mods);
void onKeyUp(int key, bool repeat, int mods);
void onMouseDown(int button, float x, float y, int mods);
void onMouseUp(int button, float x, float y, int mods);
void onMouseMove(float x, float y, int mods);
void onMouseScroll(float xoffset, float yoffset, int mods);
void onMouseEnter();
void onMouseLeave();
void onTouchStart(int pointer, float x, float y);
void onTouchMove(int pointer, float x, float y);
void onTouchEnd(int pointer, float x, float y);
void onTouchCancel();
void onButtonPress();
void onButtonRelease();
void onButtonMouseMove();
Scene scene;
Text text(&scene);
void init(){
text.setPosition(200, 200, 0);
text.setText("Events example: check output");
Engine::setAllowEventsOutCanvas(true);
Engine::setCallMouseInTouchEvent(true);
Engine::setCallTouchInMouseEvent(true);
Engine::onUpdate = onUpdate;
Engine::onCharInput = onCharInput;
Engine::onViewLoaded = onViewLoaded;
Engine::onKeyDown = onKeyDown;
Engine::onKeyUp = onKeyUp;
Engine::onMouseDown = onMouseDown;
Engine::onMouseUp = onMouseUp;
Engine::onKeyDown = onKeyDown;
Engine::onMouseMove = onMouseMove;
Engine::onMouseScroll = onMouseScroll;
Engine::onMouseEnter = onMouseEnter;
Engine::onMouseLeave = onMouseLeave;
Engine::onTouchStart = onTouchStart;
Engine::onTouchMove = onTouchMove;
Engine::onTouchEnd = onTouchEnd;
Engine::onTouchCancel = onTouchCancel;
Engine::setScene(&scene);
}
void onUpdate(){
}
void onButtonPress(){
Log::verbose("Button pressed!!");
}
void onButtonRelease(){
Log::verbose("Button released!!");
}
void onButtonMouseMove(){
Log::verbose("Button mouse move!!");
}
void onViewLoaded(){
Log::verbose("View loaded");
}
void onTouchStart(int pointer, float x, float y){
Log::verbose("Touch start %i - %f %f", pointer, x, y);
}
void onTouchMove(int pointer, float x, float y){
Log::verbose("Touch move %i - %f %f", pointer, x, y);
}
void onTouchEnd(int pointer, float x, float y){
Log::verbose("Touch end %i - %f %f", pointer, x, y);
}
void onTouchCancel(){
Log::verbose("Touch cancel");
}
void onMouseDown(int button, float x, float y, int mods){
std::string modifier = "";
if (mods & S_MODIFIER_SHIFT)
modifier += "shift;";
if (mods & S_MODIFIER_CONTROL)
modifier += "control;";
if (mods & S_MODIFIER_ALT)
modifier += "alt;";
if (mods & S_MODIFIER_SUPER)
modifier += "super;";
if (mods & S_MODIFIER_CAPS_LOCK)
modifier += "caps;";
if (mods & S_MODIFIER_NUM_LOCK)
modifier += "num;";
std::string bt = "";
if (button == S_MOUSE_BUTTON_LEFT)
bt = "left";
if (button == S_MOUSE_BUTTON_RIGHT)
bt = "right";
if (button == S_MOUSE_BUTTON_MIDDLE)
bt = "middle";
Log::verbose("Mouse down - %s - %s", bt.c_str(), modifier.c_str());
}
void onMouseUp(int button, float x, float y, int mods){
std::string modifier = "";
if (mods & S_MODIFIER_SHIFT)
modifier += "shift;";
if (mods & S_MODIFIER_CONTROL)
modifier += "control;";
if (mods & S_MODIFIER_ALT)
modifier += "alt;";
if (mods & S_MODIFIER_SUPER)
modifier += "super;";
if (mods & S_MODIFIER_CAPS_LOCK)
modifier += "caps;";
if (mods & S_MODIFIER_NUM_LOCK)
modifier += "num;";
std::string bt = "";
if (button == S_MOUSE_BUTTON_LEFT)
bt = "left";
if (button == S_MOUSE_BUTTON_RIGHT)
bt = "right";
if (button == S_MOUSE_BUTTON_MIDDLE)
bt = "middle";
Log::verbose("Mouse up - %s - %s", bt.c_str(), modifier.c_str());
}
void onMouseMove(float x, float y, int mods){
Log::verbose("Mouse %f %f", x, y);
}
void onMouseScroll(float xoffset, float yoffset, int mods){
if (xoffset != 0 || yoffset != 0)
Log::verbose("Mouse scroll %f %f", xoffset, yoffset);
}
void onMouseEnter(){
Log::verbose("Mouse enter");
}
void onMouseLeave(){
Log::verbose("Mouse leave");
}
void onCharInput(wchar_t codepoint){
Log::verbose("%s",StringUtils::toUTF8(codepoint).c_str());
}
void onKeyDown(int key, bool repeat, int mods){
std::string modifier = "";
if (mods & S_MODIFIER_SHIFT)
modifier += "shift;";
if (mods & S_MODIFIER_CONTROL)
modifier += "control;";
if (mods & S_MODIFIER_ALT)
modifier += "alt;";
if (mods & S_MODIFIER_SUPER)
modifier += "super;";
if (mods & S_MODIFIER_CAPS_LOCK)
modifier += "caps;";
if (mods & S_MODIFIER_NUM_LOCK)
modifier += "num;";
std::string rstr;
if (repeat)
rstr = "repeated";
Log::verbose("KeyDown: %i - %s - %s",key, modifier.c_str(), rstr.c_str());
}
void onKeyUp(int key, bool repeat, int mods){
std::string modifier = "";
if (mods & S_MODIFIER_SHIFT)
modifier += "shift;";
if (mods & S_MODIFIER_CONTROL)
modifier += "control;";
if (mods & S_MODIFIER_ALT)
modifier += "alt;";
if (mods & S_MODIFIER_SUPER)
modifier += "super;";
if (mods & S_MODIFIER_CAPS_LOCK)
modifier += "caps;";
if (mods & S_MODIFIER_NUM_LOCK)
modifier += "num;";
std::string rstr;
if (repeat)
rstr = "repeated";
Log::verbose("KeyUp: %i - %s - %s",key, modifier.c_str(), rstr.c_str());
}