Skip to content

Commit

Permalink
Implemented borderless windowed mode
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-fadely committed May 16, 2016
1 parent 5650406 commit d61f187
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -60,3 +60,4 @@ ipch/
*.vsp
*.vspx
*.opendb
*.db
50 changes: 39 additions & 11 deletions SA2ModLoader/dllmain.cpp
Expand Up @@ -9,13 +9,17 @@
#include <unordered_map>
#include <list>
#include <algorithm>
#include <thread>
#include <DbgHelp.h>
#include <Shlwapi.h>
#include "IniFile.hpp"
#include "SA2ModLoader.h"
#include "ModelInfo.h"
#include "CodeParser.hpp"
#include "Events.h"

static std::thread* window_thread = nullptr;

using namespace std;

// TODO: Split file replacement into separate file(s)
Expand Down Expand Up @@ -1148,20 +1152,37 @@ void __cdecl InitMods(void)

if (MainUserConfig->FullScreen == 0)
{
int endWidth = (int)HorizontalResolution;
int endHeight = (int)VerticalResolution;
RECT winFrame, winClient;
if (settings->getBool("BorderlessWindow", false))
{
window_thread = new thread([] {
SetWindowLong(MainWindowHandle, GWL_STYLE, WS_VISIBLE | WS_POPUP);

auto width = MainUserConfig->Width;
auto height = MainUserConfig->Height;

GetWindowRect(MainWindowHandle, &winFrame);
GetClientRect(MainWindowHandle, &winClient);
auto x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
auto y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;

SetWindowPos(MainWindowHandle, nullptr, x, y, width, height, SWP_FRAMECHANGED);
});
}
else
{
int endWidth = (int)HorizontalResolution;
int endHeight = (int)VerticalResolution;
RECT winFrame, winClient;

// The game uses GetSystemMetrics which appears to always report incorrect values,
// so this code calculates the window frame size manually.
endWidth += ((winFrame.right - winFrame.left) - (winClient.right - winClient.left));
endHeight += ((winFrame.bottom - winFrame.top) - (winClient.bottom - winClient.top));
GetWindowRect(MainWindowHandle, &winFrame);
GetClientRect(MainWindowHandle, &winClient);

SetWindowPos(MainWindowHandle, nullptr, 0, 0, endWidth, endHeight,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_ASYNCWINDOWPOS);
// The game uses GetSystemMetrics which appears to always report incorrect values,
// so this code calculates the window frame size manually.
endWidth += ((winFrame.right - winFrame.left) - (winClient.right - winClient.left));
endHeight += ((winFrame.bottom - winFrame.top) - (winClient.bottom - winClient.top));

SetWindowPos(MainWindowHandle, nullptr, 0, 0, endWidth, endHeight,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_ASYNCWINDOWPOS);
}
}
}

Expand All @@ -1186,7 +1207,14 @@ BOOL APIENTRY DllMain( HMODULE hModule,
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;

case DLL_PROCESS_DETACH:
if (window_thread)
{
window_thread->join();
delete window_thread;
}
break;
}
return TRUE;
Expand Down
1 change: 1 addition & 0 deletions SA2ModLoader/stdafx.h
Expand Up @@ -25,6 +25,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include <thread>

#include "ninja.h"
#include "SA2ModLoader.h"
Expand Down
107 changes: 60 additions & 47 deletions SA2ModManager/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions SA2ModManager/MainForm.cs
Expand Up @@ -82,6 +82,7 @@ private void MainForm_Load(object sender, EventArgs e)
consoleCheckBox.Checked = loaderini.DebugConsole;
fileCheckBox.Checked = loaderini.DebugFile;
pauseWhenInactiveCheckBox.Checked = loaderini.PauseWhenInactive;
borderlessWindowCheckBox.Checked = loaderini.BorderlessWindow;
if (!File.Exists(datadllpath))
{
MessageBox.Show(this, "Data_DLL.dll could not be found.\n\nCannot determine state of installation.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
Expand Down Expand Up @@ -175,7 +176,9 @@ private void Save()
loaderini.DebugConsole = consoleCheckBox.Checked;
loaderini.DebugFile = fileCheckBox.Checked;
loaderini.PauseWhenInactive = pauseWhenInactiveCheckBox.Checked;
loaderini.BorderlessWindow = borderlessWindowCheckBox.Checked;
IniFile.Serialize(loaderini, loaderinipath);
// TODO: hides field MainForm.codes
List<Code> codes = new List<Code>();
List<Code> patches = new List<Code>();
foreach (Code item in codesCheckedListBox.CheckedIndices.OfType<int>().Select(a => this.codes[a]))
Expand Down Expand Up @@ -433,6 +436,8 @@ class LoaderInfo
public bool? ShowConsole { get { return null; } set { if (value.HasValue) DebugConsole = value.Value; } }
[DefaultValue(true)]
public bool PauseWhenInactive { get; set; }
[DefaultValue(false)]
public bool BorderlessWindow { get; set; }
[IniName("Mod")]
[IniCollection(IniCollectionMode.NoSquareBrackets, StartIndex = 1)]
public List<string> Mods { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions SA2ModManager/MainForm.resx
Expand Up @@ -112,15 +112,15 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="groupBox2.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="groupBox2.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAYAEBAAAAEAIABoBAAAZgAAABgYAAABACAAiAkAAM4EAAAgIAAAAQAgAKgQAABWDgAAMDAAAAEA
Expand Down

0 comments on commit d61f187

Please sign in to comment.