From 0e7501f45cec4ee48b15e0749349fe9da2653e22 Mon Sep 17 00:00:00 2001
From: Thomas Goyne <plorkyeran@aegisub.org>
Date: Sat, 27 Oct 2012 20:44:09 -0700
Subject: [PATCH] Fix some cases where the detached video dialog would get set
 to bogus sizes

At very large and very small sizes, setting the window's size with
SetSize may not actually result in the window changing to the requested
size.  Once this happened future adjustments to the size were incorrect,
and the video display would sometimes not fit in the window, and on os x
the window could get set to a negative size, with weird results.
---
 aegisub/src/video_display.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp
index 29771e704..3be739e5c 100644
--- a/aegisub/src/video_display.cpp
+++ b/aegisub/src/video_display.cpp
@@ -318,8 +318,11 @@ void VideoDisplay::UpdateSize() {
 	if (freeSize) {
 		wxWindow *top = GetParent();
 		while (!top->IsTopLevel()) top = top->GetParent();
-		top->SetSize(top->GetSize() + videoSize - GetClientSize());
-		SetClientSize(videoSize);
+
+		wxSize cs = GetClientSize();
+		wxSize oldSize = top->GetSize();
+		top->SetSize(top->GetSize() + videoSize - cs);
+		SetClientSize(cs + top->GetSize() - oldSize);
 	}
 	else {
 		SetMinClientSize(videoSize);
@@ -378,7 +381,7 @@ void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
 
 void VideoDisplay::SetZoom(double value) {
 	zoomValue = std::max(value, .125);
-	size_t selIndex = value / .125 - 1;
+	size_t selIndex = zoomValue / .125 - 1;
 	if (selIndex < zoomBox->GetCount())
 		zoomBox->SetSelection(selIndex);
 	zoomBox->ChangeValue(wxString::Format("%g%%", zoomValue * 100.));
-- 
GitLab