make popup ptr local on main menu

This commit is contained in:
2019-02-09 11:54:42 +01:00
parent 1876207afb
commit e629a2a7b5
5 changed files with 61 additions and 57 deletions

View File

@@ -25,6 +25,7 @@ bool ABR::section_samp()
{
auto samp_size = ru32();
auto uid = rpascal();
printf("sample brush %s\n", uid.c_str());
skip(4);
auto image = parse_vmem();
if (image->channels.size() >= 3)
@@ -67,6 +68,7 @@ bool ABR::section_patt()
auto image_mode = ru32();
if (!(image_mode == 1 || image_mode == 3))
{
printf("skip image mode %d\n", image_mode);
skip(patt_length - 8);
snap();
continue;
@@ -113,16 +115,16 @@ bool ABR::section_patt()
std::shared_ptr<ABR::Image> ABR::parse_vmem()
{
// Virtual Memory Array List
auto version = ru32(); // = 3
auto length = ru32();
auto rect = rrect();
auto channels = ru32();
auto vmem_version = ru32(); // = 3
auto vmem_length = ru32();
auto vmem_rect = rrect();
auto vmem_channels = ru32();
// The following is a virtual memory array,
// repeated for the number of channels
// + one for a user mask + one for a sheet mask.
channels += 2; // user and sheet mask
auto ret = std::make_shared<Image>(version, rect);
for (int ch = 0; ch < channels; ch++)
vmem_channels += 2; // user and sheet mask
auto ret = std::make_shared<Image>(vmem_version, vmem_rect);
for (int ch = 0; ch < vmem_channels; ch++)
{
auto array_written = ru32(); // skip if 0
if (array_written == 0)
@@ -147,6 +149,7 @@ std::shared_ptr<ABR::Image> ABR::parse_vmem()
}
else if (compression == 1)
{
auto start = pos();
auto height = rect.height();
// contain the compressed length of each scanline
std::vector<uint16_t> scanlines;
@@ -160,6 +163,7 @@ std::shared_ptr<ABR::Image> ABR::parse_vmem()
raw.insert(raw.end(), decoded.begin(), decoded.end());
}
ret->channels.emplace_back(depth, rect, compression, raw);
auto len = pos() - start;
}
else
{
@@ -300,6 +304,7 @@ bool ABR::open(const std::string& path)
init(asset.read_all(), asset.m_len, BinaryStream::ByteOrder::BigEndian);
auto version_major = ru16();
auto version_minor = ru16();
printf("ABR %d.%d\n", version_major, version_minor);
while (!eof())
{
if (rstring(4) != "8BIM")

View File

@@ -105,8 +105,9 @@ public:
n = -n + 1;
j++;
auto ch = ru8();
for (int c = 0; c < n; c++)
data.push_back(ru8());
data.push_back(ch);
}
else
{
@@ -213,7 +214,7 @@ class ABR : public BinaryStream
Type::Vec items;
virtual std::string str(int indent, const std::string& prefix) const override
{
auto ret = std::string(indent, '-') + fmt::format("list: {} props:", items.size());
auto ret = std::string(indent, '-') + fmt::format("list: {} items:", items.size());
for (int i = 0; i < items.size(); i++)
ret += "\n" + items[i]->str(indent + 1, fmt::format("{}) ", i));
return ret;
@@ -371,11 +372,11 @@ private:
auto& method = m_parser_table[t];
return method();
}
else if (m_parser_table.find(pick(4)) != m_parser_table.end())
{
auto& method = m_parser_table[rstring(4)];
return method();
}
//else if (m_parser_table.find(pick(4)) != m_parser_table.end())
//{
// auto& method = m_parser_table[rstring(4)];
// return method();
//}
return nullptr;
}
std::map<std::string, std::function<Type::Ref()>> m_parser_table;

View File

@@ -56,8 +56,6 @@ public:
LayoutManager layout;
NodeMessageBox* msgbox;
NodeSettings* settings;
NodePopupMenu* popup = nullptr;
NodePopupMenu* subpopup = nullptr;
NodePopupMenu* menu_file = nullptr;
NodePopupMenu* menu_edit = nullptr;
NodePopupMenu* menu_layers = nullptr;

View File

@@ -478,9 +478,6 @@ void App::dialog_resize()
ActionManager::clear();
dialog->destroy();
};
popup->mouse_release();
popup->destroy();
}
void App::dialog_export_cubes()
@@ -517,7 +514,4 @@ void App::dialog_layer_rename()
dialog->destroy();
App::I.hideKeyboard();
};
popup->mouse_release();
popup->destroy();
}

View File

@@ -379,7 +379,7 @@ void App::init_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();
auto 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;
@@ -393,13 +393,13 @@ void App::init_menu_file()
popup->m_capture_children = false;
if (auto b = popup->find<NodeButtonCustom>("file-newdoc"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
dialog_newdoc();
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-import"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
App::I.pick_image([this](std::string path){
Image img;
async_start();
@@ -422,7 +422,7 @@ void App::init_menu_file()
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-open"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
//dialog_open();
App::I.pick_file({"ppi","PPI"}, [this](std::string path){
App::I.open_document(path);
@@ -431,13 +431,13 @@ void App::init_menu_file()
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-browse"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
dialog_browse();
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-save"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
if (Canvas::I->m_newdoc)
{
dialog_save();
@@ -450,27 +450,27 @@ void App::init_menu_file()
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-save-as"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
dialog_save();
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-save-ver"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
Canvas::I->m_newdoc ? dialog_save() : dialog_save_ver();
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-export"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
dialog_export(".jpg");
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-export-tick"))
b->on_click = [this,b](Node*) {
b->on_click = [this, b, popup](Node*) {
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
subpopup = (NodePopupMenu*)layout[const_hash("file-submenu-export")]->m_children[0]->clone();
auto subpopup = (NodePopupMenu*)layout[const_hash("file-submenu-export")]->m_children[0]->clone();
subpopup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - subpopup->m_size.x + b->m_size.x;
@@ -482,14 +482,14 @@ void App::init_menu_file()
subpopup->m_mouse_ignore = false;
subpopup->m_flood_events = true;
subpopup->m_capture_children = false;
subpopup->find<NodeButtonCustom>("file-submenu-export-png")->on_click = [this](Node*) {
subpopup->find<NodeButtonCustom>("file-submenu-export-png")->on_click = [this, subpopup, popup](Node*) {
dialog_export(".png");
subpopup->mouse_release();
subpopup->destroy();
popup->mouse_release();
popup->destroy();
};
subpopup->find<NodeButtonCustom>("file-submenu-export-layers")->on_click = [this](Node*) {
subpopup->find<NodeButtonCustom>("file-submenu-export-layers")->on_click = [this, subpopup, popup](Node*) {
dialog_export_layers();
subpopup->mouse_release();
subpopup->destroy();
@@ -498,31 +498,31 @@ void App::init_menu_file()
};
};
if (auto b = popup->find<NodeButtonCustom>("file-share"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
share_file(doc_path);
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-resize"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
dialog_resize();
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-export-cubes"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
dialog_export_cubes();
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-cloud-upload"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
cloud_upload();
popup->mouse_release();
popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-cloud-browse"))
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
cloud_browse();
popup->mouse_release();
popup->destroy();
@@ -537,7 +537,7 @@ void App::init_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();
auto 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;
@@ -559,7 +559,7 @@ void App::init_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();
auto 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;
@@ -580,19 +580,19 @@ void App::init_menu_timelapse()
}
}
popup->find<NodeButtonCustom>("timelapse-start")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("timelapse-start")->on_click = [this, popup](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*) {
popup->find<NodeButtonCustom>("timelapse-clear")->on_click = [this, popup](Node*) {
App::I.rec_clear();
popup->mouse_release();
popup->destroy();
};
popup->find<NodeButtonCustom>("timelapse-export")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("timelapse-export")->on_click = [this, popup](Node*) {
popup->mouse_release();
popup->destroy();
App::I.rec_export("");
@@ -607,7 +607,7 @@ void App::init_menu_about()
{
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("about-menu")]->m_children[0]->clone();
auto popup = (NodePopupMenu*)layout[const_hash("about-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;
@@ -620,13 +620,13 @@ void App::init_menu_about()
popup->m_flood_events = true;
popup->m_capture_children = false;
popup->find<NodeButtonCustom>("about-app")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("about-app")->on_click = [this, popup](Node*) {
dialog_about();
popup->mouse_release();
popup->destroy();
};
popup->find<NodeButtonCustom>("about-doc")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("about-doc")->on_click = [this, popup](Node*) {
// auto path = Asset::absolute("data/doc/test.pdf");
// display_file(path);
dialog_usermanual();
@@ -642,7 +642,7 @@ void App::init_menu_about()
sprintf(label, "What's new in %d.%d.%d?", g_version_major, g_version_minor, g_version_fix);
text->set_text(label);
}
item->on_click = [this](Node*) {
item->on_click = [this, popup](Node*) {
dialog_changelog();
popup->mouse_release();
popup->destroy();
@@ -651,15 +651,17 @@ void App::init_menu_about()
if (auto b = popup->find<NodeButtonCustom>("about-crash"))
{
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
LOG("crashing");
App::I.crash_test();
popup->mouse_release();
popup->destroy();
};
}
if (auto b = popup->find<NodeButtonCustom>("about-perf"))
{
b->on_click = [this](Node*) {
b->on_click = [this, popup](Node*) {
LOG("perf");
auto start = std::chrono::high_resolution_clock::now();
Canvas::I->stroke_start({ 0, 0, 0 }, 0.9f, Canvas::I->m_current_brush);
@@ -684,6 +686,8 @@ void App::init_menu_about()
static char str[256];
sprintf(str, "Time %lld ms", ms);
App::I.message_box("Performance test", str);
popup->mouse_release();
popup->destroy();
};
}
};
@@ -702,7 +706,7 @@ void App::init_menu_layer()
{
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();
auto 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;
@@ -714,20 +718,20 @@ void App::init_menu_layer()
popup->m_mouse_ignore = false;
popup->m_flood_events = true;
popup->m_capture_children = false;
popup->find<NodeButtonCustom>("clear-grids")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("clear-grids")->on_click = [this, popup](Node*) {
CanvasModeGrid* mode = (CanvasModeGrid*)Canvas::modes[(int)kCanvasMode::Grid][0];
mode->clear();
popup->mouse_release();
popup->destroy();
};
popup->find<NodeButtonCustom>("camera-reset")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("camera-reset")->on_click = [this, popup](Node*) {
canvas->reset_camera();
popup->mouse_release();
popup->destroy();
};
popup->find<NodeButtonCustom>("layer-clear")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("layer-clear")->on_click = [this, popup](Node*) {
canvas->m_canvas->clear();
popup->mouse_release();
popup->destroy();
@@ -737,8 +741,10 @@ void App::init_menu_layer()
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*) {
popup->find<NodeButtonCustom>("layer-rename")->on_click = [this, popup](Node*) {
dialog_layer_rename();
popup->mouse_release();
popup->destroy();
};
if (layers->m_current_layer)
popup->find<NodeButtonCustom>("layer-rename")->
@@ -749,7 +755,7 @@ void App::init_menu_layer()
find<NodeText>("menu-label")->
set_text("Rename Layer (Select a layer)");
popup->find<NodeButtonCustom>("layer-merge")->on_click = [this](Node*) {
popup->find<NodeButtonCustom>("layer-merge")->on_click = [this, popup](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));