Window
- Moved setting window properties to
      ClientSide
- Made Application::OnEvent private
			
			
This commit is contained in:
		
							parent
							
								
									a3092c476c
								
							
						
					
					
						commit
						612b382f30
					
				
					 6 changed files with 57 additions and 13 deletions
				
			
		| 
						 | 
					@ -17,12 +17,12 @@ namespace Light {
 | 
				
			||||||
	Application::Application()
 | 
						Application::Application()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		Logger::Initialize();
 | 
							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()
 | 
						Application::~Application()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		LT_ENGINE_INFO("Application::~Application: Terminating Application");
 | 
							LT_ENGINE_TRACE("Application::~Application()");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Application::GameLoop()
 | 
						void Application::GameLoop()
 | 
				
			||||||
| 
						 | 
					@ -30,10 +30,13 @@ namespace Light {
 | 
				
			||||||
		// check
 | 
							// check
 | 
				
			||||||
		LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty");
 | 
							LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Log some data
 | 
							// Log window data
 | 
				
			||||||
		m_Window->GetGfxContext()->LogDebugData();
 | 
							m_Window->GetGfxContext()->LogDebugData();
 | 
				
			||||||
		m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
 | 
							m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Show window
 | 
				
			||||||
 | 
							m_Window->SetVisible(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//  GAMELOOP  //
 | 
							//  GAMELOOP  //
 | 
				
			||||||
		while (m_Window->IsOpen())
 | 
							while (m_Window->IsOpen())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,9 +12,11 @@ namespace Light {
 | 
				
			||||||
	class Application
 | 
						class Application
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		std::unique_ptr<Window> m_Window = nullptr;
 | 
					 | 
				
			||||||
		LayerStack m_LayerStack;
 | 
							LayerStack m_LayerStack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						protected:
 | 
				
			||||||
 | 
							std::unique_ptr<Window> m_Window = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		Application(const Application&) = delete;
 | 
							Application(const Application&) = delete;
 | 
				
			||||||
		Application& operator=(const Application&) = delete;
 | 
							Application& operator=(const Application&) = delete;
 | 
				
			||||||
| 
						 | 
					@ -22,13 +24,15 @@ namespace Light {
 | 
				
			||||||
		virtual ~Application();
 | 
							virtual ~Application();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void GameLoop();
 | 
							void GameLoop();
 | 
				
			||||||
		void OnEvent(const Event& event);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// To be defined in client project
 | 
							// To be defined in client project
 | 
				
			||||||
		friend Application* CreateApplication();
 | 
							friend Application* CreateApplication();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		Application();
 | 
							Application();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private:
 | 
				
			||||||
 | 
							void OnEvent(const Event& event);
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -21,11 +21,17 @@ namespace Light {
 | 
				
			||||||
		bool b_Open;
 | 
							bool b_Open;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
 | 
							static Window* Create(const WindowProperties& properties, std::function<void(Event&)> callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Window(const Window&) = delete;
 | 
							Window(const Window&) = delete;
 | 
				
			||||||
		Window& operator=(const Window&) = delete;
 | 
							Window& operator=(const Window&) = delete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual ~Window() = default;
 | 
							virtual ~Window() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							virtual void SetProperties(const WindowProperties& properties) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							virtual void SetVisible(bool visible) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		inline GraphicsContext* GetGfxContext() { return m_GraphicsContext.get(); }
 | 
							inline GraphicsContext* GetGfxContext() { return m_GraphicsContext.get(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		inline bool IsOpen() const { return b_Open; }
 | 
							inline bool IsOpen() const { return b_Open; }
 | 
				
			||||||
| 
						 | 
					@ -38,8 +44,6 @@ namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual inline void* GetNativeHandle() = 0;
 | 
							virtual inline void* GetNativeHandle() = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		static Window* Create(const WindowProperties& properties, std::function<void(Event&)> callback);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		Window() = default;
 | 
							Window() = default;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,12 +17,14 @@ namespace Light {
 | 
				
			||||||
		return new wWindow(properties, callback);
 | 
							return new wWindow(properties, callback);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wWindow::wWindow(const WindowProperties& properties, std::function<void(Event&)> callback)
 | 
						wWindow::wWindow(std::function<void(Event&)> callback)
 | 
				
			||||||
		: m_Properties(properties), m_EventCallback(callback)
 | 
							: m_EventCallback(callback)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: glfwInit: failed to initialize glfw");
 | 
							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");
 | 
							LT_ENGINE_ASSERT(m_Handle, "wWindow::wWindow: glfwCreateWindow: failed to create glfw window");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
 | 
							glfwSetWindowUserPointer(m_Handle, &m_EventCallback);
 | 
				
			||||||
| 
						 | 
					@ -37,6 +39,23 @@ namespace Light {
 | 
				
			||||||
		glfwDestroyWindow(m_Handle);
 | 
							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()
 | 
						void wWindow::PollEvents()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		glfwPollEvents();
 | 
							glfwPollEvents();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,15 +13,19 @@ namespace Light {
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		GLFWwindow* m_Handle = nullptr;
 | 
							GLFWwindow* m_Handle = nullptr;
 | 
				
			||||||
		WindowProperties m_Properties;
 | 
							WindowProperties m_Properties = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		std::function<void(Event&)> m_EventCallback;
 | 
							std::function<void(Event&)> m_EventCallback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		wWindow(const WindowProperties& properties, std::function<void(Event&)> callback);
 | 
							wWindow(std::function<void(Event&)> callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		~wWindow();
 | 
							~wWindow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							virtual void SetProperties(const WindowProperties& properties) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							virtual void SetVisible(bool visible) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual void PollEvents() override;
 | 
							virtual void PollEvents() override;
 | 
				
			||||||
		virtual void OnEvent(const Event& event) override;
 | 
							virtual void OnEvent(const Event& event) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,16 @@ public:
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		LT_CLIENT_TRACE("Sandbox::Sandbox");
 | 
							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"));
 | 
							Light::LayerStack::AttachLayer(new SandboxLayer("SandboxLayer"));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue