721 lines
27 KiB
C++
721 lines
27 KiB
C++
#include "pch.h"
|
|
#include "app.h"
|
|
#include "node_icon.h"
|
|
#include "node_dialog_open.h"
|
|
#include "node_text.h"
|
|
#include "node_progress_bar.h"
|
|
#include "node_dialog_picker.h"
|
|
|
|
using namespace ui;
|
|
|
|
static glm::vec4 color_button_normal{ .1, .1, .1, 1 };
|
|
static glm::vec4 color_button_hlight{ 1, .0, .0, 1 };
|
|
|
|
void App::title_update(std::string name, int resolution)
|
|
{
|
|
static char str[256];
|
|
snprintf(str, 256, "Panodoc: %s (%dpx)", doc_name.c_str(), resolution);
|
|
if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
|
|
docname->set_text(str);
|
|
}
|
|
|
|
void App::init_toolbar_main()
|
|
{
|
|
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-export"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
if (canvas)
|
|
{
|
|
canvas->m_canvas->export_equirectangular(data_path);
|
|
}
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-anim"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
if (canvas)
|
|
{
|
|
canvas->m_canvas->export_anim(data_path);
|
|
}
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-open"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
dialog_open();
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-save"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
dialog_save();
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-undo"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
ActionManager::undo();
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-redo"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
ActionManager::redo();
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-clean-memory"))
|
|
{
|
|
button->on_click = [this](Node*) {
|
|
ActionManager::clear();
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-clear"))
|
|
{
|
|
button->on_click = [this](Node*) {
|
|
//exit(0);
|
|
if (canvas)
|
|
canvas->m_canvas->clear({ 0, 0, 0, 0 });
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-popup"))
|
|
{
|
|
button->on_click = [this](Node*) {
|
|
msgbox = new NodeMessageBox();
|
|
msgbox->m_manager = &layout;
|
|
msgbox->init();
|
|
layout[main_id]->add_child(msgbox);
|
|
layout[main_id]->update();
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-settings"))
|
|
{
|
|
button->on_click = [this](Node*) {
|
|
settings = new NodeSettings();
|
|
settings->m_manager = &layout;
|
|
settings->init();
|
|
layout[main_id]->add_child(settings);
|
|
layout[main_id]->update();
|
|
};
|
|
}
|
|
}
|
|
|
|
void App::init_sidebar()
|
|
{
|
|
sidebar = layout[main_id]->find<NodeBorder>("sidebar");
|
|
panels = layout[main_id]->find<NodeScroll>("panels");
|
|
canvas = layout[main_id]->find<NodeCanvas>("paint-canvas");
|
|
canvas->data_path = data_path;
|
|
|
|
//brushes = layout[main_id]->find<NodePanelBrush>("panel-brush");
|
|
//layers = layout[main_id]->find<NodePanelLayer>("panel-layer");
|
|
//color = layout[main_id]->find<NodePanelColor>("panel-color");
|
|
//stroke = layout[main_id]->find<NodePanelStroke>("panel-stroke");
|
|
|
|
brushes = std::make_shared<NodePanelBrush>();
|
|
brushes->m_manager = &layout;
|
|
brushes->init();
|
|
brushes->create();
|
|
brushes->loaded();
|
|
|
|
layers = std::make_shared<NodePanelLayer>();
|
|
layers->m_manager = &layout;
|
|
layers->init();
|
|
layers->create();
|
|
layers->loaded();
|
|
|
|
color = std::make_shared<NodePanelColor>();
|
|
color->m_manager = &layout;
|
|
color->init();
|
|
color->create();
|
|
color->loaded();
|
|
|
|
stroke = std::make_shared<NodePanelStroke>();
|
|
stroke->m_manager = &layout;
|
|
stroke->init();
|
|
stroke->create();
|
|
stroke->loaded();
|
|
|
|
presets = std::make_shared<NodePanelBrushPreset>();
|
|
presets->m_manager = &layout;
|
|
presets->init();
|
|
presets->create();
|
|
presets->loaded();
|
|
|
|
// if (canvas)
|
|
// {
|
|
// ui::Canvas::I->m_current_brush.m_tip_color = color->m_color;
|
|
// stroke->m_canvas->draw_stroke();
|
|
// }
|
|
|
|
brushes->on_brush_changed = [this](Node* target, int index) {
|
|
ui::Canvas::I->m_current_brush.m_tex_id = brushes->get_texture_id(index);
|
|
ui::Canvas::I->m_current_brush.id = brushes->get_brush_id(index);
|
|
stroke->m_preview->draw_stroke();
|
|
};
|
|
presets->on_brush_changed = [this](Node* target, int index) {
|
|
auto b = presets->get_brush(index);
|
|
// don't change some params
|
|
b.m_tip_size = ui::Canvas::I->m_current_brush.m_tip_size;
|
|
b.m_tip_color = ui::Canvas::I->m_current_brush.m_tip_color;
|
|
ui::Canvas::I->m_current_brush = b;
|
|
stroke->m_preview->draw_stroke();
|
|
};
|
|
|
|
color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
|
ui::Canvas::I->m_current_brush.m_tip_color = color;
|
|
};
|
|
//
|
|
// stroke->on_stroke_change = [this](Node*target) {
|
|
// if (canvas)
|
|
// canvas->m_brush = stroke->m_canvas->m_brush;
|
|
// };
|
|
|
|
layers->on_layer_add = [this](Node*) {
|
|
canvas->m_canvas->layer_add(layers->m_layers.back()->m_label_text.c_str());
|
|
};
|
|
|
|
layers->on_layer_change = [this](Node*, int old_idx, int new_idx) {
|
|
canvas->m_canvas->m_current_layer_idx = canvas->m_canvas->m_order[new_idx];
|
|
};
|
|
|
|
layers->on_layer_order = [this](Node*, int old_idx, int new_idx) {
|
|
canvas->m_canvas->layer_order(old_idx, new_idx);
|
|
};
|
|
|
|
layers->on_layer_delete = [this](Node*, int idx) {
|
|
canvas->m_canvas->layer_remove(canvas->m_canvas->m_order[idx]);
|
|
};
|
|
|
|
layers->on_layer_opacity_changed = [this](Node*, int idx, float value) {
|
|
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]].m_opacity = value;
|
|
};
|
|
|
|
layers->on_layer_visibility_changed = [this](Node*, int idx, bool visible) {
|
|
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]].m_alpha_locked = visible;
|
|
};
|
|
|
|
layers->on_layer_highlight_changed = [this](Node*, int idx, bool highlight) {
|
|
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]].m_hightlight = highlight;
|
|
};
|
|
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
panels->get_child_index(stroke.get()) == -1 ? panels->add_child(stroke) : panels->remove_child(stroke.get());
|
|
panels->fix_scroll();
|
|
button->set_color(panels->get_child_index(stroke.get()) == -1 ? color_button_normal : color_button_hlight);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-brush"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
panels->get_child_index(brushes.get()) == -1 ? panels->add_child(brushes) : panels->remove_child(brushes.get());
|
|
panels->fix_scroll();
|
|
button->set_color(panels->get_child_index(brushes.get()) == -1 ? color_button_normal : color_button_hlight);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-brush-preset"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
panels->get_child_index(presets.get()) == -1 ? panels->add_child(presets) : panels->remove_child(presets.get());
|
|
panels->fix_scroll();
|
|
button->set_color(panels->get_child_index(presets.get()) == -1 ? color_button_normal : color_button_hlight);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-color"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
panels->get_child_index(color.get()) == -1 ? panels->add_child(color) : panels->remove_child(color.get());
|
|
panels->fix_scroll();
|
|
button->set_color(panels->get_child_index(color.get()) == -1 ? color_button_normal : color_button_hlight);
|
|
// auto pick = layout[main_id]->add_child<NodeColorPicker>();
|
|
// pick->m_color_cur->m_color = ui::Canvas::I->m_current_brush.m_tip_color;
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-layer"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
panels->get_child_index(layers.get()) == -1 ? panels->add_child(layers) : panels->remove_child(layers.get());
|
|
panels->fix_scroll();
|
|
button->set_color(panels->get_child_index(layers.get()) == -1 ? color_button_normal : color_button_hlight);
|
|
};
|
|
}
|
|
}
|
|
|
|
void App::init_toolbar_draw()
|
|
{
|
|
static auto select_button = [] (Node* main, NodeButton* button) {
|
|
main->find<NodeButton>("btn-pen")->set_color(color_button_normal);
|
|
main->find<NodeButton>("btn-erase")->set_color(color_button_normal);
|
|
main->find<NodeButton>("btn-line")->set_color(color_button_normal);
|
|
main->find<NodeButton>("btn-cam")->set_color(color_button_normal);
|
|
main->find<NodeButton>("btn-grid")->set_color(color_button_normal);
|
|
//main->find<NodeButton>("btn-fill")->set_color(color_button_normal);
|
|
main->find<NodeButton>("btn-mask-free")->set_color(color_button_normal);
|
|
main->find<NodeButton>("btn-mask-line")->set_color(color_button_normal);
|
|
button->set_color(color_button_hlight);
|
|
};
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-pen"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::Draw);
|
|
};
|
|
layout[main_id]->find<NodeButton>("btn-pen")->set_color(color_button_hlight);
|
|
Canvas::set_mode(Canvas::kCanvasMode::Draw);
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-pick"))
|
|
{
|
|
button->on_click = [this](Node*) {
|
|
CanvasModePen* mode = (CanvasModePen*)canvas->m_canvas->modes[(int)Canvas::kCanvasMode::Draw][0];
|
|
if (mode && canvas->m_canvas->m_current_mode == Canvas::kCanvasMode::Draw)
|
|
{
|
|
mode->m_picking = !mode->m_picking;
|
|
}
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-touchlock"))
|
|
{
|
|
button->on_click = [this](Node*) {
|
|
canvas->m_canvas->m_touch_lock = !canvas->m_canvas->m_touch_lock;
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-erase"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::Erase);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-line"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::Line);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-cam"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::Camera);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-grid"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::Grid);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-fill"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::Fill);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-mask-free"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::MaskFree);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-mask-line"))
|
|
{
|
|
button->on_click = [this, button](Node*) {
|
|
select_button(layout[main_id], button);
|
|
Canvas::set_mode(Canvas::kCanvasMode::MaskLine);
|
|
};
|
|
}
|
|
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-bucket"))
|
|
{
|
|
button->on_click = [this](Node*) {
|
|
canvas->m_canvas->clear(ui::Canvas::I->m_current_brush.m_tip_color);
|
|
};
|
|
}
|
|
}
|
|
|
|
void App::init_menu_file()
|
|
{
|
|
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-file"))
|
|
{
|
|
menu_file->on_click = [=](Node*) {
|
|
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
|
|
popup = (NodePopupMenu*)layout[const_hash("file-menu")]->m_children[0]->clone();
|
|
popup->update();
|
|
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
|
|
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
|
|
popup->SetPositioning(YGPositionTypeAbsolute);
|
|
popup->SetPosition(pos.x, pos.y);
|
|
layout[main_id]->add_child(popup);
|
|
layout[main_id]->update();
|
|
popup->mouse_capture();
|
|
popup->m_mouse_ignore = false;
|
|
popup->m_flood_events = true;
|
|
popup->m_capture_children = false;
|
|
|
|
popup->find<NodeButtonCustom>("file-newdoc")->on_click = [this](Node*) {
|
|
dialog_newdoc();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-import")->on_click = [this](Node*) {
|
|
App::I.pick_image([](std::string path){
|
|
Canvas::I->import_equirectangular(path);
|
|
});
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-open")->on_click = [this](Node*) {
|
|
dialog_open();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-browse")->on_click = [this](Node*) {
|
|
dialog_browse();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-save")->on_click = [this](Node*) {
|
|
if (doc_name.empty())
|
|
{
|
|
dialog_save();
|
|
}
|
|
else
|
|
{
|
|
canvas->m_canvas->project_save(data_path + "/" + doc_name + ".pano");
|
|
}
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-save-as")->on_click = [this](Node*) {
|
|
dialog_save();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-save-ver")->on_click = [this](Node*) {
|
|
doc_name.empty() ? dialog_save() : dialog_save_ver();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-export")->on_click = [this](Node*) {
|
|
dialog_export();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-export-cubes")->on_click = [this](Node*) {
|
|
dialog_export_cubes();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-cloud-upload")->on_click = [this](Node*) {
|
|
cloud_upload();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
popup->find<NodeButtonCustom>("file-cloud-browse")->on_click = [this](Node*) {
|
|
cloud_browse();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
void App::init_menu_edit()
|
|
{
|
|
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-edit"))
|
|
{
|
|
menu_file->on_click = [=](Node*) {
|
|
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
|
|
popup = (NodePopupMenu*)layout[const_hash("edit-menu")]->m_children[0]->clone();
|
|
popup->update();
|
|
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
|
|
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
|
|
popup->SetPositioning(YGPositionTypeAbsolute);
|
|
popup->SetPosition(pos.x, pos.y);
|
|
layout[main_id]->add_child(popup);
|
|
layout[main_id]->update();
|
|
popup->mouse_capture();
|
|
popup->m_mouse_ignore = false;
|
|
popup->m_flood_events = true;
|
|
popup->m_capture_children = false;
|
|
};
|
|
}
|
|
}
|
|
|
|
void App::init_menu_timelapse()
|
|
{
|
|
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-timelapse"))
|
|
{
|
|
menu_file->on_click = [=](Node*) {
|
|
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
|
|
popup = (NodePopupMenu*)layout[const_hash("timelapse-menu")]->m_children[0]->clone();
|
|
popup->update();
|
|
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
|
|
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
|
|
popup->SetPositioning(YGPositionTypeAbsolute);
|
|
popup->SetPosition(pos.x, pos.y);
|
|
layout[main_id]->add_child(popup);
|
|
layout[main_id]->update();
|
|
popup->mouse_capture();
|
|
popup->m_mouse_ignore = false;
|
|
popup->m_flood_events = true;
|
|
popup->m_capture_children = false;
|
|
|
|
if (auto item = popup->find<NodeButtonCustom>("timelapse-start"))
|
|
{
|
|
if (auto text = popup->find<NodeText>("menu-label"))
|
|
{
|
|
text->set_text(App::I.rec_running ? "Stop Recording" : "Start Recording");
|
|
}
|
|
}
|
|
|
|
popup->find<NodeButtonCustom>("timelapse-start")->on_click = [this](Node*) {
|
|
App::I.rec_running ? App::I.rec_stop() : App::I.rec_start();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
|
|
popup->find<NodeButtonCustom>("timelapse-clear")->on_click = [this](Node*) {
|
|
App::I.rec_clear();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
|
|
popup->find<NodeButtonCustom>("timelapse-export")->on_click = [this](Node*) {
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
App::I.rec_export("");
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
void App::brush_update()
|
|
{
|
|
// brushes->select_brush(canvas->m_brush.id);
|
|
// stroke->set_params(canvas->m_brush);
|
|
}
|
|
|
|
void App::init_menu_layer()
|
|
{
|
|
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-layers"))
|
|
{
|
|
menu_file->on_click = [=](Node*) {
|
|
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
|
|
popup = (NodePopupMenu*)layout[const_hash("layers-menu")]->m_children[0]->clone();
|
|
popup->update();
|
|
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
|
|
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
|
|
popup->SetPositioning(YGPositionTypeAbsolute);
|
|
popup->SetPosition(pos.x, pos.y);
|
|
layout[main_id]->add_child(popup);
|
|
layout[main_id]->update();
|
|
popup->mouse_capture();
|
|
popup->m_mouse_ignore = false;
|
|
popup->m_flood_events = true;
|
|
popup->m_capture_children = false;
|
|
popup->find<NodeButtonCustom>("clear-grids")->on_click = [this](Node*) {
|
|
CanvasModeGrid* mode = (CanvasModeGrid*)ui::Canvas::modes[(int)ui::Canvas::kCanvasMode::Grid][0];
|
|
mode->clear();
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
|
|
popup->find<NodeButtonCustom>("layer-clear")->on_click = [this](Node*) {
|
|
canvas->m_canvas->clear();
|
|
};
|
|
if (layers->m_current_layer)
|
|
popup->find<NodeButtonCustom>("layer-clear")->
|
|
find<NodeText>("menu-label")->
|
|
set_text(("Clear Layer " + layers->m_current_layer->m_label_text).c_str());
|
|
|
|
popup->find<NodeButtonCustom>("layer-rename")->on_click = [this](Node*) {
|
|
dialog_layer_rename();
|
|
};
|
|
if (layers->m_current_layer)
|
|
popup->find<NodeButtonCustom>("layer-rename")->
|
|
find<NodeText>("menu-label")->
|
|
set_text(("Rename Layer " + layers->m_current_layer->m_label_text).c_str());
|
|
else
|
|
popup->find<NodeButtonCustom>("layer-rename")->
|
|
find<NodeText>("menu-label")->
|
|
set_text("Rename Layer (Select a layer)");
|
|
|
|
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);
|
|
layers->clear();
|
|
for (auto& i : canvas->m_canvas->m_order)
|
|
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
|
layers->m_current_layer->m_selected = false;
|
|
layers->m_current_layer = layers->m_layers[current_idx_order - 1];
|
|
layers->m_current_layer->m_selected = true;
|
|
layers->m_current_layer->on_selected(layers->m_current_layer);
|
|
}
|
|
popup->mouse_release();
|
|
popup->destroy();
|
|
};
|
|
if (layers->m_current_layer)
|
|
{
|
|
const auto& order = canvas->m_canvas->m_order;
|
|
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 down_layer_idx = order[current_idx_order - 1];
|
|
popup->find<NodeButtonCustom>("layer-merge")->
|
|
find<NodeText>("menu-label")->
|
|
set_text(("Merge with " + canvas->m_canvas->m_layers[down_layer_idx].m_name).c_str());
|
|
}
|
|
else
|
|
{
|
|
popup->find<NodeButtonCustom>("layer-merge")->
|
|
find<NodeText>("menu-label")->
|
|
set_text("Merge Layer (Select upper layers)");
|
|
}
|
|
}
|
|
else
|
|
popup->find<NodeButtonCustom>("layer-merge")->
|
|
find<NodeText>("menu-label")->
|
|
set_text("Merge Layer (Select a layer)");
|
|
|
|
};
|
|
}
|
|
}
|
|
|
|
void App::initLayout()
|
|
{
|
|
LOG("initializing layout statics");
|
|
NodeBorder::static_init();
|
|
NodeImage::static_init();
|
|
NodeIcon::static_init();
|
|
NodeStrokePreview::static_init();
|
|
|
|
layout.on_loaded = [&] {
|
|
LOG("initializing layout updating after load");
|
|
layout[main_id]->update(width, height, zoom);
|
|
|
|
LOG("initializing layout components");
|
|
|
|
init_sidebar();
|
|
|
|
canvas->m_canvas->layer_add("Default");
|
|
layers->add_layer("Default");
|
|
|
|
init_toolbar_draw();
|
|
init_toolbar_main();
|
|
init_menu_file();
|
|
init_menu_edit();
|
|
init_menu_layer();
|
|
init_menu_timelapse();
|
|
|
|
if (auto* menu_entry = layout[main_id]->find<NodeButtonCustom>("menu-about"))
|
|
{
|
|
menu_entry->on_click = [=](Node*) {
|
|
// int x = 0;
|
|
// sin(time(0) / x);
|
|
};
|
|
}
|
|
|
|
Brush b;
|
|
b.m_tex_id = brushes->get_texture_id(0);
|
|
b.id = brushes->get_brush_id(0);
|
|
b.m_tip_size = .1f;
|
|
b.m_tip_flow = .5f;
|
|
b.m_tip_spacing = .1f;
|
|
b.m_tip_opacity = 1.f;
|
|
ui::Canvas::I->m_current_brush = b;
|
|
|
|
brush_update();
|
|
|
|
TextureManager::load("data/paper.jpg");
|
|
|
|
// hacky thing to make the toolbar buttons not steal events when moving cursor fast
|
|
if (auto* toolbar = layout[main_id]->find<Node>("toolbar"))
|
|
toolbar->m_flood_events = true;
|
|
|
|
NodeImage* n = new NodeImage;
|
|
n->m_path = "data/ui/p-black.png";
|
|
n->m_tex_id = const_hash("data/ui/p-black.png");
|
|
n->SetSize(30, 45);
|
|
n->create();
|
|
|
|
NodeButtonCustom* butt = new NodeButtonCustom;
|
|
butt->create();
|
|
butt->add_child(n);
|
|
butt->SetPositioning(YGPositionTypeAbsolute);
|
|
butt->set_color({ 0, 0, 0, 0 });
|
|
//n->SetPosition(100, 100);
|
|
YGNodeStyleSetPosition(butt->y_node, YGEdgeBottom, 8);
|
|
YGNodeStyleSetPosition(butt->y_node, YGEdgeLeft, 15);
|
|
//butt->SetSize(30, 45);
|
|
layout[main_id]->add_child(butt);
|
|
|
|
butt->on_click = [this](Node*){
|
|
};
|
|
|
|
if (auto* slider = layout[main_id]->find<NodeSliderH>("frames-slider"))
|
|
{
|
|
auto frame_text = layout[main_id]->find<NodeText>("timeline-frame");
|
|
slider->on_value_changed = [this, frame_text](Node*, float value)
|
|
{
|
|
auto& c = *ui::Canvas::I;
|
|
|
|
for (int i = 0; i < c.m_layers.size(); i++)
|
|
{
|
|
auto l = layers->get_layer_at(i);
|
|
layers->handle_layer_opacity(l, .0f);
|
|
}
|
|
|
|
int current_layer = (int)glm::clamp<int>(
|
|
floor(value * c.m_layers.size()), 1, c.m_layers.size() - 1);
|
|
auto l = layers->get_layer_at(current_layer);
|
|
layers->handle_layer_selected(l);
|
|
layers->handle_layer_opacity(l, 1.f);
|
|
if (current_layer > 0)
|
|
{
|
|
auto l = layers->get_layer_at(current_layer - 1);
|
|
layers->handle_layer_opacity(l, .25f);
|
|
}
|
|
|
|
// First layer always visible
|
|
{
|
|
auto l = layers->get_layer_at(0);
|
|
layers->handle_layer_opacity(l, 1.0f);
|
|
}
|
|
|
|
if (frame_text)
|
|
{
|
|
char str[16];
|
|
snprintf(str, sizeof(str), "%02d", current_layer);
|
|
frame_text->set_text(str);
|
|
}
|
|
};
|
|
}
|
|
|
|
App::I.redraw = true;
|
|
};
|
|
LOG("initializing layout xml");
|
|
if (layout.m_loaded)
|
|
{
|
|
LOG("restore layout");
|
|
layout.restore_context();
|
|
if (panels->get_child_index(brushes.get()) == -1) brushes->restore_context();
|
|
if (panels->get_child_index(layers.get()) == -1) layers->restore_context();
|
|
if (panels->get_child_index(color.get()) == -1) color->restore_context();
|
|
if (panels->get_child_index(stroke.get()) == -1) stroke->restore_context();
|
|
}
|
|
else
|
|
layout.load("data/layout.xml");
|
|
LOG("initializing layout completed");
|
|
}
|