Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_graphical_application.hpp
1#pragma once
2
3#include <Windows.h>
4#include <atomic>
5#include <thread>
6
7#include "structure/opengl/spk_wgl_context.hpp"
8#include "structure/widget/spk_widget.hpp"
9#include "structure/win32/spk_class.hpp"
10#include "structure/win32/spk_window.hpp"
11#include "type/spk_enablement.hpp"
12
13#include "structure/application/module/spk_keyboard_module.hpp"
14#include "structure/application/module/spk_mouse_module.hpp"
15#include "structure/application/module/spk_paint_module.hpp"
16#include "structure/application/module/spk_system_module.hpp"
17#include "structure/application/module/spk_update_module.hpp"
18
19#include "utils/spk_event_utils.hpp"
20
21namespace spk
22{
23 namespace Module
24 {
25 class SystemModule;
26 }
27
40 {
41 public:
47 {
51 Enablement multithread = Enablement::Enable;
52 };
53
54 private:
55 friend class Module::SystemModule;
56
65 static LRESULT CALLBACK _windowProc(HWND p_hwnd, UINT p_uMsg, WPARAM p_wParam, LPARAM p_lParam);
66
67 Win32::Class _class;
68 spk::Widget _centralWidget;
69
70 Module::SystemModule _systemModule;
71 Module::PaintModule _paintModule;
72 Module::UpdateModule _updateModule;
73 Module::MouseModule _mouseModule;
74 Module::KeyboardModule _keyboardModule;
75
76 Win32::Window _window;
77 OpenGL::WglContext _wglContext;
78
79 Configuration _configuration;
80
81 std::atomic<bool> _running{false};
82 std::atomic<int> _exitCode{0};
83 std::atomic<bool> _quitMessagePosted{false};
84
85 std::jthread _updateThread;
86 std::jthread _renderThread;
87
92 bool _treatEvent(HWND p_hwnd, UINT p_uMsg, WPARAM p_wParam, LPARAM p_lParam);
93
97 void _pullEvents();
101 void _bindCentralWidget();
106 void _generateResizeEvent(const spk::Extend2D &p_extend);
111 void _resize(const spk::Extend2D &p_extend);
112
116 void _prepareRenderLoopThread();
120 void _renderLoopStep();
121
125 void _prepareUpdateLoopThread();
129 void _updateLoopStep();
130
134 void _prepareMainLoopThread();
138 void _mainLoopStep();
139
140 public:
147 GraphicalApplication(const std::wstring &p_title, const spk::Extend2D &p_extend2D, const Configuration &p_configuration);
153 GraphicalApplication(const std::wstring &p_title, const spk::Extend2D &p_extend2D);
154
159 int run();
160
165 spk::Widget &centralWidget();
170 const spk::Widget &centralWidget() const;
171
176 void quit(int p_errorID = 0);
177 };
178}
GraphicalApplication(const std::wstring &p_title, const spk::Extend2D &p_extend2D, const Configuration &p_configuration)
Builds an application with explicit configuration.
Definition spk_graphical_application.cpp:154
spk::Widget & centralWidget()
Accesses the central widget.
Definition spk_graphical_application.cpp:223
int run()
Starts the event, update, and render loops.
Definition spk_graphical_application.cpp:173
void quit(int p_errorID=0)
Requests application shutdown.
Definition spk_graphical_application.cpp:233
Dispatches keyboard events to a bound widget and tracks keyboard state.
Definition spk_keyboard_module.hpp:23
Dispatches mouse events to a bound widget and tracks mouse state.
Definition spk_mouse_module.hpp:23
Forwards paint events to the bound widget.
Definition spk_paint_module.hpp:17
Handles system-level events (creation, resize, quit) for the application and its widget tree.
Definition spk_system_module.hpp:18
Forwards update ticks to the bound widget.
Definition spk_update_module.hpp:17
Manages a Windows WGL OpenGL context tied to a window.
Definition spk_wgl_context.hpp:17
Base class for interactive UI elements handling focus and events.
Definition spk_widget.hpp:52
Registers a Win32 window class and instantiates windows from it.
Definition spk_class.hpp:24
RAII wrapper over a Win32 HWND handle created by spk::Win32::Class.
Definition spk_window.hpp:20
Runtime options affecting threading.
Definition spk_graphical_application.hpp:47
Enablement multithread
Enables or disables multithreaded loops.
Definition spk_graphical_application.hpp:51