added color quad and hue slider

This commit is contained in:
2017-03-21 09:56:33 +00:00
parent 13fa84a02c
commit 03a5212e56
6 changed files with 202 additions and 28 deletions

View File

@@ -45,6 +45,7 @@ enum class kAttribute : uint16_t
enum class kWidget : uint16_t
{
Node = const_hash("node"),
Border = const_hash("border"),
Shape = const_hash("shape"),
Text = const_hash("text"),
@@ -53,7 +54,9 @@ enum class kWidget : uint16_t
Button = const_hash("button"),
ButtonCustom = const_hash("button-custom"),
SliderCursor = const_hash("slider-cursor"),
Slider = const_hash("slider"),
SliderH = const_hash("slider-h"),
SliderV = const_hash("slider-v"),
SliderHue = const_hash("slider-hue"),
PopupMenu = const_hash("popup-menu"),
Viewport = const_hash("viewport"),
Ref = const_hash("ref"),
@@ -61,6 +64,7 @@ enum class kWidget : uint16_t
Layer = const_hash("layer"),
PanelLayers = const_hash("panel-layers"),
PanelBrushes = const_hash("panel-brushes"),
ColorQuad = const_hash("color-quad"),
};
enum class kShapeType : uint16_t
@@ -240,6 +244,7 @@ public:
virtual Node* clone_instantiate() const;
virtual void clone_copy(Node* dest) const;
virtual void clone_children(Node* dest) const;
virtual void clone_finalize(Node* dest) const { /* find controllers and stuff */ };
void watch(std::function<void(Node*)> observer)
{
observer(this);
@@ -375,21 +380,23 @@ public:
ui::ShaderManager::use(kShader::Color);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
if (m_color.a != 1.f)
glEnable(GL_BLEND);
ui::ShaderManager::u_vec4(kShaderUniform::Col, m_color);
m_plane.draw_fill();
if (m_color.a > 0.f)
{
m_color.a < 1.f ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
ui::ShaderManager::u_vec4(kShaderUniform::Col, m_color);
m_plane.draw_fill();
glDisable(GL_BLEND);
}
if (m_thinkness > 0)
if (m_thinkness > 0 && m_border_color.a > 0.f)
{
glLineWidth(m_thinkness);
ui::ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
m_border_color.a < 1.f ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
m_plane.draw_stroke();
glDisable(GL_BLEND);
}
if (m_color.a != 1.f)
glDisable(GL_BLEND);
}
};
@@ -950,16 +957,18 @@ public:
class NodeSliderCursor : public NodeButtonCustom
{
public:
glm::vec2 drag_start;
glm::vec2 drag_diff;
bool dragging = false;
glm::vec2 old_pos;
public:
glm::vec2 m_mask{ 1, 0 };
virtual Node* clone_instantiate() const override { return new NodeSliderCursor(); }
virtual void clone_copy(Node* dest) const override
{
NodeButtonCustom::clone_copy(dest);
NodeSliderCursor* n = static_cast<NodeSliderCursor*>(dest);
n->m_mask = m_mask;
}
virtual kEventResult handle_event(Event* e) override
{
@@ -979,11 +988,10 @@ public:
case kEventType::MouseMove:
if (dragging)
{
float pw = parent->GetWidth();
float w = GetWidth();
drag_diff = old_pos + ((MouseEvent*)e)->m_pos - drag_start;
float x = glm::clamp<float>(drag_diff.x, 0, pw - w);
SetPosition(x, 0);
auto sz = parent->GetSize() - GetSize();
drag_diff = old_pos + (((MouseEvent*)e)->m_pos - drag_start) * m_mask;
auto pos = glm::clamp(drag_diff, { 0, 0 }, sz);
SetPosition(pos.x, pos.y);
}
break;
default:
@@ -993,18 +1001,69 @@ public:
}
};
class NodeSlider : public NodeBorder
class NodeSliderH : public NodeBorder
{
public:
NodeSliderCursor* m_cursor;
virtual Node* clone_instantiate() const override { return new NodeSlider(); }
virtual Node* clone_instantiate() const override { return new NodeSliderH(); }
virtual void init() override
{
const auto& m_template = (NodeBorder*)init_template("tpl-slider");
const auto& m_template = (NodeBorder*)init_template("tpl-slider-h");
m_color = m_template->m_color;
m_border_color = m_template->m_border_color;
m_thinkness = m_thinkness;
m_cursor = find<NodeSliderCursor>("cursor");
m_cursor->m_mask = { 1, 0 };
}
};
class NodeSliderV : public NodeBorder
{
public:
NodeSliderCursor* m_cursor;
virtual Node* clone_instantiate() const override { return new NodeSliderV(); }
virtual void init() override
{
const auto& m_template = (NodeBorder*)init_template("tpl-slider-v");
m_color = m_template->m_color;
m_border_color = m_template->m_border_color;
m_thinkness = m_thinkness;
m_cursor = find<NodeSliderCursor>("cursor");
m_cursor->m_mask = { 0, 1 };
}
};
class NodeSliderHue : public NodeBorder
{
public:
NodeSliderCursor* m_cursor;
virtual Node* clone_instantiate() const override { return new NodeSliderHue(); }
virtual void clone_finalize(Node* dest) const override
{
NodeSliderHue* n = static_cast<NodeSliderHue*>(dest);
n->m_cursor = n->find<NodeSliderCursor>("cursor");
n->m_cursor->m_color = glm::vec4(0);
n->m_cursor->m_border_color = glm::vec4(0, 0, 0, 1);
}
virtual void init() override
{
const auto& m_template = (NodeBorder*)init_template("tpl-slider-hue");
m_color = m_template->m_color;
m_border_color = m_template->m_border_color;
m_thinkness = m_thinkness;
m_cursor = find<NodeSliderCursor>("cursor");
m_cursor->m_mask = { 0, 1 };
m_cursor->m_thinkness = 1;
m_cursor->m_color = glm::vec4(0);
m_cursor->m_border_color = glm::vec4(0, 0, 0, 1);
}
virtual void draw() override
{
using namespace ui;
ui::ShaderManager::use(kShader::ColorHue);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
//ui::ShaderManager::u_vec4(kShaderUniform::Col, m_color);
m_plane.draw_fill();
}
};
@@ -1277,7 +1336,8 @@ public:
}
virtual void draw() override
{
m_color = m_selected ? glm::vec4(1, 0, 0, 1) : color_normal;
m_color = m_mouse_inside ? color_hover : color_normal;
m_color = m_selected ? glm::vec4(.9, 0, 0, 1) : m_color;
NodeButtonCustom::draw();
}
};
@@ -1321,7 +1381,8 @@ public:
m_current->m_selected = false;
m_current = (NodeButtonBrush*)target;
m_current->m_selected = true;
on_brush_changed(this, m_current->m_brushID);
if (on_brush_changed)
on_brush_changed(this, m_current->m_brushID);
}
std::vector<std::string> FindAllBrushes(std::string folder)
{
@@ -1342,3 +1403,31 @@ public:
return names;
}
};
class NodeColorQuad : public NodeBorder
{
public:
virtual Node* clone_instantiate() const override { return new NodeColorQuad(); }
virtual void draw() override
{
using namespace ui;
ui::ShaderManager::use(kShader::ColorQuad);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
// if (m_color.a != 1.f)
// glEnable(GL_BLEND);
ui::ShaderManager::u_vec4(kShaderUniform::Col, m_color);
m_plane.draw_fill();
// if (m_thinkness > 0)
// {
// glLineWidth(m_thinkness);
// ui::ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
// m_plane.draw_stroke();
// }
// if (m_color.a != 1.f)
// glDisable(GL_BLEND);
}
};