/
window.cpp
1276 lines (1075 loc) · 32.8 KB
/
window.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file window.cpp
* Qt-based window management implementation. @ingroup base
*
* @authors Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2012 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2008 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* @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, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include <QWidget>
#include <QApplication>
#include <QDesktopWidget>
#include <QSettings>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef UNIX
# include "m_args.h"
# include <SDL.h>
#endif
#ifdef MACOSX
# include "displaymode_macx.h"
#endif
#include "window.h"
#include "canvaswindow.h"
#include "displaymode.h"
#include "de_platform.h"
#include "sys_system.h"
#include "dd_main.h"
#include "con_main.h"
#include "con_busy.h"
#include "gl_main.h"
#include "ui_main.h"
#include <QDebug>
/// Used to determine the valid region for windows on the desktop.
/// A window should never go fully (or nearly fully) outside the desktop.
static const int DESKTOP_EDGE_GRACE = 30; // pixels
static QRect desktopRect()
{
/// @todo Multimonitor? This checks the default screen.
return QApplication::desktop()->screenGeometry();
}
static QRect desktopValidRect()
{
return desktopRect().adjusted(DESKTOP_EDGE_GRACE, DESKTOP_EDGE_GRACE,
-DESKTOP_EDGE_GRACE, -DESKTOP_EDGE_GRACE);
}
struct ddwindow_s
{
CanvasWindow* widget; ///< The widget this window represents.
void (*drawFunc)(void); ///< Draws the contents of the canvas.
QRect appliedGeometry; ///< Saved for detecting when changes have occurred.
ddwindowtype_t type;
boolean inited;
RectRaw geometry; ///< Current actual geometry.
int colorDepthBits;
int flags;
consolewindow_t console; ///< Only used for WT_CONSOLE windows.
#if defined(WIN32)
HWND hWnd; ///< Needed for input (among other things).
HGLRC glContext;
#endif
void __inline assertWindow() const
{
assert(this);
assert(widget);
}
int x() const
{
return geometry.origin.x;
}
int y() const
{
return geometry.origin.y;
}
int width() const
{
return geometry.size.width;
}
int height() const
{
return geometry.size.height;
}
QRect rect() const {
return QRect(x(), y(), width(), height());
}
/**
* Checks all command line options that affect window geometry and applies
* them to this Window.
*/
void modifyAccordingToOptions()
{
if(ArgCheckWith("-width", 1))
{
geometry.size.width = qMax(WINDOW_MIN_WIDTH, atoi(ArgNext()));
}
if(ArgCheckWith("-height", 1))
{
geometry.size.height = qMax(WINDOW_MIN_HEIGHT, atoi(ArgNext()));
}
if(ArgCheckWith("-winsize", 2))
{
geometry.size.width = qMax(WINDOW_MIN_WIDTH, atoi(ArgNext()));
geometry.size.height = qMax(WINDOW_MIN_HEIGHT, atoi(ArgNext()));
}
if(ArgCheckWith("-colordepth", 1) || ArgCheckWith("-bpp", 1))
{
colorDepthBits = qBound(8, atoi(ArgNext()), 32);
}
if(ArgCheck("-nocenter"))
{
setFlag(DDWF_CENTER, false);
}
if(ArgCheckWith("-xpos", 1))
{
geometry.origin.x = atoi(ArgNext());
setFlag(DDWF_CENTER | DDWF_MAXIMIZE, false);
}
if(ArgCheckWith("-ypos", 1))
{
geometry.origin.y = atoi(ArgNext());
setFlag(DDWF_CENTER | DDWF_MAXIMIZE, false);
}
if(ArgCheck("-center"))
{
setFlag(DDWF_CENTER);
}
if(ArgCheck("-maximize"))
{
setFlag(DDWF_MAXIMIZE);
}
if(ArgCheck("-nomaximize"))
{
setFlag(DDWF_MAXIMIZE, false);
}
if(ArgExists("-nofullscreen") || ArgExists("-window"))
{
setFlag(DDWF_FULLSCREEN, false);
}
if(ArgExists("-fullscreen") || ArgExists("-nowindow"))
{
setFlag(DDWF_FULLSCREEN);
}
}
void applyDisplayMode()
{
assertWindow();
if(flags & DDWF_FULLSCREEN)
{
const DisplayMode* mode = DisplayMode_FindClosest(width(), height(), colorDepthBits, 0);
if(mode)
{
if(DisplayMode_Change(mode))
{
widget->canvas().trapMouse();
}
}
}
else
{
DisplayMode_Change(DisplayMode_OriginalMode());
widget->canvas().trapMouse(false);
}
}
/**
* Applies the information stored in the Window instance to the actual
* widget geometry. Centering is applied in this stage (it only affects the
* widget's geometry).
*/
void applyWindowGeometry()
{
assertWindow();
applyDisplayMode();
if(flags & DDWF_FULLSCREEN)
{
if(widget->isVisible()) widget->showFullScreen();
}
else
{
QRect geom = rect();
if(flags & DDWF_CENTER)
{
// Center the window.
QSize screenSize = desktopRect().size();
geom = QRect(desktopRect().topLeft() +
QPoint((screenSize.width() - width())/2,
(screenSize.height() - height())/2),
screenSize);
}
if(flags & DDWF_MAXIMIZE)
{
if(widget->isVisible()) widget->showMaximized();
}
else
{
if(widget->isVisible() && widget->isMaximized()) widget->showNormal();
widget->setGeometry(geom);
appliedGeometry = geom; // Saved for detecting changes.
}
}
}
/**
* Retrieves the actual widget geometry and updates the information stored
* in the Window instance.
*/
void fetchWindowGeometry()
{
assertWindow();
setFlag(DDWF_MAXIMIZE, widget->isMaximized());
QRect rect = widget->normalGeometry();
geometry.origin.x = rect.x();
geometry.origin.y = rect.y();
geometry.size.width = rect.width();
geometry.size.height = rect.height();
Con_Message("Window geometry: %i,%i %ix%i (max? %i)\n", geometry.origin.x, geometry.origin.y,
geometry.size.width, geometry.size.height, (flags & DDWF_MAXIMIZE) != 0);
}
void setFlag(int flag, bool set = true)
{
if(set)
{
flags |= flag;
}
else
{
flags &= ~flag;
}
}
bool isGeometryValid() const
{
if(width() < WINDOW_MIN_WIDTH) return false;
if(height() < WINDOW_MIN_HEIGHT) return false;
return desktopValidRect().contains(rect());
}
bool applyAttributes(int* attribs)
{
// Parse the attributes array and check the values.
assert(attribs);
for(int i = 0; attribs[i]; ++i)
{
switch(attribs[i++])
{
case DDWA_X:
geometry.origin.x = attribs[i];
break;
case DDWA_Y:
geometry.origin.y = attribs[i];
break;
case DDWA_WIDTH:
geometry.size.width = attribs[i];
if(geometry.size.width < WINDOW_MIN_WIDTH) return false;
break;
case DDWA_HEIGHT:
geometry.size.height = attribs[i];
if(geometry.size.height < WINDOW_MIN_HEIGHT) return false;
break;
case DDWA_CENTER:
setFlag(DDWF_CENTER, attribs[i]);
break;
case DDWA_MAXIMIZE:
setFlag(DDWF_MAXIMIZE, attribs[i]);
break;
case DDWA_FULLSCREEN:
setFlag(DDWF_FULLSCREEN, attribs[i]);
break;
case DDWA_VISIBLE:
setFlag(DDWF_VISIBLE, attribs[i]);
break;
case DDWA_COLOR_DEPTH_BITS:
colorDepthBits = attribs[i];
if(colorDepthBits < 8 || colorDepthBits > 32) return false; // Illegal value.
break;
default:
// Unknown attribute.
return false;
}
}
// Check geometry for validity (window must be on the desktop
// at least partially).
if(!isGeometryValid())
{
// We can't place the window completely outside the desktop.
return false;
}
// Seems ok, apply them.
applyWindowGeometry();
return true;
}
};
/// Current active window where all drawing operations occur.
const Window* theWindow;
static boolean winManagerInited = false;
static Window mainWindow;
static boolean mainWindowInited = false;
/*
static int screenWidth, screenHeight, screenBPP;
static boolean screenIsWindow;
*/
Window* Window_Main(void)
{
return &mainWindow;
}
static __inline Window *getWindow(uint idx)
{
if(!winManagerInited)
return NULL; // Window manager is not initialized.
if(idx == 1)
return &mainWindow;
assert(false); // We can only have window 1 (main window).
return NULL;
}
Window* Window_ByIndex(uint id)
{
return getWindow(id);
}
#if 0
boolean Sys_ChangeVideoMode(int width, int height, int bpp)
{
LIBDENG_ASSERT_IN_MAIN_THREAD();
#if 0
// Do we need to change it?
if(width == screenWidth && height == screenHeight && bpp == screenBPP &&
screenIsWindow == !(theWindow->flags & DDWF_FULLSCREEN))
{
// Got it already.
DEBUG_Message(("Sys_ChangeVideoMode: Ignoring because already using %ix%i bpp:%i window:%i\n",
width, height, bpp, screenIsWindow));
return true;
}
DEBUG_Message(("Sys_ChangeVideoMode: Setting %ix%i bpp:%i window:%i\n",
width, height, bpp, screenIsWindow));
// TODO: Attempt to change mode.
// Update current mode.
screenWidth = width; //info->current_w;
screenHeight = height; //info->current_h;
screenBPP = bpp; //info->vfmt->BitsPerPixel;
screenIsWindow = (theWindow->flags & DDWF_FULLSCREEN? false : true);
#endif
return true;
#if 0
int flags = SDL_OPENGL;
const SDL_VideoInfo *info = NULL;
LIBDENG_ASSERT_IN_MAIN_THREAD();
// Do we need to change it?
if(width == screenWidth && height == screenHeight && bpp == screenBPP &&
screenIsWindow == !(theWindow->flags & DDWF_FULLSCREEN))
{
// Got it already.
DEBUG_Message(("Sys_ChangeVideoMode: Ignoring because already using %ix%i bpp:%i window:%i\n",
width, height, bpp, screenIsWindow));
return true;
}
if(theWindow->flags & DDWF_FULLSCREEN)
flags |= SDL_FULLSCREEN;
DEBUG_Message(("Sys_ChangeVideoMode: Setting %ix%i bpp:%i window:%i\n",
width, height, bpp, screenIsWindow));
if(!SDL_SetVideoMode(width, height, bpp, flags))
{
// This could happen for a variety of reasons, including
// DISPLAY not being set, the specified resolution not being
// available, etc.
Con_Message("SDL Error: %s\n", SDL_GetError());
return false;
}
info = SDL_GetVideoInfo();
screenWidth = info->current_w;
screenHeight = info->current_h;
screenBPP = info->vfmt->BitsPerPixel;
screenIsWindow = (theWindow->flags & DDWF_FULLSCREEN? false : true);
return true;
#endif
}
#endif
#if 0
static boolean setDDWindow(Window *window, int newWidth, int newHeight,
int newBPP, uint wFlags, uint uFlags)
{
int width, height, bpp, flags;
boolean newGLContext = false;
boolean changeWindowDimensions = false;
boolean inControlPanel = false;
if(novideo)
return true;
if(uFlags & DDSW_NOCHANGES)
return true; // Nothing to do.
// Grab the current values.
width = window->geometry.size.width;
height = window->geometry.size.height;
bpp = window->bpp;
flags = window->flags;
// Force update on init?
if(!window->inited && window->type == WT_NORMAL)
{
newGLContext = true;
}
if(window->type == WT_NORMAL)
inControlPanel = UI_IsActive();
// Change to fullscreen?
if(!(uFlags & DDSW_NOFULLSCREEN) &&
(flags & DDWF_FULLSCREEN) != (wFlags & DDWF_FULLSCREEN))
{
flags ^= DDWF_FULLSCREEN;
if(window->type == WT_NORMAL)
{
newGLContext = true;
//changeVideoMode = true;
}
}
// Change window size?
if(!(uFlags & DDSW_NOSIZE) && (width != newWidth || height != newHeight))
{
width = newWidth;
height = newHeight;
changeWindowDimensions = true;
if(window->type == WT_NORMAL)
newGLContext = true;
}
// Change BPP (bits per pixel)?
if(window->type == WT_NORMAL)
{
if(!(uFlags & DDSW_NOBPP) && bpp != newBPP)
{
if(!(newBPP == 32 || newBPP == 16))
Con_Error("Sys_SetWindow: Unsupported BPP %i.", newBPP);
bpp = newBPP;
newGLContext = true;
//changeVideoMode = true;
}
}
if(changeWindowDimensions && window->type == WT_NORMAL)
{
// Can't change the resolution while the UI is active.
// (controls need to be repositioned).
if(inControlPanel)
UI_End();
}
/*
if(changeVideoMode)
{
if(flags & DDWF_FULLSCREEN)
{
if(!Sys_ChangeVideoMode(width, height, bpp))
{
Sys_CriticalMessage("Sys_SetWindow: Resolution change failed.");
return false;
}
}
else
{
// Go back to normal display settings.
ChangeDisplaySettings(0, 0);
}
}
*/
// Update the current values.
window->geometry.size.width = width;
window->geometry.size.height = height;
window->bpp = bpp;
window->flags = flags;
if(!window->inited)
window->inited = true;
// Do NOT modify Window properties after this point.
// Do we need a new GL context due to changes to the window?
if(newGLContext)
{
#if 0
// Maybe requires a renderer restart.
extern boolean usingFog;
boolean glIsInited = GL_IsInited();
#if defined(WIN32)
void *data = window->hWnd;
#else
void *data = NULL;
#endif
boolean hadFog = false;
if(glIsInited)
{
// Shut everything down, but remember our settings.
hadFog = usingFog;
GL_TotalReset();
if(DD_GameLoaded() && gx.UpdateState)
gx.UpdateState(DD_RENDER_RESTART_PRE);
R_UnloadSvgs();
GL_ReleaseTextures();
}
if(createContext(window->geometry.size.width, window->geometry.size.height,
window->normal.bpp, (window->flags & DDWF_FULLSCREEN)? false : true, data))
{
// We can get on with initializing the OGL state.
Sys_GLConfigureDefaultState();
}
if(glIsInited)
{
// Re-initialize.
GL_TotalRestore();
GL_InitRefresh();
if(hadFog)
GL_UseFog(true);
if(DD_GameLoaded() && gx.UpdateState)
gx.UpdateState(DD_RENDER_RESTART_POST);
}
#endif
}
// If the window dimensions have changed, update any sub-systems
// which need to respond.
if(changeWindowDimensions && window->type == WT_NORMAL)
{
// Update viewport coordinates.
R_SetViewGrid(0, 0);
if(inControlPanel) // Reactivate the panel?
Con_Execute(CMDS_DDAY, "panel", true, false);
}
return true;
}
#endif
/**
* Initialize the window manager.
* Tasks include; checking the system environment for feature enumeration.
*
* @return @c true, if initialization was successful.
*/
boolean Sys_InitWindowManager(void)
{
if(winManagerInited)
return true; // Already been here.
Con_Message("Sys_InitWindowManager: Using Qt window management.\n");
CanvasWindow::setDefaultGLFormat();
#ifdef UNIX
// Initialize the SDL video subsystem, unless we're going to run in
// dedicated mode.
if(!ArgExists("-dedicated"))
{
SDL_InitSubSystem(SDL_INIT_VIDEO); // used for gamma
}
#endif
#if 0
// Initialize the SDL video subsystem, unless we're going to run in
// dedicated mode.
if(!ArgExists("-dedicated"))
{
/**
* @attention Solaris has no Joystick support according to
* https://sourceforge.net/tracker/?func=detail&atid=542099&aid=1732554&group_id=74815
*/
#ifdef SOLARIS
if(SDL_InitSubSystem(SDL_INIT_VIDEO))
#else
if(SDL_InitSubSystem(SDL_INIT_VIDEO | (!ArgExists("-nojoy")?SDL_INIT_JOYSTICK : 0)))
#endif
{
Con_Message("SDL Init Failed: %s\n", SDL_GetError());
return false;
}
}
#endif
memset(&mainWindow, 0, sizeof(mainWindow));
winManagerInited = true;
theWindow = &mainWindow;
return true;
}
/**
* Shutdown the window manager.
*
* @return @c true, if shutdown was successful.
*/
boolean Sys_ShutdownWindowManager(void)
{
if(!winManagerInited)
return false; // Window manager is not initialized.
// Get rid of the windows.
Window_Delete(Window_Main());
// Now off-line, no more window management will be possible.
winManagerInited = false;
return true;
}
#if 0
/**
* Attempt to acquire a device context for OpenGL rendering and then init.
*
* @param width Width of the OGL window.
* @param height Height of the OGL window.
* @param bpp 0= the current display color depth is used.
* @param windowed @c true = windowed mode ELSE fullscreen.
* @param data Ptr to system-specific data, e.g a window handle
* or similar.
*
* @return @c true if successful.
*/
static boolean createContext(void)
{
Con_Message("createContext: OpenGL.\n");
#if 0
// Set GL attributes. We want at least 5 bits per color and a 16
// bit depth buffer. Plus double buffering, of course.
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#endif
/*
// Attempt to set the video mode.
if(!Sys_ChangeVideoMode(Window_Width(theWindow),
Window_Height(theWindow),
Window_ColorDepthBits(theWindow)))
{
Con_Error("createContext: Video mode change failed.\n");
return false;
}
*/
Sys_GLConfigureDefaultState();
#ifdef MACOSX
// Vertical sync is a GL context property.
GL_SetVSync(true);
#endif
return true;
}
#endif
static Window* canvasToWindow(Canvas& canvas)
{
assert(&mainWindow.widget->canvas() == &canvas); /// @todo multiwindow
return &mainWindow;
}
static void drawCanvasWithCallback(Canvas& canvas)
{
Window* win = canvasToWindow(canvas);
if(win->drawFunc)
{
win->drawFunc();
}
}
/*
static void windowFocusChanged(Canvas& canvas, bool focus)
{
Window* wnd = canvasToWindow(canvas);
wnd->assertWindow();
qDebug() << "windowFocusChanged" << focus << "fullscreen" << Window_IsFullscreen(wnd)
<< "hidden" << wnd->widget->isHidden() << wnd->widget->isMinimized();
if(Window_IsFullscreen(wnd))
{
if(!focus)
{
DisplayMode_Change(DisplayMode_OriginalMode());
}
else
{
wnd->applyDisplayMode();
}
}
}
*/
static void finishMainWindowInit(Canvas& canvas)
{
Window* win = canvasToWindow(canvas);
assert(win == &mainWindow);
#ifdef MACOSX
if(Window_IsFullscreen(win))
{
// The window must be manually raised above the shielding window put up by
// the display capture.
DisplayMode_Native_Raise(Window_NativeHandle(win));
}
#endif
//win->widget->canvas().setFocusFunc(windowFocusChanged);
DD_FinishInitializationAfterWindowReady();
}
static void windowWasMoved(CanvasWindow& cw)
{
Window* win = canvasToWindow(cw.canvas());
win->fetchWindowGeometry();
win->setFlag(DDWF_CENTER, false);
}
static void windowWasResized(Canvas& canvas)
{
Window* win = canvasToWindow(canvas);
DEBUG_Message(("Updating view geometry.\n"));
win->setFlag(DDWF_CENTER, false);
win->geometry.size.width = win->widget->width();
win->geometry.size.height = win->widget->height();
// Update viewports.
R_SetViewGrid(0, 0);
if(Con_IsBusy() || UI_IsActive())
{
// Update for busy mode.
R_UseViewPort(0);
}
if(UI_IsActive())
{
UI_UpdatePageLayout();
}
R_LoadSystemFonts();
}
static Window* createWindow(ddwindowtype_t type, const char* title)
{
if(mainWindowInited) return NULL; /// @todo Allow multiple.
Window* wnd = &mainWindow;
memset(wnd, 0, sizeof(*wnd));
mainWindowIdx = 1;
if(type == WT_CONSOLE)
{
mainWindow.type = WT_CONSOLE;
Sys_ConInit(title);
}
else
{
Window_RestoreState(&mainWindow);
// Create the main window (hidden).
mainWindow.widget = new CanvasWindow;
Window_SetTitle(&mainWindow, title);
// Minimum possible size when resizing.
mainWindow.widget->setMinimumSize(QSize(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT));
// After the main window is created, we can finish with the engine init.
mainWindow.widget->canvas().setInitFunc(finishMainWindowInit);
mainWindow.widget->setMoveFunc(windowWasMoved);
mainWindow.widget->canvas().setResizedFunc(windowWasResized);
// Let's see if there are command line options overriding the previous state.
mainWindow.modifyAccordingToOptions();
// Make it so. (Not shown yet.)
mainWindow.applyWindowGeometry();
mainWindow.inited = true;
#if 0
#if defined(WIN32)
// We need to grab a handle from SDL so we can link other subsystems
// (e.g. DX-based input).
{
struct SDL_SysWMinfo wmInfo;
if(!SDL_GetWMInfo(&wmInfo))
return NULL;
mainWindow.hWnd = wmInfo.window;
}
#endif
#endif
}
/// @todo Refactor for multiwindow support.
mainWindowInited = true;
return &mainWindow;
}
Window* Window_New(ddwindowtype_t type, const char* title)
{
if(!winManagerInited) return 0;
return createWindow(type, title);
}
void Window_Delete(Window* wnd)
{
assert(wnd);
if(wnd->type == WT_CONSOLE)
{
Sys_ConShutdown(wnd);
}
else
{
wnd->assertWindow();
wnd->widget->canvas().setFocusFunc(0);
// Make sure we'll remember the config.
Window_SaveState(wnd);
if(wnd == &mainWindow)
{
DisplayMode_Shutdown();
}
// Delete the CanvasWindow.
delete wnd->widget;
memset(wnd, 0, sizeof(*wnd));
}
}
#if 0
/**
* Attempt to set the appearance/behavioral properties of the given window.
*
* @param idx Index identifier (1-based) to the window.
* @param newX New x position of the left side of the window.
* @param newY New y position of the top of the window.
* @param newWidth New width to set the window to.
* @param newHeight New height to set the window to.
* @param newBPP New BPP (bits-per-pixel) to change to.
* @param wFlags DDWF_* flags to change other appearance/behavior.
* @param uFlags DDSW_* flags govern how the other paramaters should be
* interpreted.
*
* DDSW_NOSIZE:
* If set, params 'newWidth' and 'newHeight' are ignored
* and no change will be made to the window dimensions.
*
* DDSW_NOMOVE:
* If set, params 'newX' and 'newY' are ignored and no
* change will be made to the window position.
*
* DDSW_NOBPP:
* If set, param 'newBPP' is ignored and the no change
* will be made to the window color depth.
*
* DDSW_NOFULLSCREEN:
* If set, the value of the DDWF_FULLSCREEN bit in param
* 'wFlags' is ignored and no change will be made to the
* fullscreen state of the window.
*
* DDSW_NOVISIBLE:
* If set, the value of the DDWF_VISIBLE bit in param
* 'wFlags' is ignored and no change will be made to the
* window's visibility.
*
* DDSW_NOCENTER:
* If set, the value of the DDWF_CENTER bit in param
* 'wFlags' is ignored and no change will be made to the
* auto-center state of the window.
*
* @return @c true, if successful.
*/
boolean Sys_SetWindow(uint idx, int newX, int newY, int newWidth, int newHeight,
int newBPP, uint wFlags, uint uFlags)
{
Window *window = getWindow(idx);
if(window)
{
// TODO: Update if necessary.
return true;
}
/*
if(window)
return setDDWindow(window, newWidth, newHeight, newBPP,
wFlags, uFlags);
*/
return false;
}
#endif
boolean Window_ChangeAttributes(Window* wnd, int* attribs)
{
Window oldState = *wnd;
if(!wnd->applyAttributes(attribs))
{
// These weren't good!
*wnd = oldState;
return false;
}
// Everything ok!
return true;
}