Finished debug logger for now; Started work on the main window and fullscreen functionality
This commit is contained in:
parent
41d043726c
commit
5777478858
@ -121,6 +121,7 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -154,6 +155,7 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
@ -4,9 +4,11 @@ using namespace nf;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
Config conf = { 1280, 720, false };
|
||||
Config conf = { 1280, 720, false, "Test"};
|
||||
Application app(conf);
|
||||
|
||||
//Create game states, load some assets, launch loop that continually updates and renders the current state and switches states when appropriate.
|
||||
//Show window
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,13 +1,84 @@
|
||||
#include "Application.h"
|
||||
#include "Utility.h"
|
||||
#include <iostream>
|
||||
//TODO: delete this
|
||||
|
||||
namespace nf {
|
||||
DEBUGINIT;
|
||||
|
||||
Application::Application(Config& config) :
|
||||
m_currentConfig(config)
|
||||
m_currentConfig(config),
|
||||
m_wndPlacement{ sizeof(m_wndPlacement) }
|
||||
{
|
||||
std::cin.get();
|
||||
Log("Creating NF application");
|
||||
Log("Width: " + std::to_string(m_currentConfig.width) + ", Height: " + std::to_string(m_currentConfig.height) + ", Fullscreen: " + std::to_string(m_currentConfig.fullscreen) + ", Title: " + m_currentConfig.title);
|
||||
|
||||
m_hInst = GetModuleHandle(NULL);
|
||||
registerWindowClass();
|
||||
RECT windowSize = getWindowRect();
|
||||
|
||||
m_window = CreateWindowEx(NULL, m_wclassName, toWide(m_currentConfig.title), WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 1280, windowSize.bottom, NULL, NULL, m_hInst, NULL);
|
||||
if(m_currentConfig.fullscreen) toggleFullscreen();
|
||||
showWindow(true);
|
||||
}
|
||||
}
|
||||
|
||||
Config& Application::getConfig() {
|
||||
return m_currentConfig;
|
||||
}
|
||||
|
||||
void Application::showWindow(bool show) {
|
||||
if (show)
|
||||
ShowWindow(m_window, SW_SHOW);
|
||||
else
|
||||
ShowWindow(m_window, SW_HIDE);
|
||||
}
|
||||
|
||||
void Application::registerWindowClass() {
|
||||
m_wclassName = L"NFClass";
|
||||
WNDCLASS wclass = { };
|
||||
wclass.lpszClassName = m_wclassName;
|
||||
//TODO: Add custom cursor and window icon at request of frontend using future resource format
|
||||
wclass.hInstance = m_hInst;
|
||||
wclass.lpfnWndProc = Application::WindowProc;
|
||||
RegisterClass(&wclass);
|
||||
}
|
||||
|
||||
void Application::toggleFullscreen() {
|
||||
DWORD wndStyle = GetWindowLong(m_window, GWL_STYLE);
|
||||
if (wndStyle & WS_OVERLAPPEDWINDOW) {
|
||||
GetWindowPlacement(m_window, &m_wndPlacement);
|
||||
MONITORINFO mi = { sizeof(mi) };
|
||||
GetMonitorInfo(MonitorFromWindow(m_window, MONITOR_DEFAULTTOPRIMARY), &mi);
|
||||
SetWindowLong(m_window, GWL_STYLE, wndStyle & ~WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(m_window, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
}
|
||||
else {
|
||||
SetWindowLong(m_window, GWL_STYLE, wndStyle | WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPlacement(m_window, &m_wndPlacement);
|
||||
SetWindowPos(m_window, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
RECT Application::getWindowRect() {
|
||||
int w = m_currentConfig.width;
|
||||
int h = m_currentConfig.height;
|
||||
RECT temp = { };
|
||||
temp.right = w;
|
||||
temp.bottom = h;
|
||||
AdjustWindowRect(&temp, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, false);
|
||||
temp.right -= temp.left;
|
||||
temp.bottom -= temp.top;
|
||||
return temp;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
switch (uMsg) {
|
||||
|
||||
}
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);//TODO: Fill out events
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,40 @@
|
||||
//TODO: Debug logger
|
||||
//TODO: Argument parser
|
||||
//TODO: Resource pack reader
|
||||
//TODO: File IO functions
|
||||
#include "Utility.h"
|
||||
#include "Config.h"
|
||||
#include <Windows.h>
|
||||
|
||||
namespace nf {
|
||||
#ifdef _DEBUG
|
||||
void Debug::LogImp(const char* in) {
|
||||
std::chrono::duration<float> time = getCurrentTime();
|
||||
std::printf("[%.4f] Debug: %s\n", time.count(), in);
|
||||
}
|
||||
|
||||
void Debug::LogImp(const std::string& in) {
|
||||
std::chrono::duration<float> time = getCurrentTime();
|
||||
std::printf("[%.4f] Debug: %s\n", time.count(), in.c_str());
|
||||
}
|
||||
|
||||
void Debug::ErrorImp(const char* in, const char* filename, int line) {
|
||||
std::chrono::duration<float> time = getCurrentTime();
|
||||
HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(cmd, FOREGROUND_RED);
|
||||
std::printf("[%.4f] Error (%s, %i): %s\n", time.count(), filename, line, in);
|
||||
SetConsoleTextAttribute(cmd, 7);
|
||||
CloseHandle(cmd);
|
||||
}
|
||||
|
||||
std::chrono::duration<float> Debug::getCurrentTime() {
|
||||
std::chrono::steady_clock::time_point now = std::chrono::high_resolution_clock::now();
|
||||
return now - m_initTime;
|
||||
}
|
||||
#endif
|
||||
|
||||
const wchar_t* toWide(const char* in) {
|
||||
int length = std::strlen(in) + 1;
|
||||
wchar_t* out = new wchar_t[length];
|
||||
MultiByteToWideChar(CP_ACP, NULL, in, -1, out, length);
|
||||
return out;
|
||||
}
|
||||
}
|
@ -8,7 +8,22 @@ namespace nf {
|
||||
Application(Config& conf);
|
||||
Application() = delete;
|
||||
Application(Application& other) = delete;
|
||||
|
||||
Config& getConfig();
|
||||
void showWindow(bool show);
|
||||
|
||||
~Application();
|
||||
private:
|
||||
void registerWindowClass();
|
||||
void toggleFullscreen();
|
||||
RECT getWindowRect();
|
||||
|
||||
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
Config m_currentConfig;
|
||||
HINSTANCE m_hInst;
|
||||
LPCWSTR m_wclassName;
|
||||
HWND m_window;
|
||||
WINDOWPLACEMENT m_wndPlacement;
|
||||
};
|
||||
}
|
@ -3,8 +3,9 @@
|
||||
namespace nf {
|
||||
struct Config {
|
||||
public:
|
||||
int m_width;
|
||||
int m_height;
|
||||
bool m_fullscreen;
|
||||
int width;
|
||||
int height;
|
||||
bool fullscreen;
|
||||
const char* title;
|
||||
};
|
||||
}
|
@ -1,28 +1,29 @@
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace nf {
|
||||
#ifdef _DEBUG
|
||||
#define __FILENAME__ strrchr(__FILE__, '\\') + 1
|
||||
#define DEBUGINIT std::chrono::steady_clock::time_point Debug::m_initTime = std::chrono::high_resolution_clock::now();
|
||||
#define Log(x) Debug::LogImp(x) s
|
||||
#define Log(x) Debug::LogImp(x)
|
||||
#define Error(x) Debug::ErrorImp(x,__FILENAME__, __LINE__);\
|
||||
DebugBreak();
|
||||
|
||||
class Debug {
|
||||
private:
|
||||
static std::chrono::steady_clock::time_point m_initTime;
|
||||
static std::chrono::duration<float> getCurrentTime();
|
||||
public:
|
||||
static void LogImp(char* in);
|
||||
static void LogImp(std::string& in);
|
||||
static void ErrorImp(char* in, char* filename, int line);
|
||||
static void LogImp(const char* in);
|
||||
static void LogImp(const std::string& in);
|
||||
static void ErrorImp(const char* in, const char* filename, int line);
|
||||
};
|
||||
|
||||
#else
|
||||
#define DEBUGINIT
|
||||
#define Log(x)
|
||||
#define Error(x)
|
||||
#endif
|
||||
|
||||
const wchar_t* toWide(const char* in);
|
||||
}
|
Reference in New Issue
Block a user