add NodeImageTexture for dynamic images, test image thumbnail opening and rendering

This commit is contained in:
2017-05-01 22:22:16 +01:00
parent 3ea3fadc46
commit 16a53af679
7 changed files with 166 additions and 16 deletions

View File

@@ -58,6 +58,7 @@ enum class kWidget : uint16_t
Text = const_hash("text"),
TextInput = const_hash("text-input"),
Image = const_hash("image"),
ImageTexture = const_hash("image-texture"),
Icon = const_hash("icon"),
Button = const_hash("button"),
ButtonCustom = const_hash("button-custom"),
@@ -547,6 +548,39 @@ public:
}
};
class NodeImageTexture : public Node
{
public:
Texture2D tex;
virtual Node* clone_instantiate() const override { return new NodeImageTexture(); }
virtual void clone_copy(Node* dest) const override
{
Node::clone_copy(dest);
NodeImageTexture* n = static_cast<NodeImageTexture*>(dest);
n->tex = tex;
}
// TODO: maybe we can save the texture data and restore later
//virtual void restore_context() override
//{
// Node::restore_context();
// create();
//}
virtual void draw() override
{
using namespace ui;
tex.bind();
NodeImage::m_sampler.bind(0);
glEnable(GL_BLEND);
ui::ShaderManager::use(kShader::Texture);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
NodeImage::m_plane.draw_fill();
NodeImage::m_sampler.unbind();
tex.unbind();
glDisable(GL_BLEND);
}
};
class NodeButton : public Node
{
public:
@@ -1928,10 +1962,6 @@ public:
//glm::mat4 proj = glm::ortho(0.f, box.z, 0.f, box.w, -1000.f, 1000.f);
glm::mat4 proj = glm::perspective(glm::radians(m_canvas->m_cam_fov), box.z / box.w, 0.1f, 1000.f);
glm::mat4 camera = glm::eulerAngleXY(m_canvas->m_cam_rot.y, m_canvas->m_cam_rot.x);
glm::mat4 transform =
glm::translate(glm::vec3(m_pan + m_size * 0.5f * zoom, -1)) * // pan
glm::scale(glm::vec3(zoom * m_zoom_canvas, zoom * m_zoom_canvas, 1)) *
glm::eulerAngleY(glm::radians(0.f));
m_canvas->m_mv = camera;
m_canvas->m_proj = proj;