Window Procedure work and Alt-Enter fullscreen toggle
This commit is contained in:
parent
5777478858
commit
8e4ed26755
60
Game/Game.rc
60
Game/Game.rc
@ -1,60 +0,0 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE 9, 1
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (United States) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
@ -166,12 +166,6 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Game.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Game.rc" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -19,14 +19,4 @@
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Game.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,14 +0,0 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by Game.rc
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
@ -4,11 +4,15 @@ using namespace nf;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
//TODO: Argument parser
|
||||
|
||||
Config conf = { 1280, 720, false, "Test"};
|
||||
Application app(conf);
|
||||
|
||||
//app.setWindowIcon(...);
|
||||
// app.setWindowCursor(...);
|
||||
//Create game states, load some assets, launch loop that continually updates and renders the current state and switches states when appropriate.
|
||||
//Show window
|
||||
app.showWindow(true);
|
||||
app.startLoop();
|
||||
|
||||
return 0;
|
||||
}
|
@ -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