sculpto
windows_msg_crackers.cpp
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file windows_msg_crackers.cpp
3 * \brief Window class message crackers realisation module.
4 *
5 * \author Sabitov Kirill
6 * \date 18 June 2022
7 *********************************************************************/
8
9#include "sclpch.h"
10#include "windows_window.h"
11
12bool scl::windows_window::OnCreate(window_handle WindowHandle, CREATESTRUCT *CS)
13{
14 // Set window window_handle to newly created window
15 Handle = WindowHandle;
16 reinterpret_cast<windows_input_system *>(input_system::Get().get())->Init(&Handle, &MouseWheel);
17
18 SetTimer(Handle, InitialisationTimer, 0, nullptr);
19 return 1;
20}
21
22void scl::windows_window::OnSize(window_handle WindowHandle, u32 State, int W, int H)
23{
24 // Set current window sizing
25 Data.Width = W;
26 Data.Height = H;
27
28 if (!IsInitialised) return;
29
30 // Call resize callback
31 viewport_resize_event e { W, H, window::ViewportId };
33}
34
35bool scl::windows_window::OnClose(window_handle WindowHandle)
36{
37 DestroyWindow(Handle);
38 return 0;
39}
40
41void scl::windows_window::OnDestroy(window_handle WindowHandle)
42{
43 if (IsInitialised)
44 {
45 close_event e {};
47 }
48
49 PostQuitMessage(30);
50}
51
52void scl::windows_window::OnTimer(window_handle WindowHandle, UINT id)
53{
54 if (IsInitialised) return;
55
56 IsInitialised = true;
57 KillTimer(Handle, InitialisationTimer);
58
59 // Call resize callback
60 viewport_resize_event e { Data.Width, Data.Height, window::ViewportId };
62}
63
64bool scl::windows_window::OnEraseBackground(window_handle WindowHandle, HDC hDC)
65{
66 return true;
67}
68
69void scl::windows_window::OnPaint(window_handle WindowHandle)
70{
71 PAINTSTRUCT ps;
72 HDC hDC;
73
74 hDC = BeginPaint(WindowHandle, &ps);
75 EndPaint(WindowHandle, &ps);
76}
77
78void scl::windows_window::OnActivate(window_handle WindowHandle, u32 Reason, HWND hWndActDeact, bool IsMinimized)
79{
80}
81
82void scl::windows_window::OnMMove(HWND hwnd, int x, int y, u32 keyFlags)
83{
84 if (!IsInitialised) return;
85
86 mouse_move_event e { x, y,
87 (bool)(keyFlags & MK_RBUTTON), (bool)(keyFlags & MK_LBUTTON), (bool)(keyFlags & MK_MBUTTON),
88 (bool)(keyFlags & MK_SHIFT), (bool)(keyFlags & MK_CONTROL)
89 };
91}
92
93void scl::windows_window::OnMWheel(window_handle WindowHandle, int X, int Y, int Z, u32 Keys)
94{
95 if (!IsInitialised) return;
96
97 this->MouseWheel += Z;
99
100 mouse_wheel_event e { Z };
102}
103
104void scl::windows_window::OnMButDown(window_handle WindowHandle, bool IsDblClick, int X, int Y, u32 Keys)
105{
106 if (!IsInitialised) return;
107
108 mouse_button_event e { true, X, Y, (mouse_button)Keys };
110}
111
112void scl::windows_window::OnMButUp(window_handle WindowHandle, int X, int Y, u32 Keys)
113{
114 if (!IsInitialised) return;
115
116 mouse_button_event e { false, X, Y, (mouse_button)Keys };
118}
119
120void scl::windows_window::OnKey(HWND hwnd, u32 vk, bool fDown, int cRepeat, u32 flags)
121{
122 if (!IsInitialised) return;
123
124 keyboard_event e { (bool)fDown, (bool)(flags & (1 << 14)), (keycode)vk};
126}
static void Invoke(Tevent &Event)
static shared< input_system > & Get()
Definition: input.h:99
static void Response()
Definition: input.h:90
window_handle Handle
Definition: window.h:41
static const int ViewportId
Definition: window.h:38
mouse_button
Definition: mouse_event.h:16
uint32_t u32
Definition: math_common.h:21
int window_handle
Definition: base.h:55
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.