- Moved setting window properties to
      ClientSide

- Made Application::OnEvent private
This commit is contained in:
Light 2021-06-14 10:01:28 +04:30
parent a3092c476c
commit 612b382f30
6 changed files with 57 additions and 13 deletions

View file

@ -17,12 +17,12 @@ namespace Light {
Application::Application()
{
Logger::Initialize();
m_Window = std::unique_ptr<Window>(Window::Create({ "Title", 800u, 600u, false }, std::bind(&Application::OnEvent, this , std::placeholders::_1)));
m_Window = std::unique_ptr<Light::Window>(Light::Window::Create(std::bind(&Light::Application::OnEvent, this, std::placeholders::_1)));
}
Application::~Application()
{
LT_ENGINE_INFO("Application::~Application: Terminating Application");
LT_ENGINE_TRACE("Application::~Application()");
}
void Application::GameLoop()
@ -30,10 +30,13 @@ namespace Light {
// check
LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty");
// Log some data
// Log window data
m_Window->GetGfxContext()->LogDebugData();
m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
// Show window
m_Window->SetVisible(true);
// GAMELOOP //
while (m_Window->IsOpen())
{

View file

@ -12,9 +12,11 @@ namespace Light {
class Application
{
private:
std::unique_ptr<Window> m_Window = nullptr;
LayerStack m_LayerStack;
protected:
std::unique_ptr<Window> m_Window = nullptr;
public:
Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
@ -22,13 +24,15 @@ namespace Light {
virtual ~Application();
void GameLoop();
void OnEvent(const Event& event);
// To be defined in client project
friend Application* CreateApplication();
protected:
Application();
private:
void OnEvent(const Event& event);
};
}

View file

@ -21,11 +21,17 @@ namespace Light {
bool b_Open;
public:
static Window* Create(const WindowProperties& properties, std::function<void(Event&)> callback);
Window(const Window&) = delete;
Window& operator=(const Window&) = delete;
virtual ~Window() = default;
virtual void SetProperties(const WindowProperties& properties) = 0;
virtual void SetVisible(bool visible) = 0;
inline GraphicsContext* GetGfxContext() { return m_GraphicsContext.get(); }
inline bool IsOpen() const { return b_Open; }
@ -38,8 +44,6 @@ namespace Light {
virtual inline void* GetNativeHandle() = 0;
static Window* Create(const WindowProperties& properties, std::function<void(Event&)> callback);
protected:
Window() = default;
};

View file

@ -17,12 +17,14 @@ namespace Light {
return new wWindow(properties, callback);
}
wWindow::wWindow(const WindowProperties& properties, std::function<void(Event&)> callback)
: m_Properties(properties), m_EventCallback(callback)
wWindow::wWindow(std::function<void(Event&)> callback)
: m_EventCallback(callback)
{
LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: glfwInit: failed to initialize glfw");
m_Handle = glfwCreateWindow(properties.width, properties.height, properties.title.c_str(), nullptr, nullptr);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
LT_ENGINE_ASSERT(m_Handle, "wWindow::wWindow: glfwCreateWindow: failed to create glfw window");
glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
@ -37,6 +39,23 @@ namespace Light {
glfwDestroyWindow(m_Handle);
}
void wWindow::SetProperties(const WindowProperties& properties)
{
m_Properties = properties;
glfwSetWindowSize(m_Handle, properties.width, properties.height);
glfwSetWindowTitle(m_Handle, properties.title.c_str());
glfwSwapInterval((int)properties.vsync);
}
void wWindow::SetVisible(bool visible)
{
if (visible)
glfwShowWindow(m_Handle);
else
glfwHideWindow(m_Handle);
}
void wWindow::PollEvents()
{
glfwPollEvents();

View file

@ -13,15 +13,19 @@ namespace Light {
{
private:
GLFWwindow* m_Handle = nullptr;
WindowProperties m_Properties;
WindowProperties m_Properties = {};
std::function<void(Event&)> m_EventCallback;
public:
wWindow(const WindowProperties& properties, std::function<void(Event&)> callback);
wWindow(std::function<void(Event&)> callback);
~wWindow();
virtual void SetProperties(const WindowProperties& properties) override;
virtual void SetVisible(bool visible) override;
virtual void PollEvents() override;
virtual void OnEvent(const Event& event) override;

View file

@ -1,7 +1,7 @@
#define LIGHT_ENTRY_POINT
#include <LightEngine.h>
#include "SandboxLayer.h"
#include "SandboxLayer.h"
class Sandbox : public Light::Application
{
@ -10,6 +10,16 @@ public:
{
LT_CLIENT_TRACE("Sandbox::Sandbox");
// Set window properties
Light::WindowProperties properties;
properties.title = "Sandbox";
properties.width = 800u;
properties.height = 600u;
properties.vsync = true;
m_Window->SetProperties(properties);
// Attach the sandbox layer
Light::LayerStack::AttachLayer(new SandboxLayer("SandboxLayer"));
}