-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameworkWindow.cpp
226 lines (188 loc) · 4.74 KB
/
FrameworkWindow.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include "framework.h"
#include "FrameworkWindow.h"
FrameworkWindow::~FrameworkWindow()
{
}
void FrameworkWindow::createDefaultWindow(int width, int height, const char * title)
{
framework.windowTitle = title;
framework.windowIsResizable = true;
framework.enableDepthBuffer = true;
framework.msaaLevel = 4;
framework.enableRealTimeEditing = true;
framework.init(width, height);
framework.getCurrentViewportSize(m_windowSx, m_windowSy);
}
void FrameworkWindow::createWindow(const b3gWindowConstructionInfo & ci)
{
createDefaultWindow(ci.m_width, ci.m_height, ci.m_title);
}
void FrameworkWindow::closeWindow()
{
framework.shutdown();
}
void FrameworkWindow::runMainLoop()
{
framework.process();
if (m_mouseMoveCallback != nullptr)
{
if (mouse.dx || mouse.dy)
{
m_mouseMoveCallback(mouse.x, mouse.y);
}
}
if (m_mouseButtonCallback != nullptr)
{
if (mouse.wentDown(BUTTON_LEFT))
m_mouseButtonCallback(0, 1, mouse.x, mouse.y);
if (mouse.wentUp(BUTTON_LEFT))
m_mouseButtonCallback(0, 0, mouse.x, mouse.y);
}
if (m_wheelCallback != nullptr)
{
if (mouse.scrollY != 0)
m_wheelCallback(0, mouse.scrollY);
}
if (m_keyboardCallback != nullptr)
{
#if FRAMEWORK_USE_SDL
for (auto & e : framework.events)
{
if (e.type == SDL_KEYDOWN)
m_keyboardCallback(e.key.keysym.sym, 1);
else if (e.type == SDL_KEYUP)
m_keyboardCallback(e.key.keysym.sym, 0);
}
#endif
}
int viewSx;
int viewSy;
framework.getCurrentViewportSize(viewSx, viewSy);
if (viewSx != m_windowSx || viewSy != m_windowSy)
{
m_windowSx = viewSx;
m_windowSy = viewSy;
if (m_resizeCallback != nullptr)
m_resizeCallback(viewSx, viewSy);
}
}
float FrameworkWindow::getTimeInSeconds()
{
return framework.time;
}
bool FrameworkWindow::requestedExit() const
{
return framework.quitRequested;
}
void FrameworkWindow::setRequestExit()
{
framework.quitRequested = true;
}
void FrameworkWindow::startRendering()
{
framework.beginDraw(
m_backgroundColor[0] * 255.f,
m_backgroundColor[1] * 255.f,
m_backgroundColor[2] * 255.f,
255);
projectPerspective3d(90.f, .1f, 1000.f);
pushDepthTest(true, DEPTH_LESS);
}
void FrameworkWindow::endRendering()
{
popDepthTest();
framework.endDraw();
}
bool FrameworkWindow::isModifierKeyPressed(int key)
{
if (key == B3G_ALT)
return keyboard.isDown(SDLK_LALT) || keyboard.isDown(SDLK_RALT);
else if (key == B3G_CONTROL)
return keyboard.isDown(SDLK_LCTRL) || keyboard.isDown(SDLK_RCTRL);
else if (key == B3G_SHIFT)
return keyboard.isDown(SDLK_LSHIFT) || keyboard.isDown(SDLK_RSHIFT);
return false;
}
void FrameworkWindow::setMouseMoveCallback(b3MouseMoveCallback mouseCallback)
{
m_mouseMoveCallback = mouseCallback;
}
b3MouseMoveCallback FrameworkWindow::getMouseMoveCallback()
{
return m_mouseMoveCallback;
}
void FrameworkWindow::setMouseButtonCallback(b3MouseButtonCallback mouseCallback)
{
m_mouseButtonCallback = mouseCallback;
}
b3MouseButtonCallback FrameworkWindow::getMouseButtonCallback()
{
return m_mouseButtonCallback;
}
void FrameworkWindow::setResizeCallback(b3ResizeCallback resizeCallback)
{
m_resizeCallback = resizeCallback;
if (m_resizeCallback != nullptr)
{
m_resizeCallback(getWidth(), getHeight());
}
}
b3ResizeCallback FrameworkWindow::getResizeCallback()
{
return m_resizeCallback;
}
void FrameworkWindow::setWheelCallback(b3WheelCallback wheelCallback)
{
m_wheelCallback = wheelCallback;
}
b3WheelCallback FrameworkWindow::getWheelCallback()
{
return m_wheelCallback;
}
void FrameworkWindow::setKeyboardCallback(b3KeyboardCallback keyboardCallback)
{
m_keyboardCallback = keyboardCallback;
}
b3KeyboardCallback FrameworkWindow::getKeyboardCallback()
{
return m_keyboardCallback;
}
void FrameworkWindow::setRenderCallback(b3RenderCallback renderCallback)
{
m_renderCallback = renderCallback;
}
void FrameworkWindow::setWindowTitle(const char* title)
{
framework.getCurrentWindow().setTitle(title);
}
float FrameworkWindow::getRetinaScale() const
{
return framework.getCurrentBackingScale();
}
void FrameworkWindow::setAllowRetina(bool allow)
{
framework.allowHighDpi = allow;
}
int FrameworkWindow::getWidth() const
{
int sx, sy;
framework.getCurrentViewportSize(sx, sy);
return sx;
}
int FrameworkWindow::getHeight() const
{
int sx, sy;
framework.getCurrentViewportSize(sx, sy);
return sy;
}
int FrameworkWindow::fileOpenDialog(char * fileName, int maxFileNameLength)
{
Assert(false);
return 0;
}
void FrameworkWindow::setBackgroundColor(float rgb[3])
{
m_backgroundColor[0] = rgb[0];
m_backgroundColor[1] = rgb[1];
m_backgroundColor[2] = rgb[2];
}