add viewport node, return ptr instead of ref for layout[id] to check wether is valid or not
This commit is contained in:
@@ -127,70 +127,70 @@ void App::init()
|
||||
NodeIcon::static_init();
|
||||
|
||||
layout.on_loaded = [&] {
|
||||
layout[main_id].update(width, height);
|
||||
if (auto* button = layout[main_id].find<NodeButton>("btn-close"))
|
||||
layout[main_id]->update(width, height);
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-close"))
|
||||
{
|
||||
button->on_click = [] { exit(0); };
|
||||
}
|
||||
if (auto* button = layout[main_id].find<NodeButton>("btn-popup"))
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-popup"))
|
||||
{
|
||||
button->on_click = [this] {
|
||||
msgbox = new NodeMessageBox();
|
||||
msgbox->m_manager = &layout;
|
||||
msgbox->init();
|
||||
layout[main_id].add_child(msgbox);
|
||||
layout[main_id].update();
|
||||
layout[main_id]->add_child(msgbox);
|
||||
layout[main_id]->update();
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id].find<NodeButtonCustom>("btn-settings"))
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-settings"))
|
||||
{
|
||||
button->on_click = [this] {
|
||||
settings = new NodeSettings();
|
||||
settings->m_manager = &layout;
|
||||
settings->init();
|
||||
layout[main_id].add_child(settings);
|
||||
layout[main_id].update();
|
||||
layout[main_id]->add_child(settings);
|
||||
layout[main_id]->update();
|
||||
};
|
||||
}
|
||||
if (auto* menu_file = layout[main_id].find<NodeButtonCustom>("menu-file"))
|
||||
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-file"))
|
||||
{
|
||||
menu_file->on_click = [=] {
|
||||
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 = (NodePopupMenu*)layout[const_hash("file-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(pos.x, pos.y);
|
||||
layout[main_id].add_child(popup);
|
||||
layout[main_id].update();
|
||||
layout[main_id]->add_child(popup);
|
||||
layout[main_id]->update();
|
||||
};
|
||||
}
|
||||
if (auto* menu_file = layout[main_id].find<NodeButtonCustom>("menu-edit"))
|
||||
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-edit"))
|
||||
{
|
||||
menu_file->on_click = [=] {
|
||||
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 = (NodePopupMenu*)layout[const_hash("edit-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(pos.x, pos.y);
|
||||
layout[main_id].add_child(popup);
|
||||
layout[main_id].update();
|
||||
layout[main_id]->add_child(popup);
|
||||
layout[main_id]->update();
|
||||
};
|
||||
}
|
||||
if (auto* menu_file = layout[main_id].find<NodeButtonCustom>("menu-layers"))
|
||||
if (auto* menu_file = layout[main_id]->find<NodeButtonCustom>("menu-layers"))
|
||||
{
|
||||
menu_file->on_click = [=] {
|
||||
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 = (NodePopupMenu*)layout[const_hash("layers-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(pos.x, pos.y);
|
||||
layout[main_id].add_child(popup);
|
||||
layout[main_id].update();
|
||||
layout[main_id]->add_child(popup);
|
||||
layout[main_id]->update();
|
||||
};
|
||||
}
|
||||
if (auto* toolbar = layout[main_id].find<Node>("toolbar"))
|
||||
if (auto* toolbar = layout[main_id]->find<Node>("toolbar"))
|
||||
{
|
||||
toolbar->m_flood_events = true;
|
||||
}
|
||||
};
|
||||
layout.load("data/layout.xml");
|
||||
layout.load("data/layout2.xml");
|
||||
|
||||
//msgbox->find<NodeButton>("btn-ok")->on_click = [] { exit(0); };
|
||||
// msgbox->find<NodeButton>("btn-ok")->m_text->m_text = "DO";
|
||||
@@ -240,7 +240,7 @@ void App::update(float dt)
|
||||
|
||||
auto observer = [this](Node* n)
|
||||
{
|
||||
if (n->m_display)
|
||||
if (n && n->m_display)
|
||||
{
|
||||
auto box = n->m_clip;
|
||||
glScissor((int)box.x-1, (int)(height - box.y - box.w)-1, (int)box.z+2, (int)box.w+2);
|
||||
@@ -249,7 +249,8 @@ void App::update(float dt)
|
||||
};
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
layout[main_id].watch(observer);
|
||||
if (auto* main = layout[main_id])
|
||||
main->watch(observer);
|
||||
//msgbox->watch(observer);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
@@ -258,7 +259,8 @@ void App::resize(float w, float h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
layout[main_id].update(w, h);
|
||||
if (auto* main = layout[main_id])
|
||||
main->update(w, h);
|
||||
}
|
||||
|
||||
void App::mouse_down(int button, float x, float y)
|
||||
@@ -266,7 +268,7 @@ void App::mouse_down(int button, float x, float y)
|
||||
MouseEvent e;
|
||||
e.m_type = button ? kEventType::MouseDownR : kEventType::MouseDownL;
|
||||
e.m_pos = { x, y };
|
||||
layout[main_id].on_event(&e);
|
||||
layout[main_id]->on_event(&e);
|
||||
printf("mouse click %f %f\n", x, y);
|
||||
// NodeBorder* n = new NodeBorder();
|
||||
// n->SetPositioning(YGPositionTypeAbsolute);
|
||||
@@ -278,30 +280,31 @@ void App::mouse_down(int button, float x, float y)
|
||||
// layout[main_id].update(width, height);
|
||||
if (popup)
|
||||
{
|
||||
layout[main_id].remove_child(popup);
|
||||
layout[main_id]->remove_child(popup);
|
||||
popup = nullptr;
|
||||
}
|
||||
if (button == 1)
|
||||
{
|
||||
popup = (NodePopupMenu*)layout[const_hash("popup-menu")].m_children[0]->clone();
|
||||
popup = (NodePopupMenu*)layout[const_hash("popup-menu")]->m_children[0]->clone();
|
||||
popup->SetPositioning(YGPositionTypeAbsolute);
|
||||
popup->SetPosition(x, y);
|
||||
layout[main_id].add_child(popup);
|
||||
layout[main_id]->add_child(popup);
|
||||
}
|
||||
layout[main_id].update();
|
||||
layout[main_id]->update();
|
||||
}
|
||||
void App::mouse_move(float x, float y)
|
||||
{
|
||||
MouseEvent e;
|
||||
e.m_type = kEventType::MouseMove;
|
||||
e.m_pos = { x, y };
|
||||
layout[main_id].on_event(&e);
|
||||
if (auto* main = layout[main_id])
|
||||
main->on_event(&e);
|
||||
}
|
||||
void App::mouse_up(int button, float x, float y)
|
||||
{
|
||||
MouseEvent e;
|
||||
e.m_type = button ? kEventType::MouseUpR : kEventType::MouseUpL;
|
||||
e.m_pos = { x, y };
|
||||
layout[main_id].on_event(&e);
|
||||
layout[main_id].update();
|
||||
layout[main_id]->on_event(&e);
|
||||
layout[main_id]->update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user