#include "pch.h"
#include "log.h"
#include "node_dialog_resize.h"
#include "canvas.h"
#include "node_image_texture.h"
#include "app.h"
#include <array>

Node* NodeDialogResize::clone_instantiate() const
{
    return new NodeDialogResize();
}

void NodeDialogResize::clone_finalize(Node* dest) const
{
    NodeDialogResize* n = static_cast<NodeDialogResize*>(dest);
    n->init_controls();
}

void NodeDialogResize::init()
{
    auto tpl = static_cast<const NodeBorder*>(init_template("dialog-resize"));
    m_color = tpl->m_color;
    m_border_color = tpl->m_border_color;;
    m_thinkness = tpl->m_thinkness;;
    init_controls();
}

void NodeDialogResize::init_controls()
{
    btn_ok = find<NodeButton>("btn-ok");
    btn_cancel = find<NodeButton>("btn-cancel");
    combo = find<NodeComboBox>("resolution");
    text = find<NodeText>("current-res");
    resolution = Canvas::I->m_width;
    static char txt[128];
    sprintf(txt, "Current: %s", App::I.res_to_string(resolution).c_str());
    text->set_text(txt);
    btn_cancel->on_click = [this](Node*) {
        destroy();
    };
}

void NodeDialogResize::loaded()
{
//    Image thumb = Canvas::I->thumbnail_read(data_path);
//    auto image_tex = find<NodeImageTexture>("thumb-tex");
//    image_tex->tex.create(thumb);
}

int NodeDialogResize::get_resolution()
{
    return combo ? App::I.res_from_index(combo->m_current_index) : 512;
}
