Add fullscreen
This commit is contained in:
parent
bd8eda13aa
commit
9c78fe09c9
@ -1,5 +1,5 @@
|
|||||||
# NF library CMakeLists.txt
|
# NF library CMakeLists.txt
|
||||||
add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/EngineConfig.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp" "src/client/Client.h" "src/client/Client.cpp" "src/client/Window.h" "src/client/Window.cpp")
|
add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/config.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp" "src/client/Client.h" "src/client/Client.cpp" "src/client/Window.h" "src/client/Window.cpp")
|
||||||
|
|
||||||
# Use C++20
|
# Use C++20
|
||||||
set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20)
|
set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20)
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// NF startup
|
// NF startup
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
|
||||||
#include "nf/EngineConfig.h"
|
#include "nf/config.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
void runEngine(EngineConfig config) {
|
void runEngine(ClientConfig config) {
|
||||||
std::string engineStr = std::format("Nothin' Fancy {}", NFVERSION);
|
std::string engineStr = std::format("Nothin' Fancy {}", NFVERSION);
|
||||||
std::string gameStr = std::format("{} {}", config.appName, config.appVersion);
|
std::string gameStr = std::format("{} {}", config.appName, config.appVersion);
|
||||||
NFLog(engineStr);
|
NFLog(engineStr);
|
||||||
@ -18,9 +18,6 @@ namespace nf {
|
|||||||
SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str());
|
SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Disable automatic DPI upscaling
|
|
||||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
|
||||||
|
|
||||||
// Start client
|
// Start client
|
||||||
{
|
{
|
||||||
cli::Client client(config);
|
cli::Client client(config);
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
|
|
||||||
namespace nf::cli {
|
namespace nf::cli {
|
||||||
Client::Client(EngineConfig config)
|
Client::Client(ClientConfig config)
|
||||||
: m_currentConfig(config)
|
: m_config(config)
|
||||||
, m_window(1280, 720)
|
, m_window(m_config.display)
|
||||||
{
|
{
|
||||||
// Setup window and renderer
|
// Setup window and renderer
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
// NF Client class header
|
// NF Client class header
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "nf/EngineConfig.h"
|
#include "nf/config.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
namespace nf::cli {
|
namespace nf::cli {
|
||||||
class Client {
|
class Client {
|
||||||
public:
|
public:
|
||||||
Client(EngineConfig config);
|
Client(ClientConfig config);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
private:
|
private:
|
||||||
EngineConfig m_currentConfig;
|
ClientConfig m_config;
|
||||||
Window m_window;
|
Window m_window;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,18 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace nf::cli {
|
namespace nf::cli {
|
||||||
Window::Window(unsigned int width, unsigned int height)
|
Window::Window(DisplayConfig config)
|
||||||
: m_handle(nullptr)
|
: m_handle(nullptr)
|
||||||
, m_wndClassName("NothinFancyWindow")
|
, m_wndClassName("NothinFancyWindow")
|
||||||
, m_windowedStyle(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
|
, m_windowedStyle(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
|
||||||
, m_width(width)
|
, m_fullscreenStyle(WS_POPUP)
|
||||||
, m_height(height)
|
, m_config()
|
||||||
{
|
{
|
||||||
NFLog("Creating window");
|
NFLog("Creating window");
|
||||||
|
|
||||||
|
// Disable automatic DPI upscaling
|
||||||
|
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||||
|
|
||||||
// Register window class
|
// Register window class
|
||||||
WNDCLASS wc = {};
|
WNDCLASS wc = {};
|
||||||
wc.lpszClassName = m_wndClassName;
|
wc.lpszClassName = m_wndClassName;
|
||||||
@ -21,8 +24,46 @@ namespace nf::cli {
|
|||||||
wc.lpfnWndProc = wndProc;
|
wc.lpfnWndProc = wndProc;
|
||||||
RegisterClass(&wc);
|
RegisterClass(&wc);
|
||||||
|
|
||||||
m_handle = CreateWindow(m_wndClassName, "NF Window", m_windowedStyle, 0, 0, 0, 0, nullptr, nullptr, nullptr, this);
|
m_handle = CreateWindow(m_wndClassName, "NF Window", NULL, 0, 0, 0, 0, nullptr, nullptr, nullptr, this);
|
||||||
setSize();
|
setDisplay(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::setDisplay(DisplayConfig config) {
|
||||||
|
m_config = config;
|
||||||
|
bool wasShown = IsWindowVisible(m_handle);
|
||||||
|
show(false);
|
||||||
|
|
||||||
|
// Temporary monitor choice
|
||||||
|
POINT cursor = {};
|
||||||
|
GetCursorPos(&cursor);
|
||||||
|
MONITORINFO mi = {};
|
||||||
|
mi.cbSize = sizeof(mi);
|
||||||
|
GetMonitorInfo(MonitorFromPoint(cursor, MONITOR_DEFAULTTONEAREST), &mi);
|
||||||
|
int monitorX = mi.rcMonitor.left, monitorY = mi.rcMonitor.top;
|
||||||
|
int monitorWidth = mi.rcMonitor.right - monitorX, monitorHeight = mi.rcMonitor.bottom - monitorY;
|
||||||
|
int windowX = 0, windowY = 0;
|
||||||
|
unsigned int windowWidth = 0, windowHeight = 0;
|
||||||
|
|
||||||
|
switch (config.mode) {
|
||||||
|
case DisplayMode::Windowed: {
|
||||||
|
SetWindowLongPtr(m_handle, GWL_STYLE, m_windowedStyle);
|
||||||
|
windowX = monitorX + (monitorWidth / 2) - (m_config.width / 2), windowY = monitorY + (monitorHeight / 2) - (m_config.height / 2);
|
||||||
|
SIZE windowSize = getWindowSize();
|
||||||
|
windowWidth = windowSize.cx, windowHeight = windowSize.cy;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case DisplayMode::Fullscreen: {
|
||||||
|
SetWindowLongPtr(m_handle, GWL_STYLE, m_fullscreenStyle);
|
||||||
|
windowX = monitorX, windowY = monitorY;
|
||||||
|
windowWidth = monitorWidth, windowHeight = monitorHeight;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetWindowPos(m_handle, nullptr, windowX, windowY, windowWidth, windowHeight, SWP_NOZORDER | SWP_FRAMECHANGED);
|
||||||
|
|
||||||
|
show(wasShown);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::runLoop() {
|
void Window::runLoop() {
|
||||||
@ -42,24 +83,17 @@ namespace nf::cli {
|
|||||||
static Window* wnd = nullptr;
|
static Window* wnd = nullptr;
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_CREATE: {
|
case WM_CREATE:
|
||||||
wnd = reinterpret_cast<Window*>(reinterpret_cast<CREATESTRUCT*>(lParam)->lpCreateParams);
|
wnd = reinterpret_cast<Window*>(reinterpret_cast<CREATESTRUCT*>(lParam)->lpCreateParams);
|
||||||
|
|
||||||
// Temporary monitor choice
|
|
||||||
POINT cursor = {};
|
|
||||||
GetCursorPos(&cursor);
|
|
||||||
MONITORINFO mi = {};
|
|
||||||
mi.cbSize = sizeof(mi);
|
|
||||||
GetMonitorInfo(MonitorFromPoint(cursor, MONITOR_DEFAULTTONEAREST), &mi);
|
|
||||||
int monWidth = mi.rcMonitor.right - mi.rcMonitor.left, monHeight = mi.rcMonitor.bottom - mi.rcMonitor.top;
|
|
||||||
int x = mi.rcMonitor.left + (monWidth / 2) - (wnd->m_width / 2), y = mi.rcMonitor.top + (monHeight / 2) - (wnd->m_height / 2);
|
|
||||||
SetWindowPos(hWnd, nullptr, x , y , 0, 0, SWP_NOZORDER | SWP_NOSIZE);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
case WM_DPICHANGED: {
|
case WM_DPICHANGED: {
|
||||||
// Prevents resize on DPI change
|
// Prevents automatic window resize on DPI change (don't apply to fullscreen)
|
||||||
wnd->setSize();
|
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUP)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
SIZE windowSize = wnd->getWindowSize();
|
||||||
|
SetWindowPos(hWnd, nullptr, 0, 0, windowSize.cx, windowSize.cy, SWP_NOZORDER | SWP_NOMOVE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,12 +109,12 @@ namespace nf::cli {
|
|||||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setSize() {
|
SIZE Window::getWindowSize() {
|
||||||
RECT cli = {};
|
RECT cli = {};
|
||||||
cli.right = m_width;
|
cli.right = m_config.width;
|
||||||
cli.bottom = m_height;
|
cli.bottom = m_config.height;
|
||||||
AdjustWindowRectExForDpi(&cli, m_windowedStyle, FALSE, NULL, GetDpiForWindow(m_handle));
|
AdjustWindowRectExForDpi(&cli, m_windowedStyle, FALSE, NULL, GetDpiForWindow(m_handle));
|
||||||
unsigned int width = cli.right - cli.left, height = cli.bottom - cli.top;
|
int width = cli.right - cli.left, height = cli.bottom - cli.top;
|
||||||
SetWindowPos(m_handle, nullptr, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE);
|
return { width, height };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,28 @@
|
|||||||
// Window class header
|
// Window class header
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "nf/config.h"
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
namespace nf::cli {
|
namespace nf::cli {
|
||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
Window(unsigned int width, unsigned int height);
|
Window(DisplayConfig config);
|
||||||
|
|
||||||
|
void setDisplay(DisplayConfig config);
|
||||||
void runLoop();
|
void runLoop();
|
||||||
void show(bool show = true);
|
void show(bool show = true);
|
||||||
private:
|
private:
|
||||||
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
void setSize();
|
SIZE getWindowSize();
|
||||||
|
|
||||||
HWND m_handle;
|
HWND m_handle;
|
||||||
|
|
||||||
const char* m_wndClassName;
|
const char* m_wndClassName;
|
||||||
const DWORD m_windowedStyle;
|
const DWORD m_windowedStyle;
|
||||||
|
const DWORD m_fullscreenStyle;
|
||||||
|
|
||||||
unsigned int m_width, m_height;
|
DisplayConfig m_config;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// NF main public header
|
// NF main public header
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "nf/EngineConfig.h"
|
#include "nf/config.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
struct CommandLineArguments {
|
struct CommandLineArguments {
|
||||||
@ -9,16 +9,16 @@ namespace nf {
|
|||||||
char** argv;
|
char** argv;
|
||||||
};
|
};
|
||||||
|
|
||||||
EngineConfig configureEngine(CommandLineArguments cmdArgs);
|
ClientConfig configureEngine(CommandLineArguments cmdArgs);
|
||||||
|
|
||||||
void runEngine(EngineConfig config);
|
void runEngine(ClientConfig config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NF entry point
|
// NF entry point
|
||||||
#ifdef NFENTRY
|
#ifdef NFENTRY
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
nf::EngineConfig config = nf::configureEngine({ argc, argv });
|
nf::ClientConfig config = nf::configureEngine({ argc, argv });
|
||||||
|
|
||||||
nf::runEngine(config);
|
nf::runEngine(config);
|
||||||
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
// EngineConfig struct public header
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace nf {
|
|
||||||
struct EngineConfig {
|
|
||||||
const char* appName;
|
|
||||||
const char* appVersion;
|
|
||||||
|
|
||||||
EngineConfig()
|
|
||||||
: appName("Nothin' Fancy Game")
|
|
||||||
, appVersion("v0.1.0")
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
}
|
|
32
NothinFancy/src/include/nf/config.h
Normal file
32
NothinFancy/src/include/nf/config.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// EngineConfig struct public header
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace nf {
|
||||||
|
enum class DisplayMode {
|
||||||
|
Windowed,
|
||||||
|
Fullscreen
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DisplayConfig {
|
||||||
|
DisplayMode mode;
|
||||||
|
unsigned int width, height;
|
||||||
|
|
||||||
|
DisplayConfig()
|
||||||
|
: mode(DisplayMode::Windowed)
|
||||||
|
, width(1280)
|
||||||
|
, height(720)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ClientConfig {
|
||||||
|
const char* appName;
|
||||||
|
const char* appVersion;
|
||||||
|
DisplayConfig display;
|
||||||
|
|
||||||
|
ClientConfig()
|
||||||
|
: appName("Nothin' Fancy Game")
|
||||||
|
, appVersion("v0.1.0")
|
||||||
|
, display()
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
}
|
@ -3,8 +3,9 @@
|
|||||||
#include "nf.h"
|
#include "nf.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
EngineConfig configureEngine(CommandLineArguments cmdArgs) {
|
ClientConfig configureEngine(CommandLineArguments cmdArgs) {
|
||||||
EngineConfig config;
|
ClientConfig config;
|
||||||
|
//config.display.mode = DisplayMode::Fullscreen;
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user