add spacebar to rotate the view

This commit is contained in:
2019-08-06 08:33:19 +02:00
parent 6785feb9d9
commit 678114fca1
2 changed files with 37 additions and 14 deletions

View File

@@ -22,6 +22,13 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
// m_pan_start = Canvas::I->m_pan;
// node->mouse_capture();
// }
if (App::I->keys[(int)kKey::KeySpacebar])
{
m_draggingL = true;
m_pan_start = Canvas::I->m_pan;
m_dragL_start = me->m_pos;
node->mouse_capture();
}
break;
case kEventType::MouseUpL:
// if (Canvas::I->m_touch_lock && me->m_source == kEventSource::Touch)
@@ -29,6 +36,11 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
// m_draggingR = false;
// node->mouse_release();
// }
if (m_draggingL)
{
m_draggingL = false;
node->mouse_release();
}
break;
case kEventType::MouseDownR:
if (App::I->keys[(int)kKey::KeyAlt])
@@ -60,6 +72,12 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
}
}
if (m_draggingL)
{
Canvas::I->m_pan = m_pan_start + (me->m_pos - m_dragL_start) * glm::vec2(-1, -1) * (Canvas::I->m_cam_fov / 85.f);
auto angle = Canvas::I->m_pan * 0.003f;
Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
}
break;
case kEventType::MouseScroll:
m_zoom_canvas += me->m_scroll_delta * 0.1f;
@@ -128,23 +146,26 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
switch (me->m_type)
{
case kEventType::MouseDownL:
if (App::I->keys[(int)kKey::KeyAlt] || m_picking)
if (!App::I->keys[(int)kKey::KeySpacebar])
{
m_picking = true;
Canvas::I->pick_start();
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I->brush_update();
}
else
{
App::I->render_task_async([loc, pr=me->m_pressure]
if (App::I->keys[(int)kKey::KeyAlt] || m_picking)
{
Canvas::I->stroke_start({ loc, 0 }, pr);
});
m_picking = true;
Canvas::I->pick_start();
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I->brush_update();
}
else
{
App::I->render_task_async([loc, pr = me->m_pressure]
{
Canvas::I->stroke_start({ loc, 0 }, pr);
});
}
m_dragging = true;
node->mouse_capture();
}
m_dragging = true;
node->mouse_capture();
break;
case kEventType::MouseUpL:
if (m_dragging && !m_picking)

View File

@@ -56,9 +56,11 @@ public:
class CanvasModeBasicCamera : public CanvasMode
{
bool m_draggingR = false;
bool m_draggingL = false;
bool m_draggingT = false; // touch drag
bool m_zooming = false;
glm::vec2 m_dragR_start;
glm::vec2 m_dragL_start;
glm::vec2 m_pan_start;
float m_fov_start;
float m_camera_fov;