Just™ Game Engine
window.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-2022 Konstanty Misiak
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8#include "jng/core/base.hpp"
9
10#include <functional>
11
12struct GLFWwindow;
13
14namespace jng {
15
16 class Event;
17 class GraphicsContext;
18
19 class Window
20 {
21 public:
22 using EventCallbackFunc = std::function<void(Event&)>;
23
24 struct WindowData {
25 std::string title;
27 bool isMinimized = false;
29 };
30
31 void onUpdate();
32 GLFWwindow* getNativeWindowHandle() const { return m_windowHandle; }
33 void setTitle(const char* title);
34 u32 getWidth() const { return m_windowData.width; }
35 u32 getHeight() const { return m_windowData.height; }
36 bool isMinimized() const { return m_windowData.isMinimized; }
37 void setEventCallback(const EventCallbackFunc& callback) { m_windowData.eventCallback = callback; }
38 const EventCallbackFunc& getEventCallback() const { return m_windowData.eventCallback; }
39 GraphicsContext* getGraphicsContext() const { return m_graphicsContext.get(); }
40
41 static Scope<Window> create(const char* title, u32 width, u32 height);
42 Window(const char* title, u32 width, u32 height);
43 ~Window();
44 private:
45 GLFWwindow* m_windowHandle;
46 bool m_isVSyncEnabled;
47 Window::WindowData m_windowData;
48 Scope<GraphicsContext> m_graphicsContext;
49 };
50
51} // namespace jng
Definition: event.hpp:24
Definition: graphics_context.hpp:15
Definition: window.hpp:20
u32 getHeight() const
Definition: window.hpp:35
GraphicsContext * getGraphicsContext() const
Definition: window.hpp:39
~Window()
Definition: window.cpp:142
void setEventCallback(const EventCallbackFunc &callback)
Definition: window.hpp:37
std::function< void(Event &)> EventCallbackFunc
Definition: window.hpp:22
void onUpdate()
Definition: window.cpp:96
void setTitle(const char *title)
Definition: window.cpp:103
GLFWwindow * getNativeWindowHandle() const
Definition: window.hpp:32
bool isMinimized() const
Definition: window.hpp:36
Window(const char *title, u32 width, u32 height)
Definition: window.cpp:116
static Scope< Window > create(const char *title, u32 width, u32 height)
Definition: window.cpp:109
u32 getWidth() const
Definition: window.hpp:34
const EventCallbackFunc & getEventCallback() const
Definition: window.hpp:38
Definition: base.hpp:11
std::unique_ptr< T > Scope
Definition: base.hpp:24
uint32_t u32
Definition: base.hpp:41
Definition: window.hpp:24
bool isMinimized
Definition: window.hpp:27
u32 width
Definition: window.hpp:26
EventCallbackFunc eventCallback
Definition: window.hpp:28
u32 height
Definition: window.hpp:26
std::string title
Definition: window.hpp:25