1
0
Fork 0

Add video panning

This commit is contained in:
moex3 2020-11-23 20:19:29 +01:00 committed by Sodra
parent f21d8a3607
commit e3949cdaa1
3 changed files with 33 additions and 4 deletions

View File

@ -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) {

View File

@ -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<VideoOutGL> videoOut;

View File

@ -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
};