/*
	GameEngine and Editor
	by John Ryland
	Copyright (c) 2023
*/

////////////////////////////////////////////////////////////////////////////////////
//	Image View

#include "ImageView.h"
#include "Image.h"
#include "imgui.h"

namespace GameEngine {

ImageView::ImageView(ApplicationFramework::IApplication& app)
    : m_application(app)
{
}

void ImageView::AddShowMenuItem()
{
    ImGui::MenuItem("Show Image Viewer", NULL, &m_open);
}

void ImageView::Update()
{
    if (m_open)
    {
        if (ImGui::Begin("Image Viewer", &m_open))
        {
            ImGui::Text("pointer = %p", (ImTextureID)m_texture);
            ImGui::Text("size = %d x %d", m_width, m_height);
            ImGui::Image((ImTextureID)m_texture, ImVec2(m_width, m_height));
        }
        ImGui::End();
    }
}

void ImageView::Initialize()
{
    ApplicationFramework::Image textureImage;
    textureImage.Load("resources/image4.png");
    m_texture = m_application.RenderSystem()->CreateTexture(textureImage);
    m_width = textureImage.Width();
    m_height = textureImage.Height();
}

void ImageView::Shutdown()
{
    m_application.RenderSystem()->DestroyTexture(m_texture);
}

} // GameEngine namespace
