diff --git a/src/video_display.cpp b/src/video_display.cpp index 5107e2b29..7f9a8d512 100644 --- a/src/video_display.cpp +++ b/src/video_display.cpp @@ -193,7 +193,7 @@ void VideoDisplay::Render() try { PositionVideo(); videoOut->Render(viewport_left, viewport_bottom, viewport_width, viewport_height); - E(glViewport(0, viewport_bottom, videoSize.GetWidth(), videoSize.GetHeight())); + E(glViewport(0, viewport_bottom_end, videoSize.GetWidth(), videoSize.GetHeight())); E(glMatrixMode(GL_PROJECTION)); E(glLoadIdentity()); @@ -270,8 +270,11 @@ void VideoDisplay::PositionVideo() { auto provider = con->project->VideoProvider(); if (!provider || !IsShownOnScreen()) return; + int client_w, client_h; + GetClientSize(&client_w, &client_h); + viewport_left = 0; - viewport_bottom = GetClientSize().GetHeight() * scale_factor - videoSize.GetHeight(); + viewport_bottom_end = viewport_bottom = client_h * scale_factor - videoSize.GetHeight(); viewport_top = 0; viewport_width = videoSize.GetWidth(); viewport_height = videoSize.GetHeight(); @@ -299,12 +302,15 @@ void VideoDisplay::PositionVideo() { } viewport_left += pan_x; + viewport_top += pan_y; viewport_bottom -= pan_y; + viewport_bottom_end = std::min(viewport_bottom_end, 0); - if (tool) + if (tool) { + tool->SetClientSize(viewport_width, viewport_height); tool->SetDisplayArea(viewport_left / scale_factor, viewport_top / scale_factor, viewport_width / scale_factor, viewport_height / scale_factor); - + } Render(); } @@ -368,11 +374,8 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) { PositionVideo(); } - if (tool) { - if (pan_y) - event.SetPosition(wxPoint(event.GetX(), event.GetY() - pan_y)); + if (tool) tool->OnMouseEvent(event); - } } void VideoDisplay::OnMouseLeave(wxMouseEvent& event) { diff --git a/src/video_display.h b/src/video_display.h index 680873518..502442175 100644 --- a/src/video_display.h +++ b/src/video_display.h @@ -79,6 +79,8 @@ class VideoDisplay final : public wxGLCanvas { int viewport_width = 0; /// Screen pixels between the bottom of the canvas and the bottom of the video; used for glViewport int viewport_bottom = 0; + /// The REAL bottom of the viewport; used only for glViewport + int viewport_bottom_end = 0; /// Screen pixels between the bottom of the canvas and the top of the video; used for coordinate space conversion int viewport_top = 0; /// The height of the video in screen pixels diff --git a/src/visual_tool.cpp b/src/visual_tool.cpp index 61d320722..6465fe248 100644 --- a/src/visual_tool.cpp +++ b/src/visual_tool.cpp @@ -132,6 +132,10 @@ AssDialogue* VisualToolBase::GetActiveDialogueLine() { return nullptr; } +void VisualToolBase::SetClientSize(int w, int h) { + client_size = Vector2D(w, h); +} + void VisualToolBase::SetDisplayArea(int x, int y, int w, int h) { if (x == video_pos.X() && y == video_pos.Y() && w == video_res.X() && h == video_res.Y()) return; diff --git a/src/visual_tool.h b/src/visual_tool.h index 72eec4224..15d0b007d 100644 --- a/src/visual_tool.h +++ b/src/visual_tool.h @@ -104,6 +104,7 @@ protected: Vector2D script_res; ///< Script resolution Vector2D video_pos; ///< Top-left corner of the video in the display area Vector2D video_res; ///< Video resolution + Vector2D client_size; ///< The size of the display area const agi::OptionValue *highlight_color_primary_opt; const agi::OptionValue *highlight_color_secondary_opt; @@ -144,6 +145,7 @@ public: // Stuff called by VideoDisplay virtual void OnMouseEvent(wxMouseEvent &event)=0; virtual void Draw()=0; + virtual void SetClientSize(int w, int h); virtual void SetDisplayArea(int x, int y, int w, int h); virtual void SetToolbar(wxToolBar *) { } virtual ~VisualToolBase() = default; diff --git a/src/visual_tool_cross.cpp b/src/visual_tool_cross.cpp index 624cd7613..87783c616 100644 --- a/src/visual_tool_cross.cpp +++ b/src/visual_tool_cross.cpp @@ -69,10 +69,10 @@ void VisualToolCross::Draw() { gl.SetInvert(); gl.SetLineColour(*wxWHITE, 1.0, 1); float lines[] = { - video_pos.X(), mouse_pos.Y(), - video_res.X() + video_pos.X(), mouse_pos.Y(), + 0.f, mouse_pos.Y(), + client_size.X(), mouse_pos.Y(), mouse_pos.X(), 0.f, - mouse_pos.X(), video_res.Y() + video_pos.Y() * 2 + mouse_pos.X(), client_size.Y(), }; gl.DrawLines(2, lines, 4); gl.ClearInvert();