color wheel and picker

This commit is contained in:
2017-12-05 22:25:38 +00:00
parent 8a21f3f78a
commit 9978709645
12 changed files with 226 additions and 42 deletions

View File

@@ -29,7 +29,7 @@ void NodeColorQuad::set_value(float x, float y)
{
auto sz = m_size;
auto pos = glm::clamp(glm::vec2(x, y) * sz, { 0, 0 }, sz);
m_picker->SetPosition(pos - m_picker->GetSize() * .5f);
//m_picker->SetPosition(pos - m_picker->GetSize() * .5f);
m_value = pos / glm::max({ 1,1 }, sz); // avoid div0
if (on_value_changed)
on_value_changed(this, m_value);
@@ -86,6 +86,11 @@ kEventResult NodeColorQuad::handle_event(Event* e)
void NodeColorQuad::draw()
{
m_picker->m_border_color = m_value.y > .5f ? glm::vec4(1) : glm::vec4(0, 0, 0, 1);
auto sz = m_size;
auto pos = glm::clamp(m_value * sz, { 0, 0 }, sz);
m_picker->SetPosition(pos - m_picker->GetSize() * .5f);
using namespace ui;
ui::ShaderManager::use(kShader::ColorQuad);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);