add layout designer
This commit is contained in:
12
src/app.cpp
12
src/app.cpp
@@ -547,6 +547,8 @@ void App::draw(float dt)
|
|||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
for (int i = 1; i < layout[main_id]->m_children.size(); i++)
|
for (int i = 1; i < layout[main_id]->m_children.size(); i++)
|
||||||
layout[main_id]->m_children[i]->watch(observer);
|
layout[main_id]->m_children[i]->watch(observer);
|
||||||
|
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
|
||||||
|
layout_designer[main_id]->m_children[i]->watch(observer);
|
||||||
//msgbox->watch(observer);
|
//msgbox->watch(observer);
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
uirtt.unbindFramebuffer();
|
uirtt.unbindFramebuffer();
|
||||||
@@ -563,6 +565,8 @@ void App::draw(float dt)
|
|||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
for (int i = 0; i < layout[main_id]->m_children.size(); i++)
|
for (int i = 0; i < layout[main_id]->m_children.size(); i++)
|
||||||
layout[main_id]->m_children[i]->watch(observer);
|
layout[main_id]->m_children[i]->watch(observer);
|
||||||
|
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
|
||||||
|
layout_designer[main_id]->m_children[i]->watch(observer);
|
||||||
//msgbox->watch(observer);
|
//msgbox->watch(observer);
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
}
|
}
|
||||||
@@ -617,6 +621,9 @@ void App::update(float dt)
|
|||||||
if (auto* main = layout[main_id])
|
if (auto* main = layout[main_id])
|
||||||
main->update(width, height, zoom);
|
main->update(width, height, zoom);
|
||||||
|
|
||||||
|
if (auto* main = layout_designer[main_id])
|
||||||
|
main->update(width, height, zoom);
|
||||||
|
|
||||||
{
|
{
|
||||||
static glm::vec4 color_button_normal{ .1, .1, .1, 1 };
|
static glm::vec4 color_button_normal{ .1, .1, .1, 1 };
|
||||||
static glm::vec4 color_button_hlight{ 1, .0, .0, 1 };
|
static glm::vec4 color_button_hlight{ 1, .0, .0, 1 };
|
||||||
@@ -651,6 +658,7 @@ void App::terminate()
|
|||||||
TextureManager::invalidate();
|
TextureManager::invalidate();
|
||||||
ShaderManager::invalidate();
|
ShaderManager::invalidate();
|
||||||
layout.unload();
|
layout.unload();
|
||||||
|
layout_designer.unload();
|
||||||
uirtt.destroy();
|
uirtt.destroy();
|
||||||
m_face_plane.destroy();
|
m_face_plane.destroy();
|
||||||
layers.reset();
|
layers.reset();
|
||||||
@@ -921,9 +929,9 @@ void App::ui_thread_main()
|
|||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
if (layout.reload())
|
if (layout.reload())
|
||||||
{
|
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
if (layout_designer.reload())
|
||||||
|
redraw = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ public:
|
|||||||
Plane m_face_plane;
|
Plane m_face_plane;
|
||||||
Sphere sphere;
|
Sphere sphere;
|
||||||
LayoutManager layout;
|
LayoutManager layout;
|
||||||
|
LayoutManager layout_designer;
|
||||||
NodeMessageBox* msgbox;
|
NodeMessageBox* msgbox;
|
||||||
NodeSettings* settings;
|
NodeSettings* settings;
|
||||||
NodeBorder* sidebar = nullptr;
|
NodeBorder* sidebar = nullptr;
|
||||||
|
|||||||
@@ -332,6 +332,8 @@ bool App::mouse_down(int button, float x, float y, float pressure, kEventSource
|
|||||||
e.m_source = source;
|
e.m_source = source;
|
||||||
e.m_eraser = eraser;
|
e.m_eraser = eraser;
|
||||||
kEventResult ret = kEventResult::Available;
|
kEventResult ret = kEventResult::Available;
|
||||||
|
if (auto* main = layout_designer[main_id])
|
||||||
|
return main->on_event(&e) == kEventResult::Consumed;
|
||||||
if (auto* main = layout[main_id])
|
if (auto* main = layout[main_id])
|
||||||
ret = main->on_event(&e);
|
ret = main->on_event(&e);
|
||||||
return ret == kEventResult::Consumed;
|
return ret == kEventResult::Consumed;
|
||||||
@@ -347,6 +349,8 @@ bool App::mouse_move(float x, float y, float pressure, kEventSource source, bool
|
|||||||
e.m_source = source;
|
e.m_source = source;
|
||||||
e.m_eraser = eraser;
|
e.m_eraser = eraser;
|
||||||
kEventResult ret = kEventResult::Available;
|
kEventResult ret = kEventResult::Available;
|
||||||
|
if (auto* main = layout_designer[main_id])
|
||||||
|
return main->on_event(&e) == kEventResult::Consumed;
|
||||||
if (auto* main = layout[main_id])
|
if (auto* main = layout[main_id])
|
||||||
ret = main->on_event(&e);
|
ret = main->on_event(&e);
|
||||||
return ret == kEventResult::Consumed;
|
return ret == kEventResult::Consumed;
|
||||||
@@ -360,6 +364,8 @@ bool App::mouse_up(int button, float x, float y, kEventSource source, bool erase
|
|||||||
e.m_source = source;
|
e.m_source = source;
|
||||||
e.m_eraser = eraser;
|
e.m_eraser = eraser;
|
||||||
kEventResult ret = kEventResult::Available;
|
kEventResult ret = kEventResult::Available;
|
||||||
|
if (auto* main = layout_designer[main_id])
|
||||||
|
return main->on_event(&e) == kEventResult::Consumed;
|
||||||
if (auto* main = layout[main_id])
|
if (auto* main = layout[main_id])
|
||||||
ret = main->on_event(&e);
|
ret = main->on_event(&e);
|
||||||
return ret == kEventResult::Consumed;
|
return ret == kEventResult::Consumed;
|
||||||
@@ -372,6 +378,8 @@ bool App::mouse_scroll(float x, float y, float delta)
|
|||||||
e.m_pos = { x / zoom, y / zoom };
|
e.m_pos = { x / zoom, y / zoom };
|
||||||
e.m_scroll_delta = delta;
|
e.m_scroll_delta = delta;
|
||||||
kEventResult ret = kEventResult::Available;
|
kEventResult ret = kEventResult::Available;
|
||||||
|
if (auto* main = layout_designer[main_id])
|
||||||
|
return main->on_event(&e) == kEventResult::Consumed;
|
||||||
if (auto* main = layout[main_id])
|
if (auto* main = layout[main_id])
|
||||||
ret = main->on_event(&e);
|
ret = main->on_event(&e);
|
||||||
return ret == kEventResult::Consumed;
|
return ret == kEventResult::Consumed;
|
||||||
@@ -382,6 +390,8 @@ bool App::mouse_cancel(int button)
|
|||||||
MouseEvent e;
|
MouseEvent e;
|
||||||
e.m_type = kEventType::MouseCancel;
|
e.m_type = kEventType::MouseCancel;
|
||||||
kEventResult ret = kEventResult::Available;
|
kEventResult ret = kEventResult::Available;
|
||||||
|
if (auto* main = layout_designer[main_id])
|
||||||
|
return main->on_event(&e) == kEventResult::Consumed;
|
||||||
if (auto* main = layout[main_id])
|
if (auto* main = layout[main_id])
|
||||||
ret = main->on_event(&e);
|
ret = main->on_event(&e);
|
||||||
return ret == kEventResult::Consumed;
|
return ret == kEventResult::Consumed;
|
||||||
|
|||||||
@@ -1404,6 +1404,14 @@ void App::initLayout()
|
|||||||
else
|
else
|
||||||
layout.load("data/layout.xml");
|
layout.load("data/layout.xml");
|
||||||
LOG("initializing layout completed");
|
LOG("initializing layout completed");
|
||||||
|
|
||||||
|
//LOG("initializing layout designer xml");
|
||||||
|
//layout_designer.on_loaded = [&](bool reloaded) {
|
||||||
|
// if (!reloaded)
|
||||||
|
// layout_designer.create();
|
||||||
|
// layout_designer[main_id]->add_child(layout_designer.instantiate("changelog"));
|
||||||
|
//};
|
||||||
|
//layout_designer.load("data/dialogs/changelog.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::set_ui_scale(float scale)
|
void App::set_ui_scale(float scale)
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ bool Font::load(const std::string& ttf, int font_size, float font_scale)
|
|||||||
LOG("Font::load loaded");
|
LOG("Font::load loaded");
|
||||||
auto bitmap = std::make_unique<uint8_t[]>(w*h);
|
auto bitmap = std::make_unique<uint8_t[]>(w*h);
|
||||||
chars.resize(num_chars);
|
chars.resize(num_chars);
|
||||||
|
//int offset = stbtt_FindMatchingFont(file.m_data, "Arial Bold", STBTT_MACSTYLE_DONTCARE);
|
||||||
|
//if (offset < 0)
|
||||||
|
// offset = 0;
|
||||||
stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size*scale, bitmap.get(), w, h, start_char, num_chars, chars.data());
|
stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size*scale, bitmap.get(), w, h, start_char, num_chars, chars.data());
|
||||||
calc_bounds();
|
calc_bounds();
|
||||||
font_tex.create(w, h, GL_R8, GL_RED, bitmap.get());
|
font_tex.create(w, h, GL_R8, GL_RED, bitmap.get());
|
||||||
|
|||||||
@@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
class LayoutManager
|
class LayoutManager
|
||||||
{
|
{
|
||||||
std::map<uint16_t, std::shared_ptr<class Node>> m_layouts;
|
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
struct stat m_file_info { 0 };
|
struct stat m_file_info { 0 };
|
||||||
public:
|
public:
|
||||||
|
std::map<uint16_t, std::shared_ptr<class Node>> m_layouts;
|
||||||
bool m_loaded = false;
|
bool m_loaded = false;
|
||||||
std::function<void(bool reloaded)> on_loaded;
|
std::function<void(bool reloaded)> on_loaded;
|
||||||
std::function<void()> on_reloading;
|
std::function<void()> on_reloading;
|
||||||
|
|||||||
@@ -343,9 +343,6 @@ const Node* Node::init_template(const char* id)
|
|||||||
{
|
{
|
||||||
auto node = c->clone();
|
auto node = c->clone();
|
||||||
add_child(node);
|
add_child(node);
|
||||||
//node->init();
|
|
||||||
//node->create();
|
|
||||||
//node->loaded();
|
|
||||||
}
|
}
|
||||||
YGNodeCopyStyle(y_node, m_template->y_node);
|
YGNodeCopyStyle(y_node, m_template->y_node);
|
||||||
m_template->clone_copy(this);
|
m_template->clone_copy(this);
|
||||||
@@ -377,7 +374,8 @@ std::shared_ptr<Node> Node::load_template(const std::string& filename, const std
|
|||||||
LayoutManager m;
|
LayoutManager m;
|
||||||
std::shared_ptr<Node> ret;
|
std::shared_ptr<Node> ret;
|
||||||
if (m.load(filename.c_str()))
|
if (m.load(filename.c_str()))
|
||||||
ret = std::move(m.get_ref(name.c_str())->m_children[0]);
|
ret = m.get_ref(name.c_str())->m_children[0]->clone();
|
||||||
|
m.unload();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user