Elevate Engine 1
Loading...
Searching...
No Matches
WebWindow.cpp
Go to the documentation of this file.
1#include "WebWindow.h"
2
3#ifdef EE_PLATFORM_WEB
5#include <emscripten/html5.h>
6
7namespace Elevate
8{
9 WebWindow::WebWindow(const WindowProps& props)
10 {
11 Init(props);
12 }
13
14 void WebWindow::GetCanvasSize(unsigned int& width, unsigned int& height)
15 {
16 double w, h;
17 emscripten_get_element_css_size("#canvas", &w, &h);
18 width = static_cast<unsigned int>(w);
19 height = static_cast<unsigned int>(h);
20 }
21
22 void WebWindow::Init(const WindowProps& props)
23 {
24 // Create the window with the size of the canvas element in the HTML page
25 unsigned int width, height;
26 GetCanvasSize(width, height);
27 WindowProps webProps(props.Title, width, height, props.VSync);
28 EE_CORE_INFO("Initializing WebWindow with canvas size: {}x{}", width, height);
29 GlfwWindow::Init(webProps);
30
31 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, EM_TRUE,
32 [](int et, const EmscriptenUiEvent* uiEvent, void* ud) -> EM_BOOL {
33 WebWindow* window = static_cast<WebWindow*>(ud);
34 unsigned int width = 0;
35 unsigned int height = 0;
36 window->GetCanvasSize(width, height);
37 window->SetWindowSize(width, height);
38
39 GLFWwindow* nativeWin = static_cast<GLFWwindow*>(window->GetNativeWindow());
40 glfwSetWindowSize(nativeWin, width, height);
41
42 return EM_TRUE;
43 });
44 }
45}
46
47#endif
virtual void Init(const WindowProps &props) override