Elevate Engine 1
Loading...
Searching...
No Matches
Window.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <functional>
5
6namespace Elevate {
7 class Event;
8
9 using EventCallbackFn = std::function<void(Event&)>;
10
12 {
13 std::string Title;
14 unsigned int Width, Height;
15 bool Focused;
16 bool VSync;
17
19 };
20
22 {
23 std::string Title;
24 unsigned int Width;
25 unsigned int Height;
26 bool VSync;
27
28 WindowProps () : Title("ElevateEngine Dev"), Width(1280), Height(720), VSync(false) { }
29
30 WindowProps(const std::string& title, unsigned int width, unsigned int height, bool vsync)
31 : Title(title), Width(width), Height(height), VSync(vsync) { }
32
33 // To get all the revelant data from a .config file written in json
34 WindowProps(const std::string appConfigFilePath);
35 };
36
37 class Window
38 {
39 public:
40 Window() = default;
41 virtual ~Window() { }
42
43 virtual void Init(const WindowProps& props);
44 virtual void OnUpdate() = 0;
45
46 virtual unsigned int GetWidth() const = 0;
47 virtual unsigned int GetHeight() const = 0;
48 virtual bool GetFocus() const = 0;
49
50 // Window attributes
51 virtual void SetEventCallback(const EventCallbackFn& callback) = 0;
52 virtual void SetVSync(bool enabled) = 0;
53 virtual bool IsVSync() const = 0;
54
55 // todo let the user create this file
56 static Window* Create(const WindowProps& props = WindowProps("app.config"));
57
58 virtual double GetTime() const = 0;
59
60 virtual void* GetNativeWindow() const = 0; // Ex: Get the GLFW window on Windows
61
62 const WindowData& GetWindowData() const { return m_Data; }
63
64 void SetWindowSize(unsigned int width, unsigned int height);
65 void EventCallback(Event& event) { m_Data.EventCallback(event); }
66
67 protected:
69 };
70}
Window()=default
virtual void OnUpdate()=0
virtual unsigned int GetWidth() const =0
virtual unsigned int GetHeight() const =0
WindowData m_Data
Definition Window.h:68
virtual double GetTime() const =0
void EventCallback(Event &event)
Definition Window.h:65
virtual ~Window()
Definition Window.h:41
virtual void Init(const WindowProps &props)
Definition Window.cpp:82
virtual void * GetNativeWindow() const =0
virtual void SetEventCallback(const EventCallbackFn &callback)=0
virtual bool GetFocus() const =0
const WindowData & GetWindowData() const
Definition Window.h:62
virtual bool IsVSync() const =0
virtual void SetVSync(bool enabled)=0
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
std::function< void(Event &)> EventCallbackFn
Definition Window.h:9
unsigned int Width
Definition Window.h:14
unsigned int Height
Definition Window.h:14
std::string Title
Definition Window.h:13
EventCallbackFn EventCallback
Definition Window.h:18
unsigned int Height
Definition Window.h:25
unsigned int Width
Definition Window.h:24
WindowProps(const std::string &title, unsigned int width, unsigned int height, bool vsync)
Definition Window.h:30
std::string Title
Definition Window.h:23