211 lines
6.1 KiB
C++
211 lines
6.1 KiB
C++
#include "pch.h"
|
|
#include "log.h"
|
|
#include "node_dialog_cloud.h"
|
|
#include "canvas.h"
|
|
#include "node_image_texture.h"
|
|
#include "asset.h"
|
|
#include "node_message_box.h"
|
|
#include "app.h"
|
|
#include "image.h"
|
|
|
|
Node* NodeDialogCloud::clone_instantiate() const
|
|
{
|
|
return new NodeDialogCloud();
|
|
}
|
|
|
|
void NodeDialogCloud::clone_finalize(Node* dest) const
|
|
{
|
|
NodeDialogCloud* n = static_cast<NodeDialogCloud*>(dest);
|
|
n->init_controls();
|
|
}
|
|
|
|
void NodeDialogCloud::init()
|
|
{
|
|
auto tpl = static_cast<const NodeBorder*>(init_template("dialog-cloud"));
|
|
m_color = tpl->m_color;
|
|
m_border_color = tpl->m_border_color;;
|
|
m_thinkness = tpl->m_thinkness;;
|
|
init_controls();
|
|
}
|
|
|
|
void NodeDialogCloud::init_controls()
|
|
{
|
|
btn_ok = find<NodeButton>("btn-ok");
|
|
btn_cancel = find<NodeButton>("btn-cancel");
|
|
btn_cancel->on_click = [this](Node*) {
|
|
destroy();
|
|
};
|
|
container = find<Node>("files-list");
|
|
std::thread(&NodeDialogCloud::load_thumbs_thread, this).detach();
|
|
/*
|
|
auto names = Asset::list_files(data_path, false, ".*\\.pano");
|
|
for (const auto& n : names)
|
|
{
|
|
auto node = new NodeDialogCloudItem;
|
|
node->m_manager = m_manager;
|
|
node->init();
|
|
node->m_text->set_text(n.c_str());
|
|
node->m_path = data_path + "/" + n;
|
|
node->m_file_name = n;
|
|
node->on_selected = [&](NodeDialogCloudItem* target) {
|
|
if (target == current)
|
|
return;
|
|
selected_path = target->m_path;
|
|
selected_file = target->m_file_name;
|
|
selected_name = selected_file.substr(0, selected_file.length() - 5);
|
|
if (current)
|
|
current->m_selected = false;
|
|
current = target;
|
|
};
|
|
|
|
// load thumb
|
|
ui::Image thumb = ui::Canvas::I->thumbnail_read(node->m_path);
|
|
auto image_tex = node->find<NodeImageTexture>("thumb-tex");
|
|
image_tex->tex.destroy();
|
|
image_tex->tex.create(thumb);
|
|
|
|
container->add_child(node);
|
|
}
|
|
*/
|
|
}
|
|
|
|
void NodeDialogCloud::loaded()
|
|
{
|
|
}
|
|
|
|
std::vector<std::string> split(const std::string& subject, char d)
|
|
{
|
|
std::vector<std::string> ret;
|
|
int start = 0;
|
|
int n = subject.find_first_of(d);
|
|
while (n != std::string::npos)
|
|
{
|
|
ret.push_back(subject.substr(start, n - start));
|
|
start = n + 1;
|
|
n = subject.find_first_of(d, start);
|
|
}
|
|
ret.push_back(subject.substr(start));
|
|
return ret;
|
|
}
|
|
|
|
void NodeDialogCloud::load_thumbs_thread()
|
|
{
|
|
CURL *curl = curl_easy_init();
|
|
std::string res;
|
|
if (curl)
|
|
{
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res);
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler);
|
|
curl_easy_setopt(curl, CURLOPT_URL, "http://omigamedev.ddns.net:8080/panoview/cloud-list.php");
|
|
auto err = curl_easy_perform(curl);
|
|
LOG("CLOUD LIST: %s", res.c_str());
|
|
|
|
auto names = split(res, ',');
|
|
for (const auto& n : names)
|
|
{
|
|
res.clear();
|
|
std::string url = "http://omigamedev.ddns.net:8080/panoview/cloud-info.php?file=" + n;
|
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
|
auto err = curl_easy_perform(curl);
|
|
auto info = split(res, ',');
|
|
int width = atoi(info[0].c_str());
|
|
int height = atoi(info[1].c_str());
|
|
int comp = atoi(info[2].c_str());
|
|
assert(comp == 4);
|
|
std::string rgb;
|
|
rgb.resize(Base64::DecodedLength(info[3]));
|
|
Base64::Decode(info[3], &rgb);
|
|
ui::Image thumb;
|
|
thumb.create(width, height);
|
|
thumb.copy_from((uint8_t*)rgb.data());
|
|
|
|
|
|
App::I.async_start();
|
|
auto node = new NodeDialogCloudItem;
|
|
node->m_manager = m_manager;
|
|
node->init();
|
|
node->m_text->set_text(n.c_str());
|
|
node->m_path = data_path + "/" + n;
|
|
node->m_file_name = n;
|
|
auto image_tex = node->find<NodeImageTexture>("thumb-tex");
|
|
image_tex->tex.destroy();
|
|
image_tex->tex.create(thumb);
|
|
container->add_child(node);
|
|
App::I.async_end();
|
|
|
|
// node->on_selected = [&](NodeDialogCloudItem* target) {
|
|
// if (target == current)
|
|
// return;
|
|
// selected_path = target->m_path;
|
|
// selected_file = target->m_file_name;
|
|
// selected_name = selected_file.substr(0, selected_file.length() - 5);
|
|
// if (current)
|
|
// current->m_selected = false;
|
|
// current = target;
|
|
// };
|
|
|
|
// load thumb
|
|
// ui::Image thumb = ui::Canvas::I->thumbnail_read(node->m_path);
|
|
|
|
}
|
|
curl_easy_cleanup(curl);
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
Node* NodeDialogCloudItem::clone_instantiate() const
|
|
{
|
|
return new NodeDialogCloudItem;
|
|
}
|
|
void NodeDialogCloudItem::clone_finalize(Node* dest) const
|
|
{
|
|
NodeDialogCloudItem* n = static_cast<NodeDialogCloudItem*>(dest);
|
|
n->init_controls();
|
|
}
|
|
void NodeDialogCloudItem::init()
|
|
{
|
|
auto tpl = static_cast<const NodeBorder*>(init_template("dialog-cloud-item"));
|
|
m_color = tpl->m_color;
|
|
m_border_color = tpl->m_border_color;
|
|
m_thinkness = tpl->m_thinkness;
|
|
init_controls();
|
|
}
|
|
void NodeDialogCloudItem::init_controls()
|
|
{
|
|
m_text = find<NodeText>("title");
|
|
}
|
|
void NodeDialogCloudItem::loaded()
|
|
{
|
|
|
|
}
|
|
void NodeDialogCloudItem::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 NodeDialogCloudItem::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;
|
|
}
|