fix color picking
This commit is contained in:
@@ -128,8 +128,7 @@ glm::vec4 ui::Canvas::pick_get(glm::vec2 canvas_loc)
|
|||||||
{
|
{
|
||||||
pick_update(plane_id);
|
pick_update(plane_id);
|
||||||
glm::vec2 fbpos = (hit_pos.xy() * 0.5f + 0.5f) * glm::vec2(m_width, m_height);
|
glm::vec2 fbpos = (hit_pos.xy() * 0.5f + 0.5f) * glm::vec2(m_width, m_height);
|
||||||
LOG("pick plane %d x %d y %d", plane_id, (int)fbpos.x, (int)fbpos.y);
|
int i = (int)fbpos.x + (int)fbpos.y * m_width;
|
||||||
int i = fbpos.x + fbpos.y * m_width;
|
|
||||||
return glm::vec4(m_pick_data[plane_id][i]) / 255.f;
|
return glm::vec4(m_pick_data[plane_id][i]) / 255.f;
|
||||||
}
|
}
|
||||||
return {0,0,0,1};
|
return {0,0,0,1};
|
||||||
|
|||||||
@@ -80,20 +80,18 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
canvas->stroke_start(loc, me->m_pressure, node->m_brush);
|
canvas->stroke_start(loc, me->m_pressure, node->m_brush);
|
||||||
m_dragging = true;
|
|
||||||
}
|
}
|
||||||
|
m_dragging = true;
|
||||||
node->mouse_capture();
|
node->mouse_capture();
|
||||||
break;
|
break;
|
||||||
case kEventType::MouseUpL:
|
case kEventType::MouseUpL:
|
||||||
if (m_dragging)
|
if (m_dragging && !m_picking)
|
||||||
{
|
{
|
||||||
canvas->stroke_end();
|
|
||||||
m_dragging = false;
|
|
||||||
node->mouse_release();
|
node->mouse_release();
|
||||||
|
canvas->stroke_end();
|
||||||
}
|
}
|
||||||
if (m_picking)
|
if (m_dragging && m_picking)
|
||||||
{
|
{
|
||||||
m_picking = false;
|
|
||||||
node->mouse_release();
|
node->mouse_release();
|
||||||
|
|
||||||
glm::vec4 pix = canvas->pick_get(loc);
|
glm::vec4 pix = canvas->pick_get(loc);
|
||||||
@@ -136,11 +134,13 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
|||||||
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
|
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
m_dragging = false;
|
||||||
|
m_picking = false;
|
||||||
break;
|
break;
|
||||||
case kEventType::MouseMove:
|
case kEventType::MouseMove:
|
||||||
if (m_dragging)
|
if (m_dragging && !m_picking)
|
||||||
canvas->stroke_update(loc, me->m_pressure);
|
canvas->stroke_update(loc, me->m_pressure);
|
||||||
if (m_picking)
|
if (m_dragging && m_picking)
|
||||||
{
|
{
|
||||||
glm::vec4 pix = canvas->pick_get(loc);
|
glm::vec4 pix = canvas->pick_get(loc);
|
||||||
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
|
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
|
||||||
@@ -158,7 +158,6 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
|||||||
if (m_picking)
|
if (m_picking)
|
||||||
{
|
{
|
||||||
m_picking = false;
|
m_picking = false;
|
||||||
node->mouse_release();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ int main()
|
|||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
// If there any message in the queue process it
|
// If there any message in the queue process it
|
||||||
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
if (!App::I.redraw && PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
||||||
{
|
{
|
||||||
running = !(msg.message == WM_QUIT/* || gl.keys[VK_ESCAPE]*/);
|
running = !(msg.message == WM_QUIT/* || gl.keys[VK_ESCAPE]*/);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
@@ -298,10 +298,13 @@ int main()
|
|||||||
float dt = (float)(t1 - t0) / 1000.0f;
|
float dt = (float)(t1 - t0) / 1000.0f;
|
||||||
if (dt > 1.0f / 60.0f)
|
if (dt > 1.0f / 60.0f)
|
||||||
{
|
{
|
||||||
App::I.clear();
|
|
||||||
App::I.update((float)(t1 - t0) / 1000.0f);
|
|
||||||
t0 = t1;
|
t0 = t1;
|
||||||
SwapBuffers(hDC);
|
if (App::I.redraw)
|
||||||
|
{
|
||||||
|
App::I.clear();
|
||||||
|
App::I.update((float)(t1 - t0) / 1000.0f);
|
||||||
|
SwapBuffers(hDC);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -329,6 +332,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
|||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
App::I.resize((float)LOWORD(lp), (float)HIWORD(lp));
|
App::I.resize((float)LOWORD(lp), (float)HIWORD(lp));
|
||||||
App::I.clear();
|
App::I.clear();
|
||||||
|
App::I.redraw = true;
|
||||||
App::I.update(0.f);
|
App::I.update(0.f);
|
||||||
SwapBuffers(hDC);
|
SwapBuffers(hDC);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user