From 43b6d910fba7585a71c781f8da5454fb994eedde Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 22 Dec 2011 21:31:57 +0000 Subject: [PATCH] Resize the detached video dialog to the specified size when the video zoom is changed. Closes #493. Originally committed to SVN as r6142. --- aegisub/src/dialog_detached_video.cpp | 8 +--- aegisub/src/video_display.cpp | 58 ++++++++++++++++----------- aegisub/src/video_display.h | 3 +- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/aegisub/src/dialog_detached_video.cpp b/aegisub/src/dialog_detached_video.cpp index c9abc5836..0100e6e74 100644 --- a/aegisub/src/dialog_detached_video.cpp +++ b/aegisub/src/dialog_detached_video.cpp @@ -64,19 +64,15 @@ DialogDetachedVideo::DialogDetachedVideo(agi::Context *context, const wxSize &in SetTitle(wxString::Format(_("Video: %s"), wxFileName(context->videoController->GetVideoName()).GetFullName())); - // Set a background panel - wxPanel *panel = new wxPanel(this,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL | wxCLIP_CHILDREN); - // Video area; - VideoBox *videoBox = new VideoBox(panel, true, context); + VideoBox *videoBox = new VideoBox(this, true, context); context->videoDisplay->SetMinClientSize(initialDisplaySize); videoBox->Layout(); // Set sizer wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); mainSizer->Add(videoBox,1,wxEXPAND | wxALL,5); - panel->SetSizer(mainSizer); - mainSizer->SetSizeHints(this); + SetSizerAndFit(mainSizer); // Ensure we can grow smaller, without these the window is locked to at least the initial size context->videoDisplay->SetMinSize(wxSize(1,1)); diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index 6e97fd8ac..45c4f0293 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -113,7 +113,7 @@ VideoDisplay::VideoDisplay( con->videoController->Bind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this); slots.push_back(con->videoController->AddVideoOpenListener(&VideoDisplay::OnVideoOpen, this)); - slots.push_back(con->videoController->AddARChangeListener(&VideoDisplay::UpdateSize, this)); + slots.push_back(con->videoController->AddARChangeListener(&VideoDisplay::UpdateSize, this, true)); Bind(wxEVT_PAINT, std::tr1::bind(&VideoDisplay::Render, this)); Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this); @@ -254,7 +254,7 @@ void VideoDisplay::DrawOverscanMask(float horizontal_percent, float vertical_per E(glDisable(GL_BLEND)); } -void VideoDisplay::UpdateSize() { +void VideoDisplay::UpdateSize(bool force) { if (!con->videoController->IsLoaded()) return; if (!IsShownOnScreen()) return; @@ -264,7 +264,7 @@ void VideoDisplay::UpdateSize() { int arType = con->videoController->GetAspectRatioType(); double arValue = con->videoController->GetAspectRatioValue(); - if (freeSize) { + if (freeSize && !force) { GetClientSize(&w,&h); viewport_left = 0; viewport_bottom = 0; @@ -291,16 +291,25 @@ void VideoDisplay::UpdateSize() { } } else { - wxWindow* parent = GetParent(); - while (!parent->IsTopLevel()) parent = parent->GetParent(); - int maxH, maxW; - parent->GetClientSize(&maxW, &maxH); - + wxEventBlocker blocker(this); h = vidH * zoomValue; w = arType == 0 ? vidW * zoomValue : vidH * zoomValue * arValue; - // Cap the canvas size to the window size - int cw = std::min(w, maxW), ch = std::min(h, maxH); + wxWindow *top = GetParent(); + while (!top->IsTopLevel()) top = top->GetParent(); + + int cw, ch; + if (freeSize) { + cw = w; + ch = h; + } + else { + // Cap the canvas size to the window size + int maxH, maxW; + top->GetClientSize(&maxW, &maxH); + cw = std::min(w, maxW); + ch = std::min(h, maxH); + } viewport_left = 0; viewport_bottom = ch - h; @@ -310,19 +319,22 @@ void VideoDisplay::UpdateSize() { wxSize size(cw, ch); if (size != GetClientSize()) { - SetMinClientSize(size); - SetMaxClientSize(size); + if (freeSize) { + top->SetSize(top->GetSize() + size - GetClientSize()); + SetClientSize(size); + } + else { + SetMinClientSize(size); + SetMaxClientSize(size); - SetEvtHandlerEnabled(false); - GetGrandParent()->Layout(); + GetGrandParent()->Layout(); - // The sizer makes us use the full width, which at very low zoom - // levels results in stretched video, so after using the sizer to - // update the parent window sizes, reset our size to the correct - // value - SetSize(cw, ch); - - SetEvtHandlerEnabled(true); + // The sizer makes us use the full width, which at very low zoom + // levels results in stretched video, so after using the sizer to + // update the parent window sizes, reset our size to the correct + // value + SetSize(cw, ch); + } } } @@ -376,7 +388,7 @@ void VideoDisplay::OnKeyDown(wxKeyEvent &event) { void VideoDisplay::SetZoom(double value) { zoomValue = std::max(value, .125); zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.)); - UpdateSize(); + UpdateSize(true); } void VideoDisplay::SetZoomFromBox(wxCommandEvent &) { @@ -385,7 +397,7 @@ void VideoDisplay::SetZoomFromBox(wxCommandEvent &) { double value; if (strValue.ToDouble(&value)) { zoomValue = value / 100.; - UpdateSize(); + UpdateSize(true); } } diff --git a/aegisub/src/video_display.h b/aegisub/src/video_display.h index 27e31cd85..3a5d5e684 100644 --- a/aegisub/src/video_display.h +++ b/aegisub/src/video_display.h @@ -128,7 +128,8 @@ class VideoDisplay : public wxGLCanvas { void OnVideoOpen(); /// @brief Set the size of the display based on the current zoom and video resolution - void UpdateSize(); + /// @param force Force the size to be set based on zoom even in detached mode + void UpdateSize(bool force = false); /// @brief Set the zoom level to that indicated by the dropdown void SetZoomFromBox(wxCommandEvent&);