-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_Window.cpp
145 lines (114 loc) · 7.03 KB
/
Main_Window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Main Window
#include "stdafx.h"
#include <sstream>
#include <string>
#include <vector>
#include <windows.h>
#include "Character2D.h"
#include "Debug.h"
#include "Graphics_Info.h"
#include "Keyboard.h"
#include "Krampus_Game_Engine.h"
#include "Photon.h"
#include "Timing.h"
#include "Bitmap.h"
#define MAX_LOADSTRING 100
Graphics_Info graphics;
bool fullscreen = false;
bool Exit = false;
HWND Window;
WCHAR szTitle[MAX_LOADSTRING];
WCHAR szWindowClass[MAX_LOADSTRING];
Krampus_Game_Engine game_engine (graphics.window_width, graphics.window_height);
// Prototypes
void graphics_settings ();
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void set_to_fullscreen ();
void graphics_settings ()
{
graphics.game_view_width = 396;
graphics.game_view_height = 224;
graphics.pixel_scale = 2;
graphics.calculate_scale_and_window_size ();
}
int APIENTRY wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER (hPrevInstance);
UNREFERENCED_PARAMETER (lpCmdLine);
// Initialize global strings
LoadStringW (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW (hInstance, IDC_PHOTON, szWindowClass, MAX_LOADSTRING);
MyRegisterClass (hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators (hInstance, MAKEINTRESOURCE (IDC_PHOTON));
MSG msg;
game_engine.Init (Window, graphics);
// Main message loop:
while (!Exit)
{
while (PeekMessage (&msg, nullptr, 0, 0, PM_REMOVE))
{
DispatchMessage (&msg);
}
game_engine.Main_Loop ();
if (game_engine.menu.exit) Exit = true;
}
return TRUE;
}
// Registers the window class.
ATOM MyRegisterClass (HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof (WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_PHOTON));
wcex.hCursor = LoadCursor (nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCEW (IDC_PHOTON);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon (wcex.hInstance, MAKEINTRESOURCE (IDI_SMALL));
return RegisterClassExW (&wcex);
}
BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
{
graphics_settings ();
Window = CreateWindowW (szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, graphics.window_width, graphics.window_height, nullptr, nullptr, hInstance, nullptr);
if (!Window) return FALSE;
SetMenu (Window, NULL);
ShowWindow (Window, nCmdShow);
UpdateWindow (Window);
if (fullscreen) set_to_fullscreen ();
graphics.get_client_window_size (Window);
return TRUE;
}
// Processes messages for the main window.
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
Exit = true;
PostQuitMessage (0);
break;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
return 0;
}
void set_to_fullscreen ()
{
HDC hdc = GetDC (Window);
//SetWindowPos (Window, NULL, 0, 0, 600, 600, NULL);
// TODO: finish later
}