added range loop based layout nodes traversal
This commit is contained in:
@@ -126,23 +126,18 @@ void App::update(float dt)
|
|||||||
shader_color.u_vec4("col", { .3f, .3f, .3f, 1 });
|
shader_color.u_vec4("col", { .3f, .3f, .3f, 1 });
|
||||||
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
std::stack<Node*> nodes;
|
|
||||||
Node* current = &layout;
|
|
||||||
nodes.push(current);
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
while (current)
|
for (auto& n : layout)
|
||||||
{
|
{
|
||||||
nodes.pop();
|
|
||||||
|
|
||||||
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
||||||
glm::mat4 scale = glm::scale(glm::vec3(current->m_size, 1.f));
|
glm::mat4 scale = glm::scale(glm::vec3(n.m_size, 1.f));
|
||||||
glm::mat4 pos = glm::translate(glm::vec3(current->m_pos, 0));
|
glm::mat4 pos = glm::translate(glm::vec3(n.m_pos, 0));
|
||||||
auto mvp = proj * pos * scale * pivot;
|
auto mvp = proj * pos * scale * pivot;
|
||||||
|
|
||||||
auto box = current->m_clip;
|
auto box = n.m_clip;
|
||||||
glScissor(box.x, height - box.y - box.w, box.z, box.w);
|
glScissor(box.x, height - box.y - box.w, box.z, box.w);
|
||||||
|
|
||||||
shader_color.u_vec4("col", current->color);
|
shader_color.u_vec4("col", n.color);
|
||||||
shader_color.use();
|
shader_color.use();
|
||||||
shader_color.u_mat4("mvp", mvp);
|
shader_color.u_mat4("mvp", mvp);
|
||||||
plane.draw_fill();
|
plane.draw_fill();
|
||||||
@@ -151,33 +146,10 @@ void App::update(float dt)
|
|||||||
shader_color.use();
|
shader_color.use();
|
||||||
shader_color.u_mat4("mvp", mvp);
|
shader_color.u_mat4("mvp", mvp);
|
||||||
plane.draw_stroke();
|
plane.draw_stroke();
|
||||||
|
|
||||||
for (auto& c : current->children)
|
|
||||||
nodes.push(&c);
|
|
||||||
current = nodes.size() ? nodes.top() : nullptr;
|
|
||||||
}
|
}
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
tex.unbind();
|
tex.unbind();
|
||||||
sampler.unbind();
|
sampler.unbind();
|
||||||
|
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
||||||
//shader_color.use();
|
|
||||||
//shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{width/2, height/2, 0.f}) * glm::scale(glm::vec3(8)));
|
|
||||||
//shader_color.u_vec4("col", {1, 1, 1, 1});
|
|
||||||
|
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
||||||
//tex.bind();
|
|
||||||
//shader.use();
|
|
||||||
//shader.u_mat4("mvp", proj * glm::translate(glm::vec3{ width / 2, height / 2, 0.f }) * glm::scale(glm::vec3(8)));
|
|
||||||
//shader.u_int("tex", 0);
|
|
||||||
//circle3.draw_fill();
|
|
||||||
|
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
||||||
//shader_color.use();
|
|
||||||
//shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{width/2, height/2, 0.f}) * glm::scale(glm::vec3(8)));
|
|
||||||
//shader_color.u_vec4("col", {1, 1, 1, 1});
|
|
||||||
//glLineWidth(2);
|
|
||||||
//circle3.draw_fill();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::resize(float w, float h)
|
void App::resize(float w, float h)
|
||||||
|
|||||||
@@ -168,4 +168,37 @@ public:
|
|||||||
void load(const char* path);
|
void load(const char* path);
|
||||||
void load_internal(const tinyxml2::XMLElement* x_node);
|
void load_internal(const tinyxml2::XMLElement* x_node);
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
|
class iterator
|
||||||
|
{
|
||||||
|
std::stack<Node*> m_nodes;
|
||||||
|
Node* m_current;
|
||||||
|
public:
|
||||||
|
iterator(Node* root)
|
||||||
|
{
|
||||||
|
m_current = root;
|
||||||
|
if (root)
|
||||||
|
m_nodes.push(root);
|
||||||
|
}
|
||||||
|
iterator& operator++()
|
||||||
|
{
|
||||||
|
m_nodes.pop();
|
||||||
|
for (auto& c : m_current->children)
|
||||||
|
m_nodes.push(&c);
|
||||||
|
m_current = m_nodes.size() ? m_nodes.top() : nullptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Node& operator*() { return *m_current; }
|
||||||
|
Node* operator->() { return m_current; }
|
||||||
|
bool operator==(const iterator& rhs) { return m_current == rhs.m_current; }
|
||||||
|
bool operator!=(const iterator& rhs) { return m_current != rhs.m_current; }
|
||||||
|
};
|
||||||
|
iterator begin()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
iterator end()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user