0% found this document useful (0 votes)
35 views

"HZPCH.H" "Application.h" "Hazel/Log.h" : Namespace This

This C++ code defines an Application class that is responsible for running a Hazel application. The Application class constructs a Window, sets an event callback for the window, and manages a stack of Layer objects. It contains methods for pushing layers onto the stack, handling window close events, and running the main loop to update layers and draw to the window each frame.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

"HZPCH.H" "Application.h" "Hazel/Log.h" : Namespace This

This C++ code defines an Application class that is responsible for running a Hazel application. The Application class constructs a Window, sets an event callback for the window, and manages a stack of Layer objects. It contains methods for pushing layers onto the stack, handling window close events, and running the main loop to update layers and draw to the window each frame.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include "hzpch.

h"
#include "Application.h"

#include "Hazel/Log.h"

#include <glad/glad.h>

namespace Hazel {

#define BIND_EVENT_FN(x) std::bind(&Application::x, this, std::placeholders::_1)

Application::Application()
{
m_Window = std::unique_ptr<Window>(Window::Create());
m_Window->SetEventCallback(BIND_EVENT_FN(OnEvent));
}

Application::~Application()
{
}

void Application::PushLayer(Layer* layer)


{
m_LayerStack.PushLayer(layer);
}

void Application::PushOverlay(Layer* layer)


{
m_LayerStack.PushOverlay(layer);
}

void Application::OnEvent(Event& e)
{
EventDispatcher dispatcher(e);
dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FN(OnWindowClose));

//HZ_CORE_TRACE("{0}", e);

for (auto it = m_LayerStack.end(); it != m_LayerStack.begin(); )


{
(*--it)->OnEvent(e);
if (e.Handled)
break;
}
}

void Application::Run()
{
while (m_Running)
{
glClearColor(0, 0.8, 0.2, 1);
glClear(GL_COLOR_BUFFER_BIT);

for (Layer* layer : m_LayerStack)


layer->OnUpdate();
m_Window->OnUpdate();
}
}

bool Application::OnWindowClose(WindowCloseEvent& e)
{
m_Running = false;
return true;
}

You might also like