create NodeDialogOpen and bind it to the layout template
This commit is contained in:
@@ -166,7 +166,7 @@
|
||||
</layout>
|
||||
|
||||
<!-- Open Dialog Popup -->
|
||||
<layout id="popup-dialog-open">
|
||||
<layout id="dialog-open">
|
||||
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
|
||||
<border thickness="1" border-color=".2" pad="3">
|
||||
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
|
||||
@@ -177,7 +177,7 @@
|
||||
<text text="Longer description for the error or the message." font-face="arial" font-size="11"></text>
|
||||
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
|
||||
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
|
||||
<button text="Cancel" width="60" height="30" pad="10"/>
|
||||
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/>
|
||||
</node>
|
||||
</border>
|
||||
</border>
|
||||
|
||||
@@ -477,20 +477,24 @@ void App::initLayout()
|
||||
button->on_click = [this,button](Node*) {
|
||||
if (canvas)
|
||||
{
|
||||
//canvas->m_canvas->project_open(data_path);
|
||||
//for (auto& i : canvas->m_canvas->m_order)
|
||||
// layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
||||
|
||||
// load thumbnail test
|
||||
auto open_dialog = layout[const_hash("popup-dialog-open")]->m_children[0]->clone();
|
||||
auto open_dialog = std::make_shared<NodeDialogOpen>();
|
||||
open_dialog->m_manager = &layout;
|
||||
open_dialog->data_path = data_path;
|
||||
open_dialog->init();
|
||||
open_dialog->create();
|
||||
open_dialog->loaded();
|
||||
|
||||
layout[main_id]->add_child(open_dialog);
|
||||
layout[main_id]->update();
|
||||
if (open_dialog)
|
||||
|
||||
open_dialog->btn_ok->on_click = [this,open_dialog](Node*)
|
||||
{
|
||||
Image thumb = canvas->m_canvas->thumbnail_read(data_path);
|
||||
auto image_tex = open_dialog->find<NodeImageTexture>("thumb-tex");
|
||||
image_tex->tex.create(thumb);
|
||||
}
|
||||
canvas->m_canvas->project_open(data_path);
|
||||
for (auto& i : canvas->m_canvas->m_order)
|
||||
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
||||
open_dialog->destroy();
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "log.h"
|
||||
#include "canvas.h"
|
||||
|
||||
ui::Canvas* ui::Canvas::I;
|
||||
glm::vec3 ui::Canvas::m_plane_origin[6] = {
|
||||
{ 0, 0,-1}, // front
|
||||
{ 1, 0, 0}, // right
|
||||
@@ -597,6 +598,7 @@ void ui::Canvas::project_open(std::string data_path)
|
||||
fclose(fp);
|
||||
LOG("project restore from %s", name);
|
||||
}
|
||||
|
||||
ui::Image ui::Canvas::thumbnail_generate(int w, int h)
|
||||
{
|
||||
// save viewport and clear color states
|
||||
@@ -657,6 +659,7 @@ ui::Image ui::Canvas::thumbnail_generate(int w, int h)
|
||||
|
||||
return std::move(image);
|
||||
}
|
||||
|
||||
ui::Image ui::Canvas::thumbnail_read(std::string data_path)
|
||||
{
|
||||
static char name[128];
|
||||
@@ -677,6 +680,7 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path)
|
||||
LOG("project thumbnail read from %s", name);
|
||||
return std::move(thumb);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ui::Layer::destroy()
|
||||
|
||||
@@ -39,6 +39,7 @@ class Canvas
|
||||
BrushMesh m_mesh;
|
||||
bool m_dirty = false;
|
||||
public:
|
||||
static Canvas* I;
|
||||
bool m_erase = false;
|
||||
glm::mat4 m_mv;
|
||||
glm::mat4 m_proj;
|
||||
@@ -70,6 +71,7 @@ public:
|
||||
|
||||
std::vector<Layer::Snapshot> m_layers_snapshot;
|
||||
|
||||
Canvas() { I = this; }
|
||||
bool create(int width, int height);
|
||||
void resize(int width, int height);
|
||||
void layer_add(std::string name);
|
||||
|
||||
@@ -1898,6 +1898,42 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NodeDialogOpen : public NodeBorder
|
||||
{
|
||||
public:
|
||||
NodeButton* btn_cancel;
|
||||
NodeButton* btn_ok;
|
||||
std::string data_path;
|
||||
virtual Node* clone_instantiate() const override { return new NodeDialogOpen(); }
|
||||
virtual void clone_finalize(Node* dest) const override
|
||||
{
|
||||
NodeDialogOpen* n = static_cast<NodeDialogOpen*>(dest);
|
||||
n->init_controls();
|
||||
}
|
||||
virtual void init() override
|
||||
{
|
||||
auto tpl = static_cast<const NodeBorder*>(init_template("dialog-open"));
|
||||
m_color = tpl->m_color;
|
||||
m_border_color = tpl->m_border_color;;
|
||||
m_thinkness = tpl->m_thinkness;;
|
||||
init_controls();
|
||||
}
|
||||
void init_controls()
|
||||
{
|
||||
btn_ok = find<NodeButton>("btn-ok");
|
||||
btn_cancel = find<NodeButton>("btn-cancel");
|
||||
btn_cancel->on_click = [this](Node*) {
|
||||
destroy();
|
||||
};
|
||||
}
|
||||
virtual void loaded() override
|
||||
{
|
||||
ui::Image thumb = ui::Canvas::I->thumbnail_read(data_path);
|
||||
auto image_tex = find<NodeImageTexture>("thumb-tex");
|
||||
image_tex->tex.create(thumb);
|
||||
}
|
||||
};
|
||||
|
||||
class NodeCanvas : public Node
|
||||
{
|
||||
bool m_dragging = false;
|
||||
|
||||
Reference in New Issue
Block a user