//
// Created by sfd on 25-5-18.
//

#include "GameLayer.h"

#include <Hazel/Core/Application.h>
#include <Hazel/Renderer/Renderer2D.h>
#include <Hazel/Renderer/RendererCommand.h>

GameLayer::GameLayer() : Layer("GameLayer") , m_cameraController((float)(Application::Get().GetWindow().GetWidth()) / (float)(Application::Get().GetWindow().GetHeight()))
{
}


void GameLayer::OnAttach()
{
}

void GameLayer::OnDetech()
{
}

void GameLayer::OnUpdate(TimeStep& ts)
{
    auto mouseState = SDL_GetMouseState(NULL, NULL);
    static Uint32 prevMouseState = 0;
    m_cameraController.OnUpdate(ts);

    RendererCommand::SetClearColor({0.2f, 0.2f, 0.2f, 1.0f});
    RendererCommand::Clear();

    Renderer2D::BeginScene(m_cameraController.GetCamera());

    Hazel::Renderer2D::DrawQuad({0.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f});

    Renderer2D::EndScene();

    if ((mouseState & SDL_BUTTON_LMASK) && !(prevMouseState & SDL_BUTTON_LMASK))
    {
        HZ_CORE_INFO("LEFT Mouse Clicked!");
    }
    prevMouseState = mouseState;
}

void GameLayer::OnEvent(SDL_Event& e)
{
    m_cameraController.OnEvent(e);
}

void GameLayer::OnImGuiRender()
{
}