fix floating panels and iOS export picking
This commit is contained in:
@@ -161,7 +161,8 @@ public:
|
||||
void pick_image(std::function<void(std::string path)> callback);
|
||||
void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
#if __IOS__
|
||||
void pick_file_save(const std::string& type, std::function<void(std::string path)> writer);
|
||||
void pick_file_save(const std::string& type, std::function<void(std::string path)> writer,
|
||||
std::function<void(bool saved)> callback);
|
||||
#else
|
||||
void pick_file_save(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
#endif
|
||||
|
||||
@@ -609,9 +609,15 @@ void App::dialog_ppbr_export()
|
||||
info.descr = dialog->txt_descr->m_text;
|
||||
info.header_image = dialog->m_header_image;
|
||||
#if __IOS__
|
||||
App::I->pick_file_save("ppbr", [this, dialog, info] (std::string path) {
|
||||
presets->export_ppbr(path, info);
|
||||
});
|
||||
App::I->pick_file_save("ppbr",
|
||||
[this, dialog, info] (std::string path) {
|
||||
presets->export_ppbr(path, info);
|
||||
},
|
||||
[dialog] (bool saved) {
|
||||
if (saved)
|
||||
dialog->destroy();
|
||||
}
|
||||
);
|
||||
#else
|
||||
App::I->pick_file_save({ "ppbr" }, [this, dialog, info] (std::string path) {
|
||||
std::thread([this, path, dialog, info] {
|
||||
|
||||
@@ -194,25 +194,31 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
void App::pick_file_save(const std::string& type, std::function<void(std::string)> writer)
|
||||
void App::pick_file_save(const std::string& type, std::function<void(std::string)> writer,
|
||||
std::function<void(bool saved)> callback)
|
||||
{
|
||||
redraw = true;
|
||||
std::thread([=]{
|
||||
auto mb = input_box("Insert", "File name");
|
||||
std::string placeholder = "name." + type;
|
||||
mb->m_field_text->set_text(placeholder.c_str());
|
||||
mb->on_submit = [this, writer, type] (Node* target, std::string name) {
|
||||
std::string ext = "." + type;
|
||||
std::string path = data_path + "/" + name;
|
||||
if (name.find(ext) == std::string::npos)
|
||||
path += ext;
|
||||
auto mb = input_box("Insert", "File name");
|
||||
std::string placeholder = "name." + type;
|
||||
mb->m_field_text->set_text(placeholder.c_str());
|
||||
mb->on_submit = [this, writer, type, callback] (Node* target, std::string name) {
|
||||
std::string ext = "." + type;
|
||||
std::string path = data_path + "/" + name;
|
||||
if (name.find(ext) == std::string::npos)
|
||||
path += ext;
|
||||
std::thread([=]{
|
||||
writer(path);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[ios_view pick_file_save:path];
|
||||
});
|
||||
target->destroy();
|
||||
};
|
||||
}).detach();
|
||||
callback(true);
|
||||
}).detach();
|
||||
};
|
||||
mb->btn_cancel->on_click = [=] (Node* target) {
|
||||
callback(false);
|
||||
target->destroy();
|
||||
};
|
||||
}
|
||||
#else
|
||||
void App::pick_file_save(std::vector<std::string> types, std::function<void (std::string)> callback)
|
||||
|
||||
@@ -252,6 +252,7 @@ void App::init_sidebar()
|
||||
}
|
||||
layout[main_id]->add_child(stroke);
|
||||
stroke->SetSize(350, glm::max(100.f, screen.y - pos.y - 50.f));
|
||||
stroke->find("title")->SetVisibility(true);
|
||||
auto tick = layout[main_id]->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
tick->SetSize(32, 16);
|
||||
@@ -295,6 +296,7 @@ void App::init_sidebar()
|
||||
auto screen = layout[main_id]->m_size;
|
||||
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x * 0.5f, button->m_size.y);
|
||||
layout[main_id]->add_child(color);
|
||||
color->find("title")->SetVisibility(true);
|
||||
color->SetSize(350, 350);
|
||||
auto tick = layout[main_id]->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
@@ -320,6 +322,7 @@ void App::init_sidebar()
|
||||
button->on_click = [this, button](Node*) {
|
||||
auto screen = layout[main_id]->m_size;
|
||||
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x * 0.5f, button->m_size.y);
|
||||
layers->find("title")->SetVisibility(true);
|
||||
layers->SetSize(350, YGUndefined);
|
||||
if (layers->m_parent)
|
||||
{
|
||||
@@ -356,6 +359,7 @@ void App::init_sidebar()
|
||||
button->on_click = [this, button](Node*) {
|
||||
auto screen = layout[main_id]->m_size;
|
||||
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x * 0.5f, button->m_size.y);
|
||||
grid->find("title")->SetVisibility(true);
|
||||
grid->SetSize(350, YGUndefined);
|
||||
if (grid->m_parent)
|
||||
{
|
||||
@@ -776,6 +780,7 @@ void App::init_menu_tools()
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->SetMinHeight(300);
|
||||
fpanel->SetMinWidth(100);
|
||||
fpanel->m_title->set_text("Brushes");
|
||||
if (!floating_presets)
|
||||
{
|
||||
floating_presets = fpanel->m_container->add_child_ref<NodePanelBrushPreset>();
|
||||
@@ -805,12 +810,13 @@ void App::init_menu_tools()
|
||||
fpanel->m_class = NodePanelFloating::kClass::Color;
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->SetMinHeight(300);
|
||||
fpanel->m_title->set_text("Color Picker");
|
||||
if (!floating_color)
|
||||
{
|
||||
floating_color = fpanel->m_container->add_child_ref<NodePanelColor>();
|
||||
floating_color->SetHeightP(100);
|
||||
//floating_color->SetMinHeight(300);
|
||||
floating_color->find("title")->destroy();
|
||||
floating_color->find("title")->SetVisibility(false);
|
||||
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = color;
|
||||
brush_update(true, false);
|
||||
@@ -830,9 +836,11 @@ void App::init_menu_tools()
|
||||
fpanel->m_class = NodePanelFloating::kClass::ColorAdv;
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->SetWidth(300);
|
||||
fpanel->m_title->set_text("Color Picker");
|
||||
if (!floating_picker)
|
||||
{
|
||||
floating_picker = fpanel->m_container->add_child_ref<NodeColorPicker>();
|
||||
//floating_picker->find("title")->SetVisibility(false);
|
||||
//floating_picker->SetHeightP(100);
|
||||
//floating_picker->SetWidth(250);
|
||||
floating_picker->m_autohide = false;
|
||||
@@ -856,11 +864,13 @@ void App::init_menu_tools()
|
||||
fpanel->SetMinHeight(100);
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->m_container->add_child(layers);
|
||||
fpanel->m_title->set_text("Layers");
|
||||
layers->SetPositioning(YGPositionTypeRelative);
|
||||
layers->SetPosition(0, 0);
|
||||
layers->SetWidthP(100);
|
||||
layers->SetHeightP(100);
|
||||
layers->SetFlexShrink(0);
|
||||
layers->find("title")->SetVisibility(false);
|
||||
|
||||
popup_exp->destroy();
|
||||
popup_time->destroy();
|
||||
@@ -872,10 +882,12 @@ void App::init_menu_tools()
|
||||
fpanel->m_class = NodePanelFloating::kClass::Brush;
|
||||
fpanel->m_container->add_child(stroke);
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->m_title->set_text("Brush Settings");
|
||||
stroke->SetPositioning(YGPositionTypeRelative);
|
||||
stroke->SetPosition(0, 0);
|
||||
stroke->SetWidthP(100);
|
||||
stroke->SetHeightP(100);
|
||||
stroke->find("title")->SetVisibility(false);
|
||||
|
||||
popup_exp->destroy();
|
||||
popup_time->destroy();
|
||||
@@ -887,10 +899,12 @@ void App::init_menu_tools()
|
||||
fpanel->m_class = NodePanelFloating::kClass::Grids;
|
||||
fpanel->m_container->add_child(grid);
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->m_title->set_text("Grid");
|
||||
grid->SetPositioning(YGPositionTypeRelative);
|
||||
grid->SetPosition(0, 0);
|
||||
grid->SetWidthP(100);
|
||||
grid->SetHeightP(100);
|
||||
grid->find("title")->SetVisibility(false);
|
||||
|
||||
popup_exp->destroy();
|
||||
popup_time->destroy();
|
||||
@@ -1410,6 +1424,7 @@ void App::ui_save()
|
||||
fd->set("pos", Serializer::Vec2(f->GetPosition()));
|
||||
fd->set("size", Serializer::Vec2(f->m_size));
|
||||
fd->set("class", Serializer::Integer((int)f->m_class));
|
||||
fd->set("title", Serializer::CString(f->m_title->m_text));
|
||||
}
|
||||
}
|
||||
d.set("floatings", list_floatings);
|
||||
@@ -1423,6 +1438,7 @@ void App::ui_save()
|
||||
fd->class_id = "ui-dpl";
|
||||
fd->set("size", Serializer::Vec2(f->m_size));
|
||||
fd->set("class", Serializer::Integer((int)f->m_class));
|
||||
fd->set("title", Serializer::CString(f->m_title->m_text));
|
||||
}
|
||||
}
|
||||
d.set("drop-left", list_drop_left);
|
||||
@@ -1436,6 +1452,7 @@ void App::ui_save()
|
||||
fd->class_id = "ui-dpr";
|
||||
fd->set("size", Serializer::Vec2(f->m_size));
|
||||
fd->set("class", Serializer::Integer((int)f->m_class));
|
||||
fd->set("title", Serializer::CString(f->m_title->m_text));
|
||||
}
|
||||
}
|
||||
d.set("drop-right", list_drop_right);
|
||||
@@ -1471,6 +1488,9 @@ void App::ui_restore()
|
||||
auto size = ld->value<Serializer::Vec2>("size");
|
||||
auto cls = static_cast<NodePanelFloating::kClass>(ld->value<Serializer::Integer>("class"));
|
||||
auto f = floatings->add_child<NodePanelFloating>();
|
||||
std::string title = "Floating Panel";
|
||||
ld->value<Serializer::CString>("title", title);
|
||||
f->m_title->set_text(title.c_str());
|
||||
switch (cls)
|
||||
{
|
||||
case NodePanelFloating::kClass::Presets:
|
||||
@@ -1491,7 +1511,7 @@ void App::ui_restore()
|
||||
{
|
||||
floating_color = f->m_container->add_child_ref<NodePanelColor>();
|
||||
floating_color->SetHeightP(100);
|
||||
floating_color->find("title")->destroy();
|
||||
floating_color->find("title")->SetVisibility(false);
|
||||
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = color;
|
||||
brush_update(true, false);
|
||||
@@ -1512,6 +1532,7 @@ void App::ui_restore()
|
||||
f->m_container->add_child(layers);
|
||||
f->SetMinHeight(100);
|
||||
f->SetHeight(300);
|
||||
layers->find("title")->SetVisibility(false);
|
||||
layers->SetPositioning(YGPositionTypeRelative);
|
||||
layers->SetPosition(0, 0);
|
||||
layers->SetWidthP(100);
|
||||
@@ -1520,6 +1541,7 @@ void App::ui_restore()
|
||||
break;
|
||||
case NodePanelFloating::kClass::Brush:
|
||||
f->m_container->add_child(stroke);
|
||||
stroke->find("title")->SetVisibility(false);
|
||||
stroke->SetPositioning(YGPositionTypeRelative);
|
||||
stroke->SetPosition(0, 0);
|
||||
stroke->SetWidthP(100);
|
||||
@@ -1527,6 +1549,7 @@ void App::ui_restore()
|
||||
break;
|
||||
case NodePanelFloating::kClass::Grids:
|
||||
f->m_container->add_child(grid);
|
||||
grid->find("title")->SetVisibility(false);
|
||||
grid->SetPositioning(YGPositionTypeRelative);
|
||||
grid->SetPosition(0, 0);
|
||||
grid->SetWidthP(100);
|
||||
@@ -1549,6 +1572,9 @@ void App::ui_restore()
|
||||
auto size = ld->value<Serializer::Vec2>("size");
|
||||
auto cls = static_cast<NodePanelFloating::kClass>(ld->value<Serializer::Integer>("class"));
|
||||
auto f = drop_left->add_child<NodePanelFloating>();
|
||||
std::string title = "Floating Panel";
|
||||
ld->value<Serializer::CString>("title", title);
|
||||
f->m_title->set_text(title.c_str());
|
||||
switch (cls)
|
||||
{
|
||||
case NodePanelFloating::kClass::Presets:
|
||||
@@ -1626,6 +1652,9 @@ void App::ui_restore()
|
||||
auto size = ld->value<Serializer::Vec2>("size");
|
||||
auto cls = static_cast<NodePanelFloating::kClass>(ld->value<Serializer::Integer>("class"));
|
||||
auto f = drop_right->add_child<NodePanelFloating>();
|
||||
std::string title = "Floating Panel";
|
||||
ld->value<Serializer::CString>("title", title);
|
||||
f->m_title->set_text(title.c_str());
|
||||
switch (cls)
|
||||
{
|
||||
case NodePanelFloating::kClass::Presets:
|
||||
|
||||
@@ -27,6 +27,7 @@ void NodeDialogExportPPBR::init()
|
||||
|
||||
void NodeDialogExportPPBR::init_controls()
|
||||
{
|
||||
m_title = find<NodeText>("title");
|
||||
btn_ok = find<NodeButton>("btn-ok");
|
||||
btn_cancel = find<NodeButton>("btn-cancel");
|
||||
btn_cancel->on_click = [this](Node*) {
|
||||
@@ -48,10 +49,10 @@ void NodeDialogExportPPBR::init_controls()
|
||||
};
|
||||
img_header = find<NodeImageTexture>("header-tex");
|
||||
txt_header_descr = find<NodeText>("header-descr");
|
||||
txt_author = find<NodeText>("info-author");
|
||||
txt_email = find<NodeText>("info-email");
|
||||
txt_url = find<NodeText>("info-url");
|
||||
txt_descr = find<NodeText>("info-descr");
|
||||
txt_author = find<NodeTextInput>("info-author");
|
||||
txt_email = find<NodeTextInput>("info-email");
|
||||
txt_url = find<NodeTextInput>("info-url");
|
||||
txt_descr = find<NodeTextInput>("info-descr");
|
||||
}
|
||||
|
||||
void NodeDialogExportPPBR::open_header()
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "node_button.h"
|
||||
#include "node_combobox.h"
|
||||
#include "node_text.h"
|
||||
#include "node_text_input.h"
|
||||
#include "node_image_texture.h"
|
||||
|
||||
class NodeDialogExportPPBR : public NodeBorder
|
||||
@@ -13,13 +14,14 @@ public:
|
||||
NodeButton* btn_header_open;
|
||||
NodeButton* btn_header_clear;
|
||||
NodeButton* btn_header_gen;
|
||||
NodeText* m_title;
|
||||
NodeImageTexture* img_header;
|
||||
std::shared_ptr<Image> m_header_image;
|
||||
NodeText* txt_header_descr;
|
||||
NodeText* txt_author;
|
||||
NodeText* txt_descr;
|
||||
NodeText* txt_url;
|
||||
NodeText* txt_email;
|
||||
NodeTextInput* txt_author;
|
||||
NodeTextInput* txt_descr;
|
||||
NodeTextInput* txt_url;
|
||||
NodeTextInput* txt_email;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void clone_finalize(Node* dest) const override;
|
||||
virtual void init() override;
|
||||
|
||||
@@ -54,4 +54,5 @@ void NodeInputBox::added(Node* parent)
|
||||
{
|
||||
Node::added(parent);
|
||||
mouse_capture();
|
||||
m_field_text->key_capture();
|
||||
}
|
||||
|
||||
@@ -693,9 +693,9 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path, const PPBRInfo&
|
||||
auto base = m[1].str();
|
||||
auto name = m[2].str();
|
||||
auto ext = m[3].str();
|
||||
std::string out_path = base + "/" + name;
|
||||
std::string out_path = base + "/" + name + "_data";
|
||||
|
||||
Asset::create_dir(out_path);
|
||||
bool path_created = Asset::create_dir(out_path);
|
||||
|
||||
std::ofstream f(path, std::ios::binary);
|
||||
if (f.good())
|
||||
@@ -744,7 +744,8 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path, const PPBRInfo&
|
||||
if (has_header_image)
|
||||
{
|
||||
sw << *info_data.header_image;
|
||||
info_data.header_image->save_jpg(out_path + "/header.jpg", 75);
|
||||
if (path_created)
|
||||
info_data.header_image->save_jpg(out_path + "/header.jpg", 75);
|
||||
}
|
||||
|
||||
pb->increment();
|
||||
@@ -762,7 +763,8 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path, const PPBRInfo&
|
||||
Image img = pr->render_to_image();
|
||||
img.file_name = pr->m_brush->m_name;
|
||||
sw << img;
|
||||
img.save_jpg(fmt::format(out_path + "/thumb-{:04d}.jpg", thumb_counter), 75);
|
||||
if (path_created)
|
||||
img.save_jpg(fmt::format(out_path + "/thumb-{:04d}.jpg", thumb_counter), 75);
|
||||
thumb_counter++;
|
||||
pb->increment();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ void NodePanelFloating::init_controls()
|
||||
m_flood_events = true;
|
||||
m_capture_children = true;
|
||||
m_container = find("container");
|
||||
m_title = find<NodeText>("title");
|
||||
m_button_minimize = find<NodeButton>("button-minimize");
|
||||
m_button_minimize->on_click = [this](Node*) {
|
||||
m_container->ToggleVisibility();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "node_border.h"
|
||||
#include "node_button.h"
|
||||
#include "node_text.h"
|
||||
|
||||
class NodePanelFloating : public NodeBorder
|
||||
{
|
||||
@@ -15,6 +16,7 @@ class NodePanelFloating : public NodeBorder
|
||||
std::shared_ptr<NodeBorder> m_drop_placeholder;
|
||||
public:
|
||||
Node* m_container;
|
||||
NodeText* m_title;
|
||||
std::weak_ptr<Node> m_dock;
|
||||
using this_class = NodePanelFloating;
|
||||
using parent = NodeBorder;
|
||||
|
||||
@@ -577,6 +577,8 @@ std::wstring str2wstr(const std::string& str)
|
||||
//const char* ptr = str.c_str();
|
||||
//std::mbsrtowcs((wchar_t*)converted.data(), &ptr, converted.capacity(), &st);
|
||||
//return converted;
|
||||
if (str.empty())
|
||||
return {};
|
||||
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
||||
return converterX.from_bytes(str);
|
||||
@@ -590,6 +592,8 @@ std::string wstr2str(const std::wstring & wstr)
|
||||
//const wchar_t * wptr = wstr.c_str();
|
||||
//std::wcsrtombs((char*)converted.data(), &wptr, converted.capacity(), &st);
|
||||
//return converted;
|
||||
if (wstr.empty())
|
||||
return {};
|
||||
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
||||
return converterX.to_bytes(wstr);
|
||||
|
||||
Reference in New Issue
Block a user