adding color picking on iOS
This commit is contained in:
@@ -72,9 +72,10 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
switch (me->m_type)
|
||||
{
|
||||
case kEventType::MouseDownL:
|
||||
if (App::I.keys[(int)kKey::KeyAlt])
|
||||
if (App::I.keys[(int)kKey::KeyAlt] || m_picking)
|
||||
{
|
||||
m_picking = true;
|
||||
canvas->pick_start();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -94,14 +95,46 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
{
|
||||
m_picking = false;
|
||||
node->mouse_release();
|
||||
int x = me->m_pos.x;
|
||||
int y = App::I.height - me->m_pos.y - 1;
|
||||
float pix[3];
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, pix);
|
||||
|
||||
glm::vec4 pix = canvas->pick_get(loc);
|
||||
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
|
||||
App::I.color->m_hue->set_value(hsv.x);
|
||||
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
|
||||
|
||||
/*
|
||||
glm::vec3 ray_origin;
|
||||
glm::vec3 ray_dir;
|
||||
glm::vec3 hit_pos;
|
||||
glm::vec3 hit_normal;
|
||||
int plane_id;
|
||||
if (canvas->point_trace(loc, ray_origin, ray_dir, hit_pos, hit_normal, plane_id))
|
||||
{
|
||||
canvas->m_layers[canvas->m_current_layer_idx].m_rtt[plane_id].bindFramebuffer();
|
||||
glm::vec2 fbpos = (hit_pos.xy() * 0.5f + 0.5f) * glm::vec2(canvas->m_width, canvas->m_height);
|
||||
int x = fbpos.x;
|
||||
int y = fbpos.y;
|
||||
glm::u8vec4 sample;
|
||||
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &sample);
|
||||
glm::vec3 pix = glm::vec3(sample) / 255.f;
|
||||
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
|
||||
App::I.color->m_hue->set_value(hsv.x);
|
||||
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
|
||||
canvas->m_layers[canvas->m_current_layer_idx].m_rtt[plane_id].unbindFramebuffer();
|
||||
}
|
||||
*/
|
||||
/*
|
||||
glm::vec2 fbpos = me->m_pos * node->root()->m_zoom;
|
||||
int x = fbpos.x;
|
||||
int y = App::I.height - fbpos.y - 1;
|
||||
glm::i8vec4 sample;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glReadBuffer(GL_FRONT);
|
||||
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &sample);
|
||||
glm::vec3 pix = glm::vec3(sample) / 255.f;
|
||||
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
|
||||
App::I.color->m_hue->set_value(hsv.x);
|
||||
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
|
||||
*/
|
||||
}
|
||||
break;
|
||||
case kEventType::MouseMove:
|
||||
@@ -109,11 +142,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
canvas->stroke_update(loc, me->m_pressure);
|
||||
if (m_picking)
|
||||
{
|
||||
int x = me->m_pos.x;
|
||||
int y = App::I.height - me->m_pos.y - 1;
|
||||
float pix[3];
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, pix);
|
||||
glm::vec4 pix = canvas->pick_get(loc);
|
||||
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
|
||||
App::I.color->m_hue->set_value(hsv.x);
|
||||
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
|
||||
|
||||
Reference in New Issue
Block a user