DXGL r680 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r679‎ | r680 | r681 >
Date:22:37, 21 August 2016
Author:admin
Status:new
Tags:
Comment:
Add borderless window mode.
Modified paths:
  • /Help/configuration.htm (modified) (history)
  • /cfgmgr/ReadMe.txt (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/hooks.c (modified) (history)
  • /dxglcfg/dxglcfg.c (modified) (history)

Diff [purge]

Index: Help/configuration.htm
@@ -90,11 +90,13 @@
9191 <h3>Exclusive fullscreen</h3>
9292 Sets the display to fullscreen mode. For Windows Vista and greater, causes the Windows graphics to be temporarily suspended, giving the GPU exclusive control of the screen. This mode is the default and may have the best fullscreen performance.
9393 <h3>Non-exclusive fullscreen</h3>
94 - Creates a window that fills the screen but tells the display driver not to take exclusive control of the screen. This is also known as borderless windowed mode. Try this mode if the application mixes DirectDraw with GDI and some graphics elements are missing.
95 - In Windows Vista and greater, this mode may have reduced performance, increased lag, or choppy graphics.
 94+ Creates a window that fills the screen but tells the display driver not to take exclusive control of the screen. Try this mode if the application mixes DirectDraw with GDI and some graphics elements are missing.
 95+ In Windows Vista and greater, this mode may have reduced performance, increased lag, or choppy graphics. In Windows 8 and 8.1, this performance reduction may be significant due to an operating system flaw.
9696 <h3>Non-resizable window</h3>
9797 Forces the fullscreen application to display in a floating window. Please note that some applications may capture the mouse and thus may cause compatibility issues.
9898 <h3>Resizable window</h3>
9999 Forces the fullscreen application to display in a floating window that can be resized or maximized. Please note that some applications may capture the mouse and thus may cause compatibility issues.
 100+ <h3>Borderless window</h3>
 101+ Forces the application to display in a borderless pop-up window. If the application is not running at the same resolution as the display, the window will be the same size as the application's display resolution.
100102 </body>
101103 </html>
\ No newline at end of file
Index: cfgmgr/ReadMe.txt
@@ -17,9 +17,10 @@
1818 Determines how to handle fullscreen modes.
1919 Valid settings:
2020 0 - Use exclusive fullscreen
21 -1 - Use non-exclusive fullscreen aka borderless window
 21+1 - Use non-exclusive fullscreen, not quite borderless windowed mode
2222 2 - Use a non-resizable window
2323 3 - Use a resizable window, uses scaler mode, preferably 1, 2, 3, or 7
 24+4 - Use a borderless, non-resizable window, called windowed borderless in industry
2425
2526 Member colormode
2627 REG_DWORD HKCU\DXGL\<app>\ChangeColorDepth
Index: ddraw/glDirectDraw.cpp
@@ -1926,7 +1926,8 @@
19271927 }
19281928 break;
19291929 case 2:
1930 - case 3: // Forced windowed modes
 1930+ case 3:
 1931+ case 4: // Forced windowed modes
19311932 primaryx = internalx = screenx = dwWidth;
19321933 primaryy = internaly = screeny = dwHeight;
19331934 internalbpp = screenbpp = dwBPP;
Index: ddraw/glRenderer.cpp
@@ -367,7 +367,7 @@
368368 SetWindowLongPtrA(This->hWnd, GWL_STYLE, (winstyle | WS_POPUP) & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER));
369369 ShowWindow(This->hWnd, SW_MAXIMIZE);
370370 break;
371 - case 1: // Fullscreen
 371+ case 1: // Non-exclusive Fullscreen
372372 winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
373373 winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
374374 SetWindowLongPtrA(This->hWnd, GWL_EXSTYLE, winstyleex & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
@@ -374,7 +374,7 @@
375375 SetWindowLongPtrA(This->hWnd, GWL_STYLE, winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP));
376376 ShowWindow(This->hWnd, SW_MAXIMIZE);
377377 break;
378 - case 2: // Windowed
 378+ case 2: // Windowed non-resizable
379379 winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
380380 winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
381381 SetWindowLongPtrA(This->hWnd, GWL_EXSTYLE, winstyleex | WS_EX_APPWINDOW);
@@ -388,6 +388,13 @@
389389 SetWindowLongPtrA(This->hWnd, GWL_STYLE, (winstyle | WS_OVERLAPPEDWINDOW) & ~WS_POPUP);
390390 ShowWindow(This->hWnd, SW_MAXIMIZE);
391391 break;
 392+ case 4: // Windowed borderless
 393+ winstyle = GetWindowLongPtrA(This->hWnd, GWL_STYLE);
 394+ winstyleex = GetWindowLongPtrA(This->hWnd, GWL_EXSTYLE);
 395+ SetWindowLongPtrA(This->hWnd, GWL_EXSTYLE, winstyleex & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
 396+ SetWindowLongPtrA(This->hWnd, GWL_STYLE, winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP));
 397+ ShowWindow(This->hWnd, SW_MAXIMIZE);
 398+ break;
392399 }
393400 }
394401 if(width)
@@ -730,6 +737,21 @@
731738 SetWindowPos(newwnd, 0, wndrect.left, wndrect.top, wndrect.right - wndrect.left,
732739 wndrect.bottom - wndrect.top, SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
733740 break;
 741+ case 4: // Windowed borderless
 742+ winstyle = GetWindowLongPtrA(newwnd, GWL_STYLE);
 743+ winstyleex = GetWindowLongPtrA(newwnd, GWL_EXSTYLE);
 744+ SetWindowLongPtrA(newwnd, GWL_EXSTYLE, winstyleex & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
 745+ SetWindowLongPtrA(newwnd, GWL_STYLE, winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP));
 746+ ShowWindow(newwnd, SW_NORMAL);
 747+ screenx = GetSystemMetrics(SM_CXSCREEN);
 748+ screeny = GetSystemMetrics(SM_CYSCREEN);
 749+ wndrect.right = width + (screenx / 2) - (width / 2);
 750+ wndrect.bottom = height + (screeny / 2) - (height / 2);
 751+ wndrect.left = (screenx / 2) - (width / 2);
 752+ wndrect.top = (screeny / 2) - (height / 2);
 753+ SetWindowPos(newwnd, 0, wndrect.left, wndrect.top, wndrect.right - wndrect.left,
 754+ wndrect.bottom - wndrect.top, SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
 755+ break;
734756 }
735757 }
736758 This->inputs[0] = (void*)width;
Index: ddraw/hooks.c
@@ -290,7 +290,7 @@
291291 switch (dxglcfg.fullmode)
292292 {
293293 case 0:
294 - // Fix fullscreen mode
 294+ // Fix exclusive fullscreen mode
295295 if (lpDD7)
296296 {
297297 glDirectDraw7_GetSizes(lpDD7, sizes);
@@ -311,7 +311,7 @@
312312 }
313313 break;
314314 case 1:
315 - // Fix borderless mode
 315+ // Fix non-exclusive fullscreen mode
316316 if (lpDD7)
317317 {
318318 glDirectDraw7_GetSizes(lpDD7, sizes);
@@ -368,6 +368,26 @@
369369 }
370370 }
371371 break;
 372+ case 4:
 373+ // Fix borderless window mode
 374+ if (lpDD7)
 375+ {
 376+ glDirectDraw7_GetSizes(lpDD7, sizes);
 377+ GetWindowRect(hWnd, &r1);
 378+ GetClientRect(hWnd, &r2);
 379+ winstyle = GetWindowLong(hWnd, GWL_STYLE);
 380+ exstyle = GetWindowLong(hWnd, GWL_EXSTYLE);
 381+ if (winstyle & (WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP)) fixstyle = TRUE;
 382+ if (exstyle & (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)) fixstyle = TRUE;
 383+ if (!((r1.left == 0) && (r1.top == 0) && (r2.right == sizes[4]) && (r2.bottom == sizes[5]))) fixstyle = TRUE;
 384+ if (fixstyle)
 385+ {
 386+ SetWindowLongPtrA(hWnd, GWL_EXSTYLE, exstyle & ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE));
 387+ SetWindowLongPtrA(hWnd, GWL_STYLE, winstyle & ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER | WS_POPUP));
 388+ SetWindowPos(hWnd, NULL, 0, 0, sizes[4], sizes[5], SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_FRAMECHANGED);
 389+ }
 390+ }
 391+ break;
372392 }
373393 }
374394 break;
Index: dxglcfg/dxglcfg.c
@@ -567,6 +567,8 @@
568568 SendDlgItemMessage(hWnd, IDC_FULLMODE, CB_ADDSTRING, 2, (LPARAM)buffer);
569569 _tcscpy(buffer, _T("Resizable window"));
570570 SendDlgItemMessage(hWnd, IDC_FULLMODE, CB_ADDSTRING, 3, (LPARAM)buffer);
 571+ _tcscpy(buffer, _T("Borderless window"));
 572+ SendDlgItemMessage(hWnd, IDC_FULLMODE, CB_ADDSTRING, 4, (LPARAM)buffer);
571573 SendDlgItemMessage(hWnd, IDC_FULLMODE, CB_SETCURSEL, cfg->fullmode, 0);
572574 // colormode
573575 if(cfg->colormode) SendDlgItemMessage(hWnd,IDC_COLOR,BM_SETCHECK,BST_CHECKED,0);