From e3949cdaa1ccbc074a6cbc4e522ba8e6a48c8008 Mon Sep 17 00:00:00 2001 From: moex3 <46636583+moex3@users.noreply.github.com> Date: Mon, 23 Nov 2020 20:19:29 +0100 Subject: [PATCH] Add video panning --- src/video_display.cpp | 24 ++++++++++++++++++++++-- src/video_display.h | 9 +++++++++ src/visual_tool_cross.cpp | 4 ++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/video_display.cpp b/src/video_display.cpp index 8d85311a6..73df313ba 100644 --- a/src/video_display.cpp +++ b/src/video_display.cpp @@ -113,6 +113,8 @@ VideoDisplay::VideoDisplay(wxToolBar *toolbar, bool freeSize, wxComboBox *zoomBo Bind(wxEVT_LEFT_DCLICK, &VideoDisplay::OnMouseEvent, this); Bind(wxEVT_LEFT_DOWN, &VideoDisplay::OnMouseEvent, this); Bind(wxEVT_LEFT_UP, &VideoDisplay::OnMouseEvent, this); + Bind(wxEVT_MIDDLE_DOWN, &VideoDisplay::OnMouseEvent, this); + Bind(wxEVT_MIDDLE_UP, &VideoDisplay::OnMouseEvent, this); Bind(wxEVT_MOTION, &VideoDisplay::OnMouseEvent, this); Bind(wxEVT_MOUSEWHEEL, &VideoDisplay::OnMouseWheel, this); @@ -191,7 +193,7 @@ void VideoDisplay::Render() try { PositionVideo(); videoOut->Render(viewport_left, viewport_bottom, viewport_width, viewport_height); - E(glViewport(0, std::min(viewport_bottom, 0), videoSize.GetWidth(), videoSize.GetHeight())); + E(glViewport(0, viewport_bottom, videoSize.GetWidth(), videoSize.GetHeight())); E(glMatrixMode(GL_PROJECTION)); E(glLoadIdentity()); @@ -296,6 +298,9 @@ void VideoDisplay::PositionVideo() { } } + viewport_left += pan_x; + viewport_bottom -= pan_y; + if (tool) tool->SetDisplayArea(viewport_left / scale_factor, viewport_top / scale_factor, viewport_width / scale_factor, viewport_height / scale_factor); @@ -351,8 +356,23 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) { last_mouse_pos = mouse_pos = event.GetPosition(); - if (tool) + if (event.GetButton() == wxMOUSE_BTN_MIDDLE) { + if ((panning = event.ButtonDown())) + pan_last_pos = event.GetPosition(); + } + if (panning && event.Dragging()) { + pan_x += event.GetX() - pan_last_pos.X(); + pan_y += event.GetY() - pan_last_pos.Y(); + pan_last_pos = event.GetPosition(); + + PositionVideo(); + } + + if (tool) { + if (pan_y) + event.SetPosition(wxPoint(event.GetX(), event.GetY() - pan_y)); tool->OnMouseEvent(event); + } } void VideoDisplay::OnMouseLeave(wxMouseEvent& event) { diff --git a/src/video_display.h b/src/video_display.h index f0d65edb6..46ed78a69 100644 --- a/src/video_display.h +++ b/src/video_display.h @@ -87,6 +87,15 @@ class VideoDisplay final : public wxGLCanvas { /// The current zoom level, where 1.0 = 100% double zoomValue; + /// The last position of the mouse, when dragging + Vector2D pan_last_pos; + /// True if middle mouse button is down, and we should update pan_{x,y} + bool panning = false; + /// The current video pan offset width + int pan_x = 0; + /// The current video pan offset height + int pan_y = 0; + /// The video renderer std::unique_ptr videoOut; diff --git a/src/visual_tool_cross.cpp b/src/visual_tool_cross.cpp index ffbf5329b..624cd7613 100644 --- a/src/visual_tool_cross.cpp +++ b/src/visual_tool_cross.cpp @@ -69,8 +69,8 @@ void VisualToolCross::Draw() { gl.SetInvert(); gl.SetLineColour(*wxWHITE, 1.0, 1); float lines[] = { - 0.f, mouse_pos.Y(), - video_res.X() + video_pos.X() * 2, mouse_pos.Y(), + video_pos.X(), mouse_pos.Y(), + video_res.X() + video_pos.X(), mouse_pos.Y(), mouse_pos.X(), 0.f, mouse_pos.X(), video_res.Y() + video_pos.Y() * 2 };