Elevate Engine 1
Loading...
Searching...
No Matches
Window.cpp
Go to the documentation of this file.
1#include "Window.h"
2
5
6#include <rapidjson/document.h>
7#include <rapidjson/allocators.h>
8#include <rapidjson/filereadstream.h>
9#include <rapidjson/encodings.h>
10#include <rapidjson/rapidjson.h>
11
12#if defined(EE_PLATFORM_WINDOWS)
14#elif defined(EE_PLATFORM_WEB)
16#elif defined(EE_PLATFORM_LINUX)
18#else
19 #error "Unknown platform! Cannot create window on this platform."
20#endif
21
22namespace Elevate
23{
24#if defined(EE_PLATFORM_WINDOWS)
25 using PlatformWindow = WindowsWindow;
26#elif defined(EE_PLATFORM_WEB)
27 using PlatformWindow = WebWindow;
28#elif defined(EE_PLATFORM_LINUX)
29 using PlatformWindow = LinuxWindow;
30#else
31 #error "Unknown platform! Cannot create window on this platform."
32#endif
33
34 WindowProps::WindowProps(const std::string appConfigFilePath)
35 {
36 // TODO put this part in a util somehwerre to get the document
38 FILE* fp = fopen(appConfigFilePath.c_str(), "r");
39 char readBuffer[65536];
40 rapidjson::FileReadStream is(fp, readBuffer,
41 sizeof(readBuffer));
42 rapidjson::Document doc;
43 doc.ParseStream(is);
44 fclose(fp);
45
46 // Error handling
47 if (doc.HasParseError())
48 {
49 EE_CORE_TRACE("ERROR PARSING The WindowProps JSON");
50 }
52
53 if (doc.HasMember("title") && doc["title"].IsString())
54 {
55 this->Title = doc["title"].GetString();
56 }
57
58 if (doc.HasMember("size"))
59 {
60 const rapidjson::Value& size = doc["size"];
61 if (size.HasMember("x") && size["x"].IsInt())
62 {
63 this->Width = size["x"].GetInt();
64 }
65 if (size.HasMember("y") && size["y"].IsInt())
66 {
67 this->Height = size["y"].GetInt();
68 }
69 }
70
71 if (doc.HasMember("vsync") && doc["vsync"].IsBool())
72 {
73 this->VSync = doc["vsync"].GetBool();
74 }
75 }
76
78 {
79 return new PlatformWindow(props);
80 }
81
82 void Window::Init(const WindowProps& props)
83 {
84 m_Data.Title = props.Title;
85 m_Data.Width = props.Width;
86 m_Data.Height = props.Height;
87 EE_CORE_TRACE("Creating window: {} ({}x{})", props.Title.c_str(), props.Width, props.Height);
88 }
89
90 void Window::SetWindowSize(unsigned int width, unsigned int height)
91 {
92 EE_CORE_INFO("Setting window size to {}x{}", width, height);
93 m_Data.Width = width;
94 m_Data.Height = height;
95 WindowResizeEvent event(width, height);
96 EventCallback(event);
97 }
98}
WindowData m_Data
Definition Window.h:68
void EventCallback(Event &event)
Definition Window.h:65
virtual void Init(const WindowProps &props)
Definition Window.cpp:82
void SetWindowSize(unsigned int width, unsigned int height)
Definition Window.cpp:90
static Window * Create(const WindowProps &props=WindowProps("app.config"))
Definition Window.cpp:77
unsigned int Width
Definition Window.h:14
unsigned int Height
Definition Window.h:14
std::string Title
Definition Window.h:13
unsigned int Height
Definition Window.h:25
unsigned int Width
Definition Window.h:24
std::string Title
Definition Window.h:23