settings file and save/restore ui state
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "node_progress_bar.h"
|
||||
#include "node_dialog_picker.h"
|
||||
#include "node_panel_floating.h"
|
||||
#include "settings.h"
|
||||
|
||||
void App::title_update()
|
||||
{
|
||||
@@ -511,7 +512,7 @@ void App::init_menu_file()
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-import"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
App::I.pick_file({ "JPG", "PNG", "ABR" }, [this](std::string path){
|
||||
pick_file({ "JPG", "PNG", "ABR" }, [this](std::string path){
|
||||
std::string name, base, ext;
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
|
||||
std::smatch m;
|
||||
@@ -551,8 +552,8 @@ void App::init_menu_file()
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-open"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
//dialog_open();
|
||||
App::I.pick_file({"ppi","PPI"}, [this](std::string path){
|
||||
App::I.open_document(path);
|
||||
pick_file({"ppi","PPI"}, [this](std::string path){
|
||||
open_document(path);
|
||||
});
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
@@ -723,18 +724,18 @@ void App::init_menu_experimental()
|
||||
{
|
||||
if (auto text = popup_time->find<NodeText>("menu-label"))
|
||||
{
|
||||
text->set_text(App::I.rec_running ? "Stop Recording" : "Start Recording");
|
||||
text->set_text(rec_running ? "Stop Recording" : "Start Recording");
|
||||
}
|
||||
}
|
||||
|
||||
popup_time->find<NodeButtonCustom>("timelapse-start")->on_click = [this, popup_time, popup_exp](Node*) {
|
||||
App::I.rec_running ? App::I.rec_stop() : App::I.rec_start();
|
||||
rec_running ? rec_stop() : rec_start();
|
||||
popup_time->destroy();
|
||||
popup_exp->destroy();
|
||||
};
|
||||
|
||||
popup_time->find<NodeButtonCustom>("timelapse-clear")->on_click = [this, popup_time, popup_exp](Node*) {
|
||||
App::I.rec_clear();
|
||||
rec_clear();
|
||||
popup_time->destroy();
|
||||
popup_exp->destroy();
|
||||
};
|
||||
@@ -742,7 +743,7 @@ void App::init_menu_experimental()
|
||||
popup_time->find<NodeButtonCustom>("timelapse-export")->on_click = [this, popup_time, popup_exp](Node*) {
|
||||
popup_time->destroy();
|
||||
popup_exp->destroy();
|
||||
App::I.rec_export("");
|
||||
rec_export("");
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -783,6 +784,7 @@ void App::init_menu_experimental()
|
||||
if (visible(floating_presets.get()))
|
||||
return;
|
||||
auto fpanel = floatings_container->add_child<NodePanelFloating>();
|
||||
fpanel->m_class = NodePanelFloating::kClass::Presets;
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->SetMinHeight(300);
|
||||
if (!floating_presets)
|
||||
@@ -811,6 +813,7 @@ void App::init_menu_experimental()
|
||||
if (visible(floating_color.get()))
|
||||
return;
|
||||
auto fpanel = floatings_container->add_child<NodePanelFloating>();
|
||||
fpanel->m_class = NodePanelFloating::kClass::Color;
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->SetMinHeight(300);
|
||||
if (!floating_color)
|
||||
@@ -835,6 +838,7 @@ void App::init_menu_experimental()
|
||||
if (visible(floating_picker.get()))
|
||||
return;
|
||||
auto fpanel = floatings_container->add_child<NodePanelFloating>();
|
||||
fpanel->m_class = NodePanelFloating::kClass::ColorAdv;
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->SetWidth(300);
|
||||
if (!floating_picker)
|
||||
@@ -856,21 +860,10 @@ void App::init_menu_experimental()
|
||||
popup_exp->destroy();
|
||||
};
|
||||
popup_time->find<NodeButtonCustom>("panel-layers")->on_click = [this, popup_time, popup_exp, visible](Node*) {
|
||||
//if (visible(floating_layers.get()))
|
||||
// return;
|
||||
//auto fpanel = floatings_container->add_child<NodePanelFloating>();
|
||||
//if (!floating_layers)
|
||||
//{
|
||||
// floating_layers = fpanel->m_container->add_child_ref<NodePanelLayer>();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// fpanel->m_container->add_child(floating_layers);
|
||||
//}
|
||||
|
||||
if (visible(layers.get()))
|
||||
return;
|
||||
auto fpanel = floatings_container->add_child<NodePanelFloating>();
|
||||
fpanel->m_class = NodePanelFloating::kClass::Layers;
|
||||
fpanel->SetMinHeight(100);
|
||||
fpanel->SetHeight(300);
|
||||
fpanel->m_container->add_child(layers);
|
||||
@@ -887,10 +880,13 @@ void App::init_menu_experimental()
|
||||
if (visible(stroke.get()))
|
||||
return;
|
||||
auto fpanel = floatings_container->add_child<NodePanelFloating>();
|
||||
fpanel->m_class = NodePanelFloating::kClass::Brush;
|
||||
fpanel->m_container->add_child(stroke);
|
||||
fpanel->SetHeight(300);
|
||||
stroke->SetPositioning(YGPositionTypeRelative);
|
||||
stroke->SetPosition(0, 0);
|
||||
stroke->SetWidthP(100);
|
||||
stroke->SetHeightP(100);
|
||||
|
||||
popup_time->destroy();
|
||||
popup_exp->destroy();
|
||||
@@ -899,6 +895,7 @@ void App::init_menu_experimental()
|
||||
if (visible(grid.get()))
|
||||
return;
|
||||
auto fpanel = floatings_container->add_child<NodePanelFloating>();
|
||||
fpanel->m_class = NodePanelFloating::kClass::Grids;
|
||||
fpanel->m_container->add_child(grid);
|
||||
fpanel->SetHeight(300);
|
||||
grid->SetPositioning(YGPositionTypeRelative);
|
||||
@@ -914,11 +911,16 @@ void App::init_menu_experimental()
|
||||
|
||||
if (auto rtl_btn = popup_exp->find<NodeButtonCustom>("experimental-rtl"))
|
||||
{
|
||||
auto ui = main->find("central-row");
|
||||
NodeCheckBox* cb = rtl_btn->find<NodeCheckBox>("experimental-rtl-check");
|
||||
cb->set_value(ui->GetRTL() == YGDirectionRTL, false);
|
||||
|
||||
rtl_btn->on_click = [this, popup_exp, rtl_btn](Node* b)
|
||||
{
|
||||
NodeCheckBox* cb = rtl_btn->find<NodeCheckBox>("experimental-rtl-check");
|
||||
cb->set_value(!cb->checked, true);
|
||||
};
|
||||
|
||||
rtl_btn->find<NodeCheckBox>("experimental-rtl-check")->on_value_changed = [this, main](Node*, bool checked)
|
||||
{
|
||||
auto ui = main->find("central-row");
|
||||
@@ -928,25 +930,29 @@ void App::init_menu_experimental()
|
||||
|
||||
if (auto vr_btn = popup_exp->find<NodeButtonCustom>("experimental-vr"))
|
||||
{
|
||||
NodeCheckBox* cb = vr_btn->find<NodeCheckBox>("experimental-vr-check");
|
||||
cb->set_value(has_vr);
|
||||
|
||||
vr_btn->on_click = [this, popup_exp, vr_btn](Node* b)
|
||||
{
|
||||
NodeCheckBox* cb = vr_btn->find<NodeCheckBox>("experimental-vr-check");
|
||||
cb->set_value(!cb->checked, true);
|
||||
};
|
||||
|
||||
vr_btn->find<NodeCheckBox>("experimental-vr-check")->on_value_changed = [this, main](Node* target, bool checked)
|
||||
{
|
||||
if (checked)
|
||||
{
|
||||
if (!App::I.vr_start())
|
||||
if (!vr_start())
|
||||
{
|
||||
auto cb = static_cast<NodeCheckBox*>(target);
|
||||
cb->set_value(false);
|
||||
App::I.message_box("VR Failed", "Couldn't start Virtual Reality mode");
|
||||
message_box("VR Failed", "Couldn't start Virtual Reality mode");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
App::I.vr_stop();
|
||||
vr_stop();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1006,7 +1012,7 @@ void App::init_menu_about()
|
||||
{
|
||||
b->on_click = [this, popup](Node*) {
|
||||
LOG("crashing");
|
||||
App::I.crash_test();
|
||||
crash_test();
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
@@ -1038,7 +1044,7 @@ void App::init_menu_about()
|
||||
LOG("%lld ms", ms);
|
||||
static char str[256];
|
||||
sprintf(str, "Time %lld ms", ms);
|
||||
App::I.message_box("Performance test", str);
|
||||
message_box("Performance test", str);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
@@ -1302,8 +1308,9 @@ void App::initLayout()
|
||||
//picker->SetHeightP(100);
|
||||
//color->find("title")->destroy();
|
||||
*/
|
||||
ui_restore();
|
||||
|
||||
App::I.redraw = true;
|
||||
redraw = true;
|
||||
};
|
||||
|
||||
LOG("initializing layout xml");
|
||||
@@ -1316,3 +1323,304 @@ void App::initLayout()
|
||||
layout.load("data/layout.xml");
|
||||
LOG("initializing layout completed");
|
||||
}
|
||||
|
||||
void App::ui_save()
|
||||
{
|
||||
Serializer::Descriptor d;
|
||||
d.class_id = "ui-state";
|
||||
|
||||
Serializer::List list_floatings;
|
||||
for (auto const& c : layout[main_id]->find("floatings")->m_children)
|
||||
{
|
||||
if (auto const& f = std::dynamic_pointer_cast<NodePanelFloating>(c))
|
||||
{
|
||||
auto fd = list_floatings.add<Serializer::Descriptor>();
|
||||
fd->class_id = "ui-flt";
|
||||
fd->set("pos", Serializer::Vec2(f->GetPosition()));
|
||||
fd->set("size", Serializer::Vec2(f->m_size));
|
||||
fd->set("class", Serializer::Integer((int)f->m_class));
|
||||
}
|
||||
}
|
||||
d.set("floatings", list_floatings);
|
||||
|
||||
Serializer::List list_drop_left;
|
||||
for (auto const& c : layout[main_id]->find("drop-left")->m_children)
|
||||
{
|
||||
if (auto const& f = std::dynamic_pointer_cast<NodePanelFloating>(c))
|
||||
{
|
||||
auto fd = list_drop_left.add<Serializer::Descriptor>();
|
||||
fd->class_id = "ui-dpl";
|
||||
fd->set("size", Serializer::Vec2(f->m_size));
|
||||
fd->set("class", Serializer::Integer((int)f->m_class));
|
||||
}
|
||||
}
|
||||
d.set("drop-left", list_drop_left);
|
||||
|
||||
Serializer::List list_drop_right;
|
||||
for (auto const& c : layout[main_id]->find("drop-right")->m_children)
|
||||
{
|
||||
if (auto const& f = std::dynamic_pointer_cast<NodePanelFloating>(c))
|
||||
{
|
||||
auto fd = list_drop_right.add<Serializer::Descriptor>();
|
||||
fd->class_id = "ui-dpr";
|
||||
fd->set("size", Serializer::Vec2(f->m_size));
|
||||
fd->set("class", Serializer::Integer((int)f->m_class));
|
||||
}
|
||||
}
|
||||
d.set("drop-right", list_drop_right);
|
||||
|
||||
Settings::set("ui", d);
|
||||
Settings::set("ui-rtl", Serializer::Integer(layout[main_id]->find("central-row")->GetRTL()));
|
||||
|
||||
#if _WIN32
|
||||
extern void win32_save_window_state();
|
||||
win32_save_window_state();
|
||||
#endif
|
||||
|
||||
Settings::save();
|
||||
}
|
||||
|
||||
void App::ui_restore()
|
||||
{
|
||||
if (Settings::has("ui-rtl"))
|
||||
layout[main_id]->find("central-row")->SetRTL((YGDirection)Settings::value<Serializer::Integer>("ui-rtl"));
|
||||
|
||||
if (!Settings::has("ui"))
|
||||
return;
|
||||
auto floatings = layout[main_id]->find_ref("floatings");
|
||||
auto drop_left = layout[main_id]->find_ref("drop-left");
|
||||
auto drop_right = layout[main_id]->find_ref("drop-right");
|
||||
auto d = Settings::get<Serializer::Descriptor>("ui");
|
||||
for (auto const& l : d->get<Serializer::List>("floatings")->items)
|
||||
{
|
||||
auto ld = std::static_pointer_cast<Serializer::Descriptor>(l);
|
||||
auto pos = ld->value<Serializer::Vec2>("pos");
|
||||
auto size = ld->value<Serializer::Vec2>("size");
|
||||
auto cls = static_cast<NodePanelFloating::kClass>(ld->value<Serializer::Integer>("class"));
|
||||
auto f = floatings->add_child<NodePanelFloating>();
|
||||
switch (cls)
|
||||
{
|
||||
case NodePanelFloating::kClass::Presets:
|
||||
{
|
||||
auto floating_presets = f->m_container->add_child<NodePanelBrushPreset>();
|
||||
floating_presets->SetHeightP(100);
|
||||
floating_presets->find("toolbar")->destroy();
|
||||
floating_presets->on_brush_changed = [this](Node* target, std::shared_ptr<Brush>& b) {
|
||||
auto c = Canvas::I->m_current_brush->m_tip_color;
|
||||
*Canvas::I->m_current_brush = *b;
|
||||
Canvas::I->m_current_brush->m_tip_color = c;
|
||||
Canvas::I->m_current_brush->load();
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::Color:
|
||||
{
|
||||
auto floating_color = f->m_container->add_child<NodePanelColor>();
|
||||
floating_color->SetHeightP(100);
|
||||
floating_color->find("title")->destroy();
|
||||
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = color;
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::ColorAdv:
|
||||
{
|
||||
floating_picker = f->m_container->add_child_ref<NodeColorPicker>();
|
||||
floating_picker->m_autohide = false;
|
||||
floating_picker->on_color_change = [this](Node* target, glm::vec3 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = glm::vec4(color, 1.f);
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::Layers:
|
||||
f->m_container->add_child(layers);
|
||||
f->SetMinHeight(100);
|
||||
f->SetHeight(300);
|
||||
layers->SetPositioning(YGPositionTypeRelative);
|
||||
layers->SetPosition(0, 0);
|
||||
layers->SetWidthP(100);
|
||||
layers->SetHeightP(100);
|
||||
layers->SetFlexShrink(0);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Brush:
|
||||
f->m_container->add_child(stroke);
|
||||
stroke->SetPositioning(YGPositionTypeRelative);
|
||||
stroke->SetPosition(0, 0);
|
||||
stroke->SetWidthP(100);
|
||||
stroke->SetHeightP(100);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Grids:
|
||||
f->m_container->add_child(grid);
|
||||
grid->SetPositioning(YGPositionTypeRelative);
|
||||
grid->SetPosition(0, 0);
|
||||
grid->SetWidthP(100);
|
||||
grid->SetHeightP(100);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Generic:
|
||||
default:
|
||||
f->m_container->add_child<Node>();
|
||||
break;
|
||||
}
|
||||
f->m_class = cls;
|
||||
f->SetSize(size);
|
||||
f->SetPosition(pos);
|
||||
f->SetPositioning(YGPositionTypeAbsolute);
|
||||
}
|
||||
|
||||
for (auto const& l : d->get<Serializer::List>("drop-left")->items)
|
||||
{
|
||||
auto ld = std::static_pointer_cast<Serializer::Descriptor>(l);
|
||||
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>();
|
||||
switch (cls)
|
||||
{
|
||||
case NodePanelFloating::kClass::Presets:
|
||||
{
|
||||
auto floating_presets = f->m_container->add_child<NodePanelBrushPreset>();
|
||||
floating_presets->SetHeightP(100);
|
||||
floating_presets->find("toolbar")->destroy();
|
||||
floating_presets->on_brush_changed = [this](Node* target, std::shared_ptr<Brush>& b) {
|
||||
auto c = Canvas::I->m_current_brush->m_tip_color;
|
||||
*Canvas::I->m_current_brush = *b;
|
||||
Canvas::I->m_current_brush->m_tip_color = c;
|
||||
Canvas::I->m_current_brush->load();
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::Color:
|
||||
{
|
||||
auto floating_color = f->m_container->add_child<NodePanelColor>();
|
||||
floating_color->SetHeightP(100);
|
||||
floating_color->find("title")->destroy();
|
||||
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = color;
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::ColorAdv:
|
||||
{
|
||||
floating_picker = f->m_container->add_child_ref<NodeColorPicker>();
|
||||
floating_picker->m_autohide = false;
|
||||
floating_picker->on_color_change = [this](Node* target, glm::vec3 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = glm::vec4(color, 1.f);
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::Layers:
|
||||
f->m_container->add_child(layers);
|
||||
layers->SetPositioning(YGPositionTypeRelative);
|
||||
layers->SetPosition(0, 0);
|
||||
layers->SetWidthP(100);
|
||||
layers->SetHeightP(100);
|
||||
layers->SetFlexShrink(0);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Brush:
|
||||
f->m_container->add_child(stroke);
|
||||
stroke->SetPositioning(YGPositionTypeRelative);
|
||||
stroke->SetPosition(0, 0);
|
||||
stroke->SetWidthP(100);
|
||||
stroke->SetHeightP(100);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Grids:
|
||||
f->m_container->add_child(grid);
|
||||
grid->SetPositioning(YGPositionTypeRelative);
|
||||
grid->SetPosition(0, 0);
|
||||
grid->SetWidthP(100);
|
||||
grid->SetHeightP(100);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Generic:
|
||||
default:
|
||||
f->m_container->add_child<Node>();
|
||||
break;
|
||||
}
|
||||
f->m_class = cls;
|
||||
f->m_dock = drop_left;
|
||||
f->SetPositioning(YGPositionTypeRelative);
|
||||
f->SetPosition(0, 0);
|
||||
f->SetSize(size);
|
||||
}
|
||||
|
||||
for (auto const& l : d->get<Serializer::List>("drop-right")->items)
|
||||
{
|
||||
auto ld = std::static_pointer_cast<Serializer::Descriptor>(l);
|
||||
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>();
|
||||
switch (cls)
|
||||
{
|
||||
case NodePanelFloating::kClass::Presets:
|
||||
{
|
||||
auto floating_presets = f->m_container->add_child<NodePanelBrushPreset>();
|
||||
floating_presets->SetHeightP(100);
|
||||
floating_presets->find("toolbar")->destroy();
|
||||
floating_presets->on_brush_changed = [this](Node* target, std::shared_ptr<Brush>& b) {
|
||||
auto c = Canvas::I->m_current_brush->m_tip_color;
|
||||
*Canvas::I->m_current_brush = *b;
|
||||
Canvas::I->m_current_brush->m_tip_color = c;
|
||||
Canvas::I->m_current_brush->load();
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::Color:
|
||||
{
|
||||
auto floating_color = f->m_container->add_child<NodePanelColor>();
|
||||
floating_color->SetHeightP(100);
|
||||
floating_color->find("title")->destroy();
|
||||
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = color;
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::ColorAdv:
|
||||
{
|
||||
floating_picker = f->m_container->add_child_ref<NodeColorPicker>();
|
||||
floating_picker->m_autohide = false;
|
||||
floating_picker->on_color_change = [this](Node* target, glm::vec3 color) {
|
||||
Canvas::I->m_current_brush->m_tip_color = glm::vec4(color, 1.f);
|
||||
brush_update();
|
||||
};
|
||||
break;
|
||||
}
|
||||
case NodePanelFloating::kClass::Layers:
|
||||
f->m_container->add_child(layers);
|
||||
layers->SetPositioning(YGPositionTypeRelative);
|
||||
layers->SetPosition(0, 0);
|
||||
layers->SetWidthP(100);
|
||||
layers->SetHeightP(100);
|
||||
layers->SetFlexShrink(0);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Brush:
|
||||
f->m_container->add_child(stroke);
|
||||
stroke->SetPositioning(YGPositionTypeRelative);
|
||||
stroke->SetPosition(0, 0);
|
||||
stroke->SetWidthP(100);
|
||||
stroke->SetHeightP(100);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Grids:
|
||||
f->m_container->add_child(grid);
|
||||
grid->SetPositioning(YGPositionTypeRelative);
|
||||
grid->SetPosition(0, 0);
|
||||
grid->SetWidthP(100);
|
||||
grid->SetHeightP(100);
|
||||
break;
|
||||
case NodePanelFloating::kClass::Generic:
|
||||
default:
|
||||
f->m_container->add_child<Node>();
|
||||
break;
|
||||
}
|
||||
f->m_class = cls;
|
||||
f->m_dock = drop_right;
|
||||
f->SetPositioning(YGPositionTypeRelative);
|
||||
f->SetPosition(0, 0);
|
||||
f->SetSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user