|
51 | 51 | #include "Common/GameMemory.h" |
52 | 52 | #include "Common/StackDump.h" |
53 | 53 | #include "Common/MessageStream.h" |
| 54 | +#include "Common/OptionPreferences.h" |
54 | 55 | #include "Common/Registry.h" |
55 | 56 | #include "Common/Team.h" |
56 | 57 | #include "GameClient/ClientInstance.h" |
| 58 | +#include "GameClient/Display.h" |
57 | 59 | #include "GameClient/InGameUI.h" |
58 | 60 | #include "GameClient/GameClient.h" |
59 | 61 | #include "GameLogic/GameLogic.h" ///< @todo for demo, remove |
@@ -655,6 +657,71 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, |
655 | 657 | break; |
656 | 658 | } |
657 | 659 | #endif |
| 660 | + case WM_SYSKEYDOWN: |
| 661 | + { |
| 662 | + if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter |
| 663 | + { |
| 664 | + if (TheGameEngine && !TheGameEngine->getQuitting() && TheDisplay) |
| 665 | + { |
| 666 | + TheWritableGlobalData->m_windowed = !TheGlobalData->m_windowed; |
| 667 | + |
| 668 | + // Determine desired client resolution |
| 669 | + Int resX = TheGlobalData->m_xResolution; |
| 670 | + Int resY = TheGlobalData->m_yResolution; |
| 671 | + |
| 672 | + // Update window style and calculate correct window size |
| 673 | + DWORD windowStyle = WS_POPUP | WS_VISIBLE; |
| 674 | + DWORD exStyle = 0; |
| 675 | + if (TheGlobalData->m_windowed) |
| 676 | + { |
| 677 | + // Standard windowed style with caption and fixed dialog border |
| 678 | + windowStyle |= WS_MINIMIZEBOX | WS_SYSMENU | WS_DLGFRAME | WS_CAPTION; |
| 679 | + } |
| 680 | + else |
| 681 | + { |
| 682 | + // Fullscreen style (borderless popup) |
| 683 | + windowStyle |= WS_SYSMENU; |
| 684 | + exStyle |= WS_EX_TOPMOST; |
| 685 | + } |
| 686 | + |
| 687 | + // Let Windows calculate the required window size for our desired client resolution |
| 688 | + RECT windowRect = { 0, 0, resX, resY }; |
| 689 | + AdjustWindowRect(&windowRect, windowStyle, FALSE); |
| 690 | + int width = windowRect.right - windowRect.left; |
| 691 | + int height = windowRect.bottom - windowRect.top; |
| 692 | + |
| 693 | + // Determine position (center it if windowed) |
| 694 | + int x = 0, y = 0; |
| 695 | + if (TheGlobalData->m_windowed) |
| 696 | + { |
| 697 | + x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; |
| 698 | + y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; |
| 699 | + if (x < 0) x = 0; |
| 700 | + if (y < 0) y = 0; |
| 701 | + } |
| 702 | + |
| 703 | + // Apply styles and size |
| 704 | + SetWindowLong(hWnd, GWL_STYLE, windowStyle); |
| 705 | + SetWindowLong(hWnd, GWL_EXSTYLE, exStyle); |
| 706 | + SetWindowPos(hWnd, TheGlobalData->m_windowed ? HWND_NOTOPMOST : HWND_TOPMOST, |
| 707 | + x, y, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW); |
| 708 | + |
| 709 | + // Toggle and save |
| 710 | + TheDisplay->setDisplayMode(resX, resY, 32, TheGlobalData->m_windowed); |
| 711 | + |
| 712 | + OptionPreferences optionPref; |
| 713 | + optionPref.setWindowed(TheGlobalData->m_windowed); |
| 714 | + optionPref.write(); |
| 715 | + |
| 716 | + // Re-apply refresh just in case reset messed it up |
| 717 | + SetWindowPos(hWnd, TheGlobalData->m_windowed ? HWND_NOTOPMOST : HWND_TOPMOST, |
| 718 | + x, y, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW); |
| 719 | + UpdateWindow(hWnd); |
| 720 | + } |
| 721 | + return 0; |
| 722 | + } |
| 723 | + break; |
| 724 | + } |
658 | 725 | } |
659 | 726 |
|
660 | 727 | } |
|
0 commit comments