/
sys_sdl_window.c
998 lines (839 loc) · 27.6 KB
/
sys_sdl_window.c
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
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2011 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2009 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2008 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* 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
*/
/**
* sys_sdl_window.c: Cross-platform, SDL-based window management.
*
* This code wraps SDL window management routines in order to provide
* common behavior. The availabilty of features and behavioral traits can
* be queried for.
*/
// HEADER FILES ------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <SDL.h>
#include <SDL_syswm.h>
#include "de_base.h"
#include "de_console.h"
#include "de_system.h"
#include "de_refresh.h"
#include "de_misc.h"
#include "de_ui.h"
// MACROS ------------------------------------------------------------------
#define LINELEN (1024)
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static boolean setDDWindow(ddwindow_t *win, int newWidth, int newHeight,
int newBPP, uint wFlags, uint uFlags);
static void setConWindowCmdLine(uint idx, const char *text,
unsigned int cursorPos, int flags);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// Currently active window where all drawing operations are directed at.
const ddwindow_t* theWindow;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static boolean winManagerInited = false;
static ddwindow_t mainWindow;
static boolean mainWindowInited = false;
static int screenWidth, screenHeight, screenBPP;
#if defined(UNIX)
static WINDOW* cursesRootWin;
#endif
// CODE --------------------------------------------------------------------
static __inline ddwindow_t *getWindow(uint idx)
{
if(!winManagerInited)
return NULL; // Window manager is not initialized.
if(idx != 0)
return NULL;
return &mainWindow;
}
#if defined(UNIX)
static void setAttrib(int flags)
{
if(!mainWindowInited)
return;
if(flags & (CBLF_YELLOW | CBLF_LIGHT))
wattrset(mainWindow.console.winText, A_BOLD);
else
wattrset(mainWindow.console.winText, A_NORMAL);
}
/**
* Writes the text in winText at (cx,cy).
*/
static void writeText(const char *line, int len)
{
wmove(mainWindow.console.winText,
mainWindow.console.cy, mainWindow.console.cx);
waddnstr(mainWindow.console.winText, line, len);
wclrtoeol(mainWindow.console.winText);
}
static int getScreenSize(int axis)
{
int x, y;
getmaxyx(mainWindow.console.winText, y, x);
return axis == VX ? x : y;
}
void Sys_ConPrint(uint idx, const char *text, int clflags)
{
ddwindow_t *win;
char line[LINELEN];
int count = strlen(text), lineStart, bPos;
const char *ptr = text;
char ch;
int maxPos[2];
if(!winManagerInited || !text)
return;
if(!novideo && idx != 1)
{
// We only support one terminal window (this isn't for us).
return;
}
win = &mainWindow;
// Determine the size of the text window.
getmaxyx(win->console.winText, maxPos[VY], maxPos[VX]);
if(win->console.needNewLine)
{
// Need to make some room.
win->console.cx = 0;
win->console.cy++;
if(win->console.cy >= maxPos[VY])
{
win->console.cy--;
scroll(win->console.winText);
}
win->console.needNewLine = false;
}
bPos = lineStart = win->console.cx;
setAttrib(clflags);
for(; count > 0; count--, ptr++)
{
ch = *ptr;
// Ignore carriage returns.
if(ch == '\r')
continue;
if(ch != '\n' && bPos < maxPos[VX])
{
line[bPos] = ch;
bPos++;
}
// Time for newline?
if(ch == '\n' || bPos >= maxPos[VX])
{
writeText(line + lineStart, bPos - lineStart);
win->console.cx += bPos - lineStart;
bPos = 0;
lineStart = 0;
if(count > 1) // Not the last character?
{
win->console.needNewLine = false;
win->console.cx = 0;
win->console.cy++;
if(win->console.cy == maxPos[VY])
{
scroll(win->console.winText);
win->console.cy--;
}
}
else
win->console.needNewLine = true;
}
}
// Something in the buffer?
if(bPos - lineStart)
{
writeText(line + lineStart, bPos - lineStart);
win->console.cx += bPos - lineStart;
}
wrefresh(win->console.winText);
// Move the cursor back onto the command line.
setConWindowCmdLine(1, NULL, 0, 0);
}
/**
* Set the command line display of the specified console window.
*
* @param idx Console window identifier.
* @param text Text string to copy.
* @param cursorPos Position to set the cursor on the command line.
* @param flags CLF_* flags control the appearance of the
* command line.
*/
void Sys_SetConWindowCmdLine(uint idx, const char *text, uint cursorPos,
int flags)
{
ddwindow_t *win;
if(!winManagerInited)
return;
win = getWindow(idx - 1);
if(!win || win->type != WT_CONSOLE)
return;
setConWindowCmdLine(idx, text, cursorPos, flags);
}
static void setConWindowCmdLine(uint idx, const char *text,
unsigned int cursorPos, int flags)
{
ddwindow_t *win;
unsigned int i;
char line[LINELEN], *ch;
int maxX;
int length;
if(idx != 1)
{
// We only support one console window; (this isn't for us).
return;
}
win = &mainWindow;
maxX = getScreenSize(VX);
if(!text)
{
int y, x;
// Just move the cursor into the command line window.
getyx(win->console.winCommand, y, x);
wmove(win->console.winCommand, y, x);
}
else
{
memset(line, 0, sizeof(line));
line[0] = '>';
for(i = 0, ch = line + 1; i < LINELEN - 1; ++i, ch++)
{
if(i < strlen(text))
*ch = text[i];
else
*ch = 0;
}
wmove(win->console.winCommand, 0, 0);
// Can't print longer than the window.
length = strlen(text);
waddnstr(win->console.winCommand, line, MIN_OF(maxX, length + 1));
wclrtoeol(win->console.winCommand);
}
wrefresh(win->console.winCommand);
}
#endif
boolean Sys_ChangeVideoMode(int width, int height, int bpp)
{
int flags = SDL_OPENGL;
const SDL_VideoInfo *info = NULL;
int windowflags;
windowflags = (theWindow->flags);
if(windowflags & DDWF_FULLSCREEN)
flags |= SDL_FULLSCREEN;
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;
}
Con_Message("createContext: OpenGL.\n");
info = SDL_GetVideoInfo();
screenWidth = info->current_w;
screenHeight = info->current_h;
screenBPP = info->vfmt->BitsPerPixel;
return true;
}
/**
* 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 SDL window management.\n");
// 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;
}
}
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.
if(mainWindow.type == WT_CONSOLE)
Sys_DestroyWindow(1);
// Now off-line, no more window management will be possible.
winManagerInited = false;
//if(isDedicated)
// Sys_ConShutdown();
return true;
}
static boolean initOpenGL(void)
{
// Attempt to set the video mode.
if(!Sys_ChangeVideoMode(theWindow->width, theWindow->height,
theWindow->normal.bpp))
return false;
// Setup the GL state like we want it.
Sys_InitGLState();
return true;
}
/**
* Attempt to acquire a device context for OGL 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(int width, int height, int bpp,
boolean windowed, void *data)
{
Con_Message("createContext: OpenGL.\n");
// 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_DOUBLEBUFFER, 1);
if(!initOpenGL())
{
Con_Error("createContext: OpenGL init failed.\n");
}
return true;
}
/**
* Complete the given wminfo_t, detailing what features are supported by
* this window manager implementation.
*
* @param info Ptr to the wminfo_t structure to complete.
*
* @return @c true, if successful.
*/
boolean Sys_GetWindowManagerInfo(wminfo_t *info)
{
if(!winManagerInited)
return false; // Window manager is not initialized.
if(!info)
return false; // Wha?
// Complete the structure detailing what features are available.
info->canMoveWindow = false;
info->maxWindows = 1;
info->maxConsoles = 1;
return true;
}
static ddwindow_t *createDDWindow(application_t *app, int w, int h, int bpp,
int flags, ddwindowtype_t type,
const char *title)
{
// SDL only supports one window.
if(mainWindowInited)
return NULL;
if(type == WT_CONSOLE)
{
#if defined(UNIX)
int maxPos[2];
// Initialize curses.
if(!(cursesRootWin = initscr()))
Sys_CriticalMessage("createDDWindow: Failed creating terminal.");
cbreak();
noecho();
nonl();
mainWindow.type = type;
// The current size of the screen.
getmaxyx(stdscr, maxPos[VY], maxPos[VX]);
// Create the three windows we will be using.
mainWindow.console.winTitle = newwin(1, maxPos[VX], 0, 0);
mainWindow.console.winText = newwin(maxPos[VY] - 2, maxPos[VX], 1, 0);
mainWindow.console.winCommand = newwin(1, maxPos[VX], maxPos[VY] - 1, 0);
// Set attributes.
wattrset(mainWindow.console.winTitle, A_REVERSE);
wattrset(mainWindow.console.winText, A_NORMAL);
wattrset(mainWindow.console.winCommand, A_BOLD);
scrollok(mainWindow.console.winText, TRUE);
wclear(mainWindow.console.winText);
wrefresh(mainWindow.console.winText);
keypad(mainWindow.console.winCommand, TRUE);
nodelay(mainWindow.console.winCommand, TRUE);
setConWindowCmdLine(1, "", 1, 0);
// The background will also be in reverse.
wbkgdset(mainWindow.console.winTitle, ' ' | A_REVERSE);
// First clear the whole line.
wmove(mainWindow.console.winTitle, 0, 0);
wclrtoeol(mainWindow.console.winTitle);
// Center the title.
wmove(mainWindow.console.winTitle, 0, getmaxx(mainWindow.console.winTitle) / 2 - strlen(title) / 2);
waddstr(mainWindow.console.winTitle, title);
wrefresh(mainWindow.console.winTitle);
// We'll need the input event handler.
Sys_ConInputInit();
#endif
}
else
{
if(!(bpp == 32 || bpp == 16))
{
Con_Message("createWindow: Unsupported BPP %i.", bpp);
return 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
}
setDDWindow(&mainWindow, w, h, bpp, flags,
DDSW_NOVISIBLE | DDSW_NOCENTER | DDSW_NOFULLSCREEN);
mainWindowInited = true;
return &mainWindow;
}
/**
* Create a new (OpenGL-ready) system window.
*
* @param app Ptr to the application structure holding our globals.
* @param parentIDX Ignored: SDL does not support parent/child windows.
* @param x Ignored: SDL does not support changing X position.
* @param y Ignored: SDL does not support changing Y position..
* @param w Width (client area).
* @param h Height (client area).
* @param bpp BPP (bits-per-pixel)
* @param flags DDWF_* flags, control appearance/behavior.
* @param type Type of window to be created.
* @param title Window title string, ELSE @c NULL,.
* @param data Platform specific data.
*
* @return If @c 0, window creation was unsuccessful,
* ELSE 1-based index identifier of the new window.
*/
uint Sys_CreateWindow(application_t *app, uint parentIDX,
int x, int y, int w, int h, int bpp, int flags,
ddwindowtype_t type, const char *title, void *data)
{
ddwindow_t *win;
if(!winManagerInited)
return 0; // Window manager not initialized yet.
win = createDDWindow(app, w, h, bpp, flags, type, title);
if(win)
return 1; // Success.
return 0;
}
/**
* Destroy the specified window.
*
* Side-effects: If the window is fullscreen and the current video mode is
* not that set as the desktop default: an attempt will be made to change
* back to the desktop default video mode.
*
* @param idx Index of the window to destroy (1-based).
*
* @return @c true, if successful.
*/
boolean Sys_DestroyWindow(uint idx)
{
ddwindow_t *window = getWindow(idx - 1);
if(!window)
return false;
if(window->type == WT_CONSOLE)
{
// Delete windows and shut down curses.
delwin(window->console.winTitle);
delwin(window->console.winText);
delwin(window->console.winCommand);
window->console.winTitle = window->console.winText =
window->console.winCommand = NULL;
delwin(cursesRootWin);
cursesRootWin = 0;
endwin();
refresh();
Sys_ConInputShutdown();
}
return true;
}
/**
* Change the currently active window.
*
* @param idx Index of the window to make active (1-based).
*
* @return @c true, if successful.
*/
boolean Sys_SetActiveWindow(uint idx)
{
// We only support one window, so yes its active.
return true;
}
static boolean setDDWindow(ddwindow_t *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->width;
height = window->height;
bpp = window->normal.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->width = width;
window->height = height;
window->normal.bpp = bpp;
window->flags = flags;
if(!window->inited)
window->inited = true;
// Do NOT modify ddwindow_t properties after this point.
// Do we need a new GL context due to changes to the window?
if(newGLContext)
{ // 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;
if(glIsInited)
{
// Shut everything down, but remember our settings.
hadFog = usingFog;
GL_TotalReset();
gx.UpdateState(DD_RENDER_RESTART_PRE);
UI_ClearTextures();
}
if(createContext(window->width, window->height, window->normal.bpp,
(window->flags & DDWF_FULLSCREEN)? false : true,
data))
{
// We can get on with initializing the OGL state.
Sys_InitGLState();
}
if(glIsInited)
{
// Re-initialize.
GL_TotalRestore();
GL_InitRefresh();
if(hadFog)
GL_UseFog(true);
gx.UpdateState(DD_RENDER_RESTART_POST);
UI_LoadTextures();
}
}
/*else
{
Sys_ChangeVideoMode(window->width, window->height, window->normal.bpp);
}*/
// 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;
}
/**
* 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)
{
ddwindow_t *window = getWindow(idx - 1);
if(window)
return setDDWindow(window, newWidth, newHeight, newBPP,
wFlags, uFlags);
return false;
}
/**
* Make the content of the framebuffer visible.
*/
void Sys_UpdateWindow(uint idx)
{
if(GL_state.forceFinishBeforeSwap)
{
glFinish();
}
// Swap buffers.
SDL_GL_SwapBuffers(); // Includes a call to glFlush()
}
/**
* Attempt to set the title of the given window.
*
* @param idx Index identifier (1-based) to the window.
* @param title New title for the window.
*
* @return @c true, if successful.
*/
boolean Sys_SetWindowTitle(uint idx, const char *title)
{
ddwindow_t *window = getWindow(idx - 1);
if(window)
{
if(window->type == WT_NORMAL)
{
SDL_WM_SetCaption(title, NULL);
}
else // Its a terminal window.
{
#if defined(UNIX)
// The background will also be in reverse.
wbkgdset(window->console.winTitle, ' ' | A_REVERSE);
// First clear the whole line.
wmove(window->console.winTitle, 0, 0);
wclrtoeol(window->console.winTitle);
// Center the title.
wmove(window->console.winTitle, 0, getmaxx(window->console.winTitle) / 2 - strlen(title) / 2);
waddstr(window->console.winTitle, title);
wrefresh(window->console.winTitle);
#endif
}
return true;
}
return false;
}
/**
* Attempt to get the dimensions (and position) of the given window (client
* area) in screen-space.
*
* @param idx Index identifier (1-based) to the window.
* @param x Address to write the x position back to,
* unsupported by SDL so always 0.
* @param y Address to write the y position back to,
* unsupported by SDL so always 0.
* @param width Address to write the width back to (if any).
* @param height Address to write the height back to (if any).
*
* @return @c true, if successful.
*/
boolean Sys_GetWindowDimensions(uint idx, int *x, int *y, int *width,
int *height)
{
ddwindow_t *window = getWindow(idx - 1);
if(!window || (!x && !y && !width && !height))
return false;
// Moving does not work in dedicated mode.
if(isDedicated)
return false;
if(x)
*x = 0;
if(y)
*y = 0;
if(width)
*width = window->width;
if(height)
*height = window->height;
return true;
}
/**
* Attempt to get the BPP (bits-per-pixel) of the given window.
*
* @param idx Index identifier (1-based) to the window.
* @param bpp Address to write the BPP back to (if any).
*
* @return @c true, if successful.
*/
boolean Sys_GetWindowBPP(uint idx, int *bpp)
{
ddwindow_t *window = getWindow(idx - 1);
if(!window || !bpp)
return false;
// Not in dedicated mode.
if(isDedicated)
return false;
*bpp = window->normal.bpp;
return true;
}
/**
* Attempt to get the fullscreen-state of the given window.
*
* @param idx Index identifier (1-based) to the window.
* @param fullscreen Address to write the fullscreen state back to (if any).
*
* @return @c true, if successful.
*/
boolean Sys_GetWindowFullscreen(uint idx, boolean *fullscreen)
{
ddwindow_t *window = getWindow(idx - 1);
if(!window || !fullscreen)
return false;
*fullscreen = ((window->flags & DDWF_FULLSCREEN)? true : false);
return true;
}
/**
* Attempt to get a HWND handle to the given window.
*
* \todo: Factor platform specific design patterns out of Doomsday. We should
* not be passing around HWND handles...
*
* @param idx Index identifier (1-based) to the window.
*
* @return HWND handle if successful, ELSE @c NULL,.
*/
#if defined(WIN32)
HWND Sys_GetWindowHandle(uint idx)
{
ddwindow_t *window = getWindow(idx - 1);
if(!window)
return NULL;
return window->hWnd;
}
#endif