started implementing dynamic widget allocation by xml tag
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
</plane>
|
</plane>
|
||||||
<!-- content panel -->
|
<!-- content panel -->
|
||||||
<plane width="1" grow="1" height="100%" pad="30" wrap="1">
|
<plane width="1" grow="1" height="100%" pad="30" wrap="1">
|
||||||
<plane color=".2" height="100%"></plane>
|
<border color=".2" height="100%"></border>
|
||||||
</plane>
|
</plane>
|
||||||
</plane>
|
</plane>
|
||||||
<!-- status bar -->
|
<!-- status bar -->
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
AD58E0761E3421F2006ACC15 /* YGNodeList.c in Sources */ = {isa = PBXBuildFile; fileRef = AD58E0741E3421F2006ACC15 /* YGNodeList.c */; };
|
AD58E0761E3421F2006ACC15 /* YGNodeList.c in Sources */ = {isa = PBXBuildFile; fileRef = AD58E0741E3421F2006ACC15 /* YGNodeList.c */; };
|
||||||
AD58E0771E3421F2006ACC15 /* Yoga.c in Sources */ = {isa = PBXBuildFile; fileRef = AD58E0751E3421F2006ACC15 /* Yoga.c */; };
|
AD58E0771E3421F2006ACC15 /* Yoga.c in Sources */ = {isa = PBXBuildFile; fileRef = AD58E0751E3421F2006ACC15 /* Yoga.c */; };
|
||||||
AD58E0791E342205006ACC15 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD58E0781E342205006ACC15 /* tinyxml2.cpp */; };
|
AD58E0791E342205006ACC15 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD58E0781E342205006ACC15 /* tinyxml2.cpp */; };
|
||||||
|
ADB61C821E3D38450093280F /* util.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADB61C801E3D38450093280F /* util.cpp */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
@@ -61,6 +62,8 @@
|
|||||||
AD58E0741E3421F2006ACC15 /* YGNodeList.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = YGNodeList.c; path = libs/yoga/yoga/YGNodeList.c; sourceTree = "<group>"; };
|
AD58E0741E3421F2006ACC15 /* YGNodeList.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = YGNodeList.c; path = libs/yoga/yoga/YGNodeList.c; sourceTree = "<group>"; };
|
||||||
AD58E0751E3421F2006ACC15 /* Yoga.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Yoga.c; path = libs/yoga/yoga/Yoga.c; sourceTree = "<group>"; };
|
AD58E0751E3421F2006ACC15 /* Yoga.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Yoga.c; path = libs/yoga/yoga/Yoga.c; sourceTree = "<group>"; };
|
||||||
AD58E0781E342205006ACC15 /* tinyxml2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tinyxml2.cpp; path = libs/tinyxml2/tinyxml2.cpp; sourceTree = "<group>"; };
|
AD58E0781E342205006ACC15 /* tinyxml2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tinyxml2.cpp; path = libs/tinyxml2/tinyxml2.cpp; sourceTree = "<group>"; };
|
||||||
|
ADB61C801E3D38450093280F /* util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = util.cpp; sourceTree = "<group>"; };
|
||||||
|
ADB61C811E3D38450093280F /* util.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = util.hpp; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -116,6 +119,8 @@
|
|||||||
AD58E0671E2A7741006ACC15 /* image.hpp */,
|
AD58E0671E2A7741006ACC15 /* image.hpp */,
|
||||||
AD58E0691E2A774F006ACC15 /* texture.cpp */,
|
AD58E0691E2A774F006ACC15 /* texture.cpp */,
|
||||||
AD58E06A1E2A774F006ACC15 /* texture.hpp */,
|
AD58E06A1E2A774F006ACC15 /* texture.hpp */,
|
||||||
|
ADB61C801E3D38450093280F /* util.cpp */,
|
||||||
|
ADB61C811E3D38450093280F /* util.hpp */,
|
||||||
AD58E06C1E2A78BD006ACC15 /* pch.h */,
|
AD58E06C1E2A78BD006ACC15 /* pch.h */,
|
||||||
);
|
);
|
||||||
path = engine;
|
path = engine;
|
||||||
@@ -191,6 +196,7 @@
|
|||||||
AD58E06F1E2A80BC006ACC15 /* shape.cpp in Sources */,
|
AD58E06F1E2A80BC006ACC15 /* shape.cpp in Sources */,
|
||||||
AD58E0651E2A76FD006ACC15 /* shader.cpp in Sources */,
|
AD58E0651E2A76FD006ACC15 /* shader.cpp in Sources */,
|
||||||
AD58E0761E3421F2006ACC15 /* YGNodeList.c in Sources */,
|
AD58E0761E3421F2006ACC15 /* YGNodeList.c in Sources */,
|
||||||
|
ADB61C821E3D38450093280F /* util.cpp in Sources */,
|
||||||
AD58E06B1E2A774F006ACC15 /* texture.cpp in Sources */,
|
AD58E06B1E2A774F006ACC15 /* texture.cpp in Sources */,
|
||||||
AD3B1EC01E3B8B7600E918E3 /* layout.cpp in Sources */,
|
AD3B1EC01E3B8B7600E918E3 /* layout.cpp in Sources */,
|
||||||
AD58E0721E2A90EF006ACC15 /* app.cpp in Sources */,
|
AD58E0721E2A90EF006ACC15 /* app.cpp in Sources */,
|
||||||
|
|||||||
@@ -109,8 +109,6 @@ void App::init()
|
|||||||
|
|
||||||
void App::update(float dt)
|
void App::update(float dt)
|
||||||
{
|
{
|
||||||
glm::mat4 proj = glm::ortho(0.f, width, height, 0.f, -1.f, 1.f);
|
|
||||||
|
|
||||||
glClearColor(.1f, .1f, .1f, 1.f);
|
glClearColor(.1f, .1f, .1f, 1.f);
|
||||||
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
@@ -129,23 +127,21 @@ void App::update(float dt)
|
|||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
for (auto& n : layout)
|
for (auto& n : layout)
|
||||||
{
|
{
|
||||||
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
|
||||||
glm::mat4 scale = glm::scale(glm::vec3(n.m_size, 1.f));
|
|
||||||
glm::mat4 pos = glm::translate(glm::vec3(n.m_pos, 0));
|
|
||||||
auto mvp = proj * pos * scale * pivot;
|
|
||||||
|
|
||||||
auto box = n.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", n.color);
|
if (n.m_widget)
|
||||||
shader_color.use();
|
{
|
||||||
shader_color.u_mat4("mvp", mvp);
|
shader_color.u_vec4("col", n.color);
|
||||||
plane.draw_fill();
|
shader_color.use();
|
||||||
|
shader_color.u_mat4("mvp", n.m_widget->mvp);
|
||||||
|
plane.draw_fill();
|
||||||
|
|
||||||
shader_color.u_vec4("col", { 1, 1, 1, 1 });
|
shader_color.u_vec4("col", { 1, 1, 1, 1 });
|
||||||
shader_color.use();
|
shader_color.use();
|
||||||
shader_color.u_mat4("mvp", mvp);
|
shader_color.u_mat4("mvp", n.m_widget->mvp);
|
||||||
plane.draw_stroke();
|
plane.draw_stroke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
tex.unbind();
|
tex.unbind();
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
Plane* WidgetBorder::m_plane;
|
||||||
|
|
||||||
void Node::update(float width, float height)
|
void Node::update(float width, float height)
|
||||||
{
|
{
|
||||||
YGNodeStyleSetWidth(y_node, width);
|
YGNodeStyleSetWidth(y_node, width);
|
||||||
YGNodeStyleSetHeight(y_node, height);
|
YGNodeStyleSetHeight(y_node, height);
|
||||||
YGNodeCalculateLayout(y_node, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(y_node, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
update_internal({ 0, 0 });
|
glm::mat4 proj = glm::ortho(0.f, m_size.x, m_size.y, 0.f, -1.f, 1.f);
|
||||||
|
update_internal({ 0, 0 }, proj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::update_internal(glm::vec2 origin)
|
void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||||
{
|
{
|
||||||
float x = YGNodeLayoutGetLeft(y_node);
|
float x = YGNodeLayoutGetLeft(y_node);
|
||||||
float y = YGNodeLayoutGetTop(y_node);
|
float y = YGNodeLayoutGetTop(y_node);
|
||||||
@@ -17,12 +21,17 @@ void Node::update_internal(glm::vec2 origin)
|
|||||||
float h = YGNodeLayoutGetHeight(y_node);
|
float h = YGNodeLayoutGetHeight(y_node);
|
||||||
m_pos = origin + glm::vec2(x, y);
|
m_pos = origin + glm::vec2(x, y);
|
||||||
m_size = glm::vec2(w, h);
|
m_size = glm::vec2(w, h);
|
||||||
if (!parent)
|
m_clip = !parent ? glm::vec4(m_pos, m_size) : rect_intersection(glm::vec4(m_pos, m_size), parent->m_clip);
|
||||||
m_clip = glm::vec4(m_pos, m_size);
|
if (m_widget)
|
||||||
else
|
{
|
||||||
m_clip = rect_intersection(glm::vec4(m_pos, m_size), parent->m_clip);
|
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
||||||
|
glm::mat4 scale = glm::scale(glm::vec3(m_size, 1.f));
|
||||||
|
glm::mat4 pos = glm::translate(glm::vec3(m_pos, 0));
|
||||||
|
m_widget->mvp = proj * pos * scale * pivot;
|
||||||
|
m_widget->clip = m_clip;
|
||||||
|
}
|
||||||
for (auto& c : m_children)
|
for (auto& c : m_children)
|
||||||
c.update_internal(m_pos);
|
c.update_internal(m_pos, proj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* attr)
|
void Node::parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* attr)
|
||||||
@@ -179,9 +188,18 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
|
|||||||
{
|
{
|
||||||
m_name = x_node->Name();
|
m_name = x_node->Name();
|
||||||
auto attr = x_node->FirstAttribute();
|
auto attr = x_node->FirstAttribute();
|
||||||
|
|
||||||
|
att::kWidget widget_id = (att::kWidget)const_hash(x_node->Name());
|
||||||
|
switch (widget_id)
|
||||||
|
{
|
||||||
|
case att::kWidget::Border:
|
||||||
|
m_widget = std::make_unique<WidgetBorder>();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
while (attr)
|
while (attr)
|
||||||
{
|
{
|
||||||
parse_attributes((att::kAttribute)att::const_hash(attr->Name()), attr);
|
parse_attributes((att::kAttribute)const_hash(attr->Name()), attr);
|
||||||
attr = attr->Next();
|
attr = attr->Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "shape.hpp"
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
namespace att
|
namespace att
|
||||||
{
|
{
|
||||||
uint16_t constexpr const_hash(char const *input)
|
|
||||||
{
|
|
||||||
return *input ?
|
|
||||||
static_cast<uint16_t>(*input) + 33 * const_hash(input + 1) :
|
|
||||||
5381;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class kAttribute : uint16_t
|
enum class kAttribute : uint16_t
|
||||||
{
|
{
|
||||||
Width = const_hash("width"),
|
Width = const_hash("width"),
|
||||||
@@ -107,13 +102,20 @@ namespace att
|
|||||||
|
|
||||||
class Widget
|
class Widget
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
glm::mat4 mvp;
|
||||||
|
glm::vec4 clip;
|
||||||
|
virtual void draw() { };
|
||||||
};
|
};
|
||||||
|
|
||||||
class WidgetBorder : public Widget
|
class WidgetBorder : public Widget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static class Plane* m_plane;
|
static Plane* m_plane;
|
||||||
|
virtual void draw() override
|
||||||
|
{
|
||||||
|
m_plane->draw_fill();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Node
|
class Node
|
||||||
@@ -186,11 +188,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update(float width, float height);
|
void update(float width, float height);
|
||||||
void update_internal(glm::vec2 origin);
|
void update_internal(const glm::vec2& origin, const glm::mat4& proj);
|
||||||
void parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* attr);
|
void parse_attributes(att::kAttribute ka, const tinyxml2::XMLAttribute* attr);
|
||||||
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();
|
||||||
|
void draw();
|
||||||
|
|
||||||
class iterator
|
class iterator
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,18 +80,18 @@ void Shader::use()
|
|||||||
{
|
{
|
||||||
glUseProgram(prog);
|
glUseProgram(prog);
|
||||||
}
|
}
|
||||||
void Shader::u_vec4(std::string name, const glm::vec4& v)
|
void Shader::u_vec4(const char* name, const glm::vec4& v)
|
||||||
{
|
{
|
||||||
auto loc = glGetUniformLocation(prog, name.c_str());
|
auto loc = glGetUniformLocation(prog, name);
|
||||||
glUniform4fv(loc, 1, glm::value_ptr(v));
|
glUniform4fv(loc, 1, glm::value_ptr(v));
|
||||||
}
|
}
|
||||||
void Shader::u_mat4(std::string name, const glm::mat4& m)
|
void Shader::u_mat4(const char* name, const glm::mat4& m)
|
||||||
{
|
{
|
||||||
auto loc = glGetUniformLocation(prog, name.c_str());
|
auto loc = glGetUniformLocation(prog, name);
|
||||||
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(m));
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(m));
|
||||||
}
|
}
|
||||||
void Shader::u_int(std::string name, int i)
|
void Shader::u_int(const char* name, int i)
|
||||||
{
|
{
|
||||||
auto loc = glGetUniformLocation(prog, name.c_str());
|
auto loc = glGetUniformLocation(prog, name);
|
||||||
glUniform1i(loc, i);
|
glUniform1i(loc, i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
class Shader
|
class Shader
|
||||||
{
|
{
|
||||||
@@ -6,7 +7,19 @@ class Shader
|
|||||||
public:
|
public:
|
||||||
bool create(std::string vertex, std::string fragment);
|
bool create(std::string vertex, std::string fragment);
|
||||||
void use();
|
void use();
|
||||||
void u_vec4(std::string name, const glm::vec4& v);
|
void u_vec4(const char* name, const glm::vec4& v);
|
||||||
void u_mat4(std::string name, const glm::mat4& m);
|
void u_mat4(const char* name, const glm::mat4& m);
|
||||||
void u_int(std::string name, int i);
|
void u_int(const char* name, int i);
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class kShader : uint16_t
|
||||||
|
{
|
||||||
|
Color = const_hash("color"),
|
||||||
|
};
|
||||||
|
|
||||||
|
class ShaderManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void use(kShader id);
|
||||||
|
static void use(const char* name);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "layout.h"
|
|
||||||
|
|
||||||
class Shape
|
class Shape
|
||||||
{
|
{
|
||||||
@@ -10,7 +9,7 @@ protected:
|
|||||||
GLvoid* ioff[2]{ 0 };
|
GLvoid* ioff[2]{ 0 };
|
||||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
||||||
public:
|
public:
|
||||||
att::AttrubutesMap attribs;
|
// att::AttrubutesMap attribs;
|
||||||
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
|
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
|
||||||
void draw_fill() const;
|
void draw_fill() const;
|
||||||
void draw_stroke() const;
|
void draw_stroke() const;
|
||||||
@@ -57,6 +56,7 @@ public:
|
|||||||
create_impl(w, h, div, idx, vertices);
|
create_impl(w, h, div, idx, vertices);
|
||||||
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
bool create(att::Divisions divisions, att::Width w, att::Height h)
|
bool create(att::Divisions divisions, att::Width w, att::Height h)
|
||||||
{
|
{
|
||||||
const int div = divisions.value;
|
const int div = divisions.value;
|
||||||
@@ -80,6 +80,7 @@ public:
|
|||||||
const auto d = get_attribute(att::Divisions(1));
|
const auto d = get_attribute(att::Divisions(1));
|
||||||
return create(d, w, h);
|
return create(d, w, h);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
class RectShape : public Shape
|
class RectShape : public Shape
|
||||||
|
|||||||
3
engine/util.cpp
Normal file
3
engine/util.cpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
8
engine/util.hpp
Normal file
8
engine/util.hpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
uint16_t constexpr const_hash(char const *input)
|
||||||
|
{
|
||||||
|
return *input ?
|
||||||
|
static_cast<uint16_t>(*input) + 33 * const_hash(input + 1) :
|
||||||
|
5381;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user