open dialog list files and thumbnail preview

This commit is contained in:
2017-08-10 23:43:57 +01:00
parent 5bc9d443bc
commit 178c944df1
6 changed files with 141 additions and 23 deletions

View File

@@ -187,10 +187,10 @@
</layout>
<layout id="dialog-open-item">
<node dir="row">
<image-texture id="thumb-tex" width="64" height="64"/>
<text text="Longer description for the error or the message." font-face="arial" font-size="11"></text>
</node>
<border dir="row" color=".4 .4 .4 .8" pad="4">
<!--<image-texture id="thumb-tex" width="64" height="64"/>-->
<text id="title" text="Title" font-face="arial" font-size="11"/>
</border>
</layout>
<!-- Open Dialog Popup -->
@@ -201,9 +201,14 @@
<text text="Open PanoPainter Project" font-face="arial" font-size="11"></text>
</border>
<border width="400" color="0 0 0 .9" pad="10" dir="col">
<ref id="dialog-open-item" />
<ref id="dialog-open-item" />
<ref id="dialog-open-item" />
<node dir="row">
<node id="files-list" dir="col"/>
<node dir="col" grow="1" margin="0 0 0 10">
<border height="20" align="center" justify="center" color=".2 .2 .2 1"><text id="info-title" text="Title" font-face="arial" font-size="11"/></border>
<text id="info-data" text="Title" font-face="arial" font-size="11"/>
</node>
<image-texture id="thumb-tex" width="100" height="100"/>
</node>
<!--<text-input width="100" height="100" color=".3"/>-->
<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"/>

View File

@@ -269,7 +269,7 @@ void App::initLayout()
open_dialog->btn_ok->on_click = [this,open_dialog](Node*)
{
layers->clear();
canvas->m_canvas->project_open(data_path);
canvas->m_canvas->project_open(open_dialog->selected_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();
@@ -410,12 +410,13 @@ void App::initLayout()
popup->find<NodeButtonCustom>("layer-merge")->on_click = [this](Node*) {
const auto& order = canvas->m_canvas->m_order;
//layers->get_child_index(layers->)
int current_idx_order = std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx));
if (current_idx_order > 0)
{
int dest_layer_idx = order[current_idx_order - 1];
canvas->m_canvas->layer_merge(canvas->m_canvas->m_current_layer_idx, dest_layer_idx);
canvas->m_canvas->layer_remove(current_idx_order);
canvas->m_canvas->layer_remove(canvas->m_canvas->m_current_layer_idx);
layers->clear();
for (auto& i : canvas->m_canvas->m_order)
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());

View File

@@ -15,7 +15,7 @@ std::vector<std::string> Asset::list_files(std::string folder, bool is_asset, co
std::vector<std::string> names;
#ifdef _WIN32
WIN32_FIND_DATAA fd;
HANDLE hFind = ::FindFirstFileA((folder + "*").c_str(), &fd);
HANDLE hFind = ::FindFirstFileA((folder + "\\*").c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
do

View File

@@ -1064,12 +1064,12 @@ void ui::Canvas::project_save(std::string data_path)
void ui::Canvas::project_open(std::string data_path)
{
static char name[128];
sprintf(name, "%s/latlong.pano", data_path.c_str());
FILE* fp = fopen(name, "rb");
// static char name[128];
// sprintf(name, "%s/latlong.pano", data_path.c_str());
FILE* fp = fopen(data_path.c_str(), "rb");
if (!fp)
{
LOG("cannot write project to %s", name);
LOG("cannot write project to %s", data_path.c_str());
return;
}
@@ -1130,7 +1130,7 @@ void ui::Canvas::project_open(std::string data_path)
m_layers.back().restore(snap);
}
fclose(fp);
LOG("project restore from %s", name);
LOG("project restore from %s", data_path.c_str());
}
ui::Image ui::Canvas::thumbnail_generate(int w, int h)
@@ -1196,12 +1196,12 @@ ui::Image ui::Canvas::thumbnail_generate(int w, int h)
ui::Image ui::Canvas::thumbnail_read(std::string data_path)
{
static char name[128];
sprintf(name, "%s/latlong.pano", data_path.c_str());
FILE* fp = fopen(name, "rb");
// static char name[128];
// sprintf(name, "%s/latlong.pano", data_path.c_str());
FILE* fp = fopen(data_path.c_str(), "rb");
if (!fp)
{
LOG("cannot read project %s", name);
LOG("cannot read project %s", data_path.c_str());
return {}; // return empty image
}
Image thumb;
@@ -1211,7 +1211,7 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path)
thumb.create();
fread((uint8_t*)thumb.data(), thumb.size(), 1, fp);
fclose(fp);
LOG("project thumbnail read from %s", name);
LOG("project thumbnail read from %s", data_path.c_str());
return std::move(thumb);
}

View File

@@ -3,6 +3,7 @@
#include "node_dialog_open.h"
#include "canvas.h"
#include "node_image_texture.h"
#include "asset.h"
Node* NodeDialogOpen::clone_instantiate() const
{
@@ -31,11 +32,98 @@ void NodeDialogOpen::init_controls()
btn_cancel->on_click = [this](Node*) {
destroy();
};
container = find<Node>("files-list");
auto names = Asset::list_files(data_path, false, ".*\\.pano");
for (const auto& n : names)
{
auto node = new NodeDialogOpenItem;
node->m_manager = m_manager;
node->init();
node->m_text->set_text(n.c_str());
node->m_path = data_path + "/" + n;
node->on_selected = [&](NodeDialogOpenItem* target) {
static NodeDialogOpenItem* current = nullptr;
if (target == current)
return;
ui::Image thumb = ui::Canvas::I->thumbnail_read(target->m_path);
auto image_tex = find<NodeImageTexture>("thumb-tex");
image_tex->tex.destroy();
image_tex->tex.create(thumb);
selected_path = target->m_path;
if (current)
current->m_selected = false;
current = target;
};
container->add_child(node);
}
container->update();
if (auto* first = (NodeDialogOpenItem*)container->get_child_at(0))
{
first->on_selected(first);
first->m_selected = true;
}
}
void NodeDialogOpen::loaded()
{
ui::Image thumb = ui::Canvas::I->thumbnail_read(data_path);
auto image_tex = find<NodeImageTexture>("thumb-tex");
image_tex->tex.create(thumb);
// ui::Image thumb = ui::Canvas::I->thumbnail_read(data_path);
// auto image_tex = find<NodeImageTexture>("thumb-tex");
// image_tex->tex.create(thumb);
}
//////////////////////////////////////////////////////////////////
Node* NodeDialogOpenItem::clone_instantiate() const
{
return new NodeDialogOpenItem;
}
void NodeDialogOpenItem::clone_finalize(Node* dest) const
{
NodeDialogOpenItem* n = static_cast<NodeDialogOpenItem*>(dest);
n->init_controls();
}
void NodeDialogOpenItem::init()
{
auto tpl = static_cast<const NodeBorder*>(init_template("dialog-open-item"));
m_color = tpl->m_color;
m_border_color = tpl->m_border_color;
m_thinkness = tpl->m_thinkness;
init_controls();
}
void NodeDialogOpenItem::init_controls()
{
m_text = find<NodeText>("title");
}
void NodeDialogOpenItem::loaded()
{
}
void NodeDialogOpenItem::draw()
{
auto c = m_selected ? m_color_selected : m_color_normal;
//m_thinkness = m_selected ? 1.f : 0.f;
m_color = m_mouse_inside ? m_color_hover : c;
NodeBorder::draw();
}
kEventResult NodeDialogOpenItem::handle_event(Event* e)
{
NodeBorder::handle_event(e);
switch (e->m_type)
{
case kEventType::MouseEnter:
break;
case kEventType::MouseLeave:
break;
case kEventType::MouseDownL:
m_selected = true;
if (on_selected)
on_selected(this);
break;
case kEventType::MouseUpL:
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
}

View File

@@ -1,12 +1,36 @@
#pragma once
#include "node_border.h"
#include "node_button.h"
#include "node_image_texture.h"
#include "node_text.h"
class NodeDialogOpenItem : public NodeBorder
{
public:
NodeText* m_text;
NodeImageTexture* m_thumb;
glm::vec4 m_color_normal = glm::vec4(.4, .4, .4, 1);
glm::vec4 m_color_selected = glm::vec4(.3, .3, .3, 1);
glm::vec4 m_color_hover = glm::vec4(.5, .5, .5, 1);
bool m_selected = false;
std::string m_path;
std::function<void(NodeDialogOpenItem* target)> on_selected;
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;
virtual void init() override;
void init_controls();
virtual void loaded() override;
virtual void draw() override;
virtual kEventResult handle_event(Event* e) override;
};
class NodeDialogOpen : public NodeBorder
{
public:
NodeButton* btn_cancel;
NodeButton* btn_ok;
Node* container;
std::string selected_path;
std::string data_path;
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;