/
legacywidget.cpp
282 lines (235 loc) · 7.47 KB
/
legacywidget.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/** @file legacywidget.cpp
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#include "de_platform.h"
#include "ui/widgets/legacywidget.h"
#include "ui/dd_input.h"
#include "ui/ui_main.h"
#include "ui/ui2_main.h"
#include "ui/sys_input.h"
#include "ui/busyvisual.h"
#include "ui/windowsystem.h"
#include "ui/widgets/taskbarwidget.h"
#include "dd_def.h"
#include "dd_main.h"
#include "dd_loop.h"
#include "sys_system.h"
#include "edit_bias.h"
#include "world/map.h"
#include "network/net_main.h"
#include "render/r_main.h"
#include "render/rend_list.h"
//#include "render/rend_console.h"
#include "audio/s_main.h"
#include "gl/gl_main.h"
#include "gl/sys_opengl.h"
#include "gl/gl_defer.h"
#include <de/GLState>
/**
* Maximum number of milliseconds spent uploading textures at the beginning
* of a frame. Note that non-uploaded textures will appear as pure white
* until their content gets uploaded (you should precache them).
*/
#define FRAME_DEFERRED_UPLOAD_TIMEOUT 20
boolean drawGame = true; // If false the game viewport won't be rendered
using namespace de;
DENG2_PIMPL(LegacyWidget)
{
Instance(Public *i) : Base(i)
{}
void draw()
{
bool cannotDraw = (self.isDisabled() || !GL_IsFullyInited());
if(renderWireframe || cannotDraw)
{
// When rendering is wireframe mode, we must clear the screen
// before rendering a frame.
glClear(GL_COLOR_BUFFER_BIT);
}
if(cannotDraw) return;
if(drawGame)
{
if(App_GameLoaded())
{
// Interpolate the world ready for drawing view(s) of it.
if(App_World().hasMap())
{
R_BeginWorldFrame();
}
R_RenderViewPorts();
}
else if(titleFinale == 0)
{
// Title finale is not playing. Lets do it manually.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1, 1);
R_RenderBlankView();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
if(!(UI_IsActive() && UI_Alpha() >= 1.0))
{
UI2_Drawer();
// Draw any full window game graphics.
if(App_GameLoaded() && gx.DrawWindow)
{
Size2Raw dimensions(DENG_WINDOW->width(), DENG_WINDOW->height());
gx.DrawWindow(&dimensions);
}
}
}
if(Con_TransitionInProgress())
Con_DrawTransition();
if(drawGame)
{
// Shadow Bias Editor HUD (if it is active).
SBE_DrawHUD();
/*
* Draw debug information.
*/
if(App_World().hasMap() && App_World().map().hasLightGrid())
{
App_World().map().lightGrid().drawDebugVisual();
}
Net_Drawer();
S_Drawer();
// Finish up any tasks that must be completed after view(s) have been drawn.
R_EndWorldFrame();
}
if(UI_IsActive())
{
// Draw user interface.
UI_Drawer();
}
// Draw console.
//Rend_Console();
// End any open DGL sequence.
DGL_End();
}
};
LegacyWidget::LegacyWidget(String const &name)
: GuiWidget(name), d(new Instance(this))
{}
void LegacyWidget::viewResized()
{
if(BusyMode_Active() || isDisabled() || Sys_IsShuttingDown()) return;
LOG_AS("LegacyWidget");
LOG_TRACE("View resized to ") << root().viewSize().asText();
// Update viewports.
R_SetViewGrid(0, 0);
if(/*BusyMode_Active() ||*/ UI_IsActive() || !App_GameLoaded())
{
// Update for busy mode.
R_UseViewPort(0);
}
R_LoadSystemFonts();
if(UI_IsActive())
{
UI_UpdatePageLayout();
}
}
void LegacyWidget::update()
{
GuiWidget::update();
if(isDisabled()) return;
//LOG_DEBUG("Legacy update");
DENG2_ASSERT(!BusyMode_Active());
// We may be performing GL operations.
ClientWindow::main().glActivate();
// Run at least one (fractional) tic.
Loop_RunTics();
// We may have received a Quit message from the windowing system
// during events/tics processing.
if(Sys_IsShuttingDown())
return;
GL_ProcessDeferredTasks(FRAME_DEFERRED_UPLOAD_TIMEOUT);
// Request update of window contents.
root().window().draw();
// After the first frame, start timedemo.
//DD_CheckTimeDemo();
}
void LegacyWidget::drawContent()
{
if(isDisabled() || !GL_IsFullyInited())
return;
#if 0
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
GL_Init2DState();
#endif
d->draw();
#if 0
glPopClientAttrib();
glPopAttrib();
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
#endif
}
bool LegacyWidget::handleEvent(Event const &event)
{
/**
* @todo Event processing should occur here, not during Loop_RunTics().
* However, care must be taken to reproduce the vanilla behavior of
* controls with regard to response times.
*
* @todo Input drivers need to support Unicode text; for now we have to
* submit as Latin1.
*/
// Clicking on the game view will trap the mouse automatically.
Canvas &canvas = root().window().canvas();
if(!canvas.isMouseTrapped() && event.type() == Event::MouseButton &&
App_GameLoaded())
{
MouseEvent const &mouse = event.as<MouseEvent>();
if(mouse.state() == MouseEvent::Released && hitTest(mouse.pos()))
{
if(root().focus())
{
// First click will remove UI focus, allowing LegacyWidget
// to receive events.
root().setFocus(0);
return true;
}
canvas.trapMouse();
root().window().taskBar().close();
return true;
}
}
if(event.type() == Event::KeyPress ||
event.type() == Event::KeyRepeat ||
event.type() == Event::KeyRelease)
{
KeyEvent const &ev = event.as<KeyEvent>();
Keyboard_Submit(ev.state() == KeyEvent::Pressed? IKE_DOWN :
ev.state() == KeyEvent::Repeat? IKE_REPEAT :
IKE_UP,
ev.ddKey(), ev.nativeCode(), ev.text().toLatin1());
}
return false;
}