Window Procedure work and Alt-Enter fullscreen toggle
This commit is contained in:
1 parent
5777478858
commit
8e4ed26755
8 files changed
+71
-101
No files matched your search
@@ -1,14 +1,13 @@
|
||||
#include "Application.h"
|
||||
#include "Utility.h"
|
||||
#include <iostream>
|
||||
//TODO: delete this
|
||||
|
||||
namespace nf {
|
||||
DEBUGINIT;
|
||||
|
||||
Application::Application(Config& config) :
|
||||
m_currentConfig(config),
|
||||
m_wndPlacement{ sizeof(m_wndPlacement) }
|
||||
m_wndPlacement{ sizeof(m_wndPlacement) },
|
||||
m_running(false)
|
||||
{
|
||||
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);
|
||||
@@ -18,12 +17,32 @@ namespace nf {
|
||||
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);
|
||||
SetProp(m_window, L"App", this);
|
||||
if(m_currentConfig.fullscreen) toggleFullscreen();
|
||||
showWindow(true);
|
||||
}
|
||||
|
||||
Config& Application::getConfig() {
|
||||
return m_currentConfig;
|
||||
void Application::setWindowIcon(HANDLE hIcon) {
|
||||
SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
|
||||
SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
|
||||
}
|
||||
|
||||
void Application::setWindowCursor(HCURSOR hCursor) {
|
||||
SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor);
|
||||
}
|
||||
|
||||
void Application::startLoop() {
|
||||
m_running = true;
|
||||
MSG msg = { };
|
||||
while (m_running) {
|
||||
//TODO: FPS and delta timing
|
||||
while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
if (msg.message == WM_QUIT)
|
||||
m_running = false;
|
||||
}
|
||||
//TODO: Update and render current state
|
||||
}
|
||||
}
|
||||
|
||||
void Application::showWindow(bool show) {
|
||||
@@ -33,11 +52,16 @@ namespace nf {
|
||||
ShowWindow(m_window, SW_HIDE);
|
||||
}
|
||||
|
||||
Config& Application::getConfig() {
|
||||
return m_currentConfig;
|
||||
}
|
||||
|
||||
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.hCursor = NULL;
|
||||
wclass.hIcon = NULL;
|
||||
wclass.hInstance = m_hInst;
|
||||
wclass.lpfnWndProc = Application::WindowProc;
|
||||
RegisterClass(&wclass);
|
||||
@@ -72,8 +96,32 @@ namespace nf {
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
Application* app = (Application*)GetProp(hWnd, L"App");
|
||||
switch (uMsg) {
|
||||
|
||||
case WM_CREATE: {
|
||||
|
||||
return 0;
|
||||
}
|
||||
case WM_SYSKEYDOWN: {
|
||||
if (GetKeyState(VK_RETURN) & 0x8000) {
|
||||
app->toggleFullscreen();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_MENUCHAR: {
|
||||
return MNC_CLOSE << 16;
|
||||
}
|
||||
case WM_CLOSE: {
|
||||
//State onExit() in order
|
||||
//unload anything else
|
||||
DestroyWindow(hWnd);
|
||||
return 0;
|
||||
}
|
||||
case WM_DESTROY: {
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);//TODO: Fill out events
|
||||
}
|
||||
|
||||
@@ -9,8 +9,11 @@ namespace nf {
|
||||
Application() = delete;
|
||||
Application(Application& other) = delete;
|
||||
|
||||
Config& getConfig();
|
||||
void setWindowIcon(HANDLE hIcon);
|
||||
void setWindowCursor(HCURSOR hCursor);
|
||||
void startLoop();
|
||||
void showWindow(bool show);
|
||||
Config& getConfig();
|
||||
|
||||
~Application();
|
||||
private:
|
||||
@@ -21,6 +24,7 @@ namespace nf {
|
||||
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
Config m_currentConfig;
|
||||
bool m_running;
|
||||
HINSTANCE m_hInst;
|
||||
LPCWSTR m_wclassName;
|
||||
HWND m_window;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
@@ -7,9 +8,12 @@ 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 SleepS(x) std::this_thread::sleep_for(std::chrono::seconds(x))
|
||||
#define SleepMS(x) std::this_thread::sleep_for(std::chrono::milliseconds(x))
|
||||
#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;
|
||||
|
||||
Reference in new issue
Block a user