Resize the detached video dialog to the specified size when the video zoom is changed. Closes #493.

Originally committed to SVN as r6142.
This commit is contained in:
Thomas Goyne 2011-12-22 21:31:57 +00:00
parent 77cf1f7583
commit 43b6d910fb
3 changed files with 39 additions and 30 deletions

View File

@ -64,19 +64,15 @@ DialogDetachedVideo::DialogDetachedVideo(agi::Context *context, const wxSize &in
SetTitle(wxString::Format(_("Video: %s"), wxFileName(context->videoController->GetVideoName()).GetFullName())); 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; // Video area;
VideoBox *videoBox = new VideoBox(panel, true, context); VideoBox *videoBox = new VideoBox(this, true, context);
context->videoDisplay->SetMinClientSize(initialDisplaySize); context->videoDisplay->SetMinClientSize(initialDisplaySize);
videoBox->Layout(); videoBox->Layout();
// Set sizer // Set sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(videoBox,1,wxEXPAND | wxALL,5); mainSizer->Add(videoBox,1,wxEXPAND | wxALL,5);
panel->SetSizer(mainSizer); SetSizerAndFit(mainSizer);
mainSizer->SetSizeHints(this);
// Ensure we can grow smaller, without these the window is locked to at least the initial size // Ensure we can grow smaller, without these the window is locked to at least the initial size
context->videoDisplay->SetMinSize(wxSize(1,1)); context->videoDisplay->SetMinSize(wxSize(1,1));

View File

@ -113,7 +113,7 @@ VideoDisplay::VideoDisplay(
con->videoController->Bind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this); con->videoController->Bind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this);
slots.push_back(con->videoController->AddVideoOpenListener(&VideoDisplay::OnVideoOpen, 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_PAINT, std::tr1::bind(&VideoDisplay::Render, this));
Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this); Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this);
@ -254,7 +254,7 @@ void VideoDisplay::DrawOverscanMask(float horizontal_percent, float vertical_per
E(glDisable(GL_BLEND)); E(glDisable(GL_BLEND));
} }
void VideoDisplay::UpdateSize() { void VideoDisplay::UpdateSize(bool force) {
if (!con->videoController->IsLoaded()) return; if (!con->videoController->IsLoaded()) return;
if (!IsShownOnScreen()) return; if (!IsShownOnScreen()) return;
@ -264,7 +264,7 @@ void VideoDisplay::UpdateSize() {
int arType = con->videoController->GetAspectRatioType(); int arType = con->videoController->GetAspectRatioType();
double arValue = con->videoController->GetAspectRatioValue(); double arValue = con->videoController->GetAspectRatioValue();
if (freeSize) { if (freeSize && !force) {
GetClientSize(&w,&h); GetClientSize(&w,&h);
viewport_left = 0; viewport_left = 0;
viewport_bottom = 0; viewport_bottom = 0;
@ -291,16 +291,25 @@ void VideoDisplay::UpdateSize() {
} }
} }
else { else {
wxWindow* parent = GetParent(); wxEventBlocker blocker(this);
while (!parent->IsTopLevel()) parent = parent->GetParent();
int maxH, maxW;
parent->GetClientSize(&maxW, &maxH);
h = vidH * zoomValue; h = vidH * zoomValue;
w = arType == 0 ? vidW * zoomValue : vidH * zoomValue * arValue; w = arType == 0 ? vidW * zoomValue : vidH * zoomValue * arValue;
// Cap the canvas size to the window size wxWindow *top = GetParent();
int cw = std::min(w, maxW), ch = std::min(h, maxH); 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_left = 0;
viewport_bottom = ch - h; viewport_bottom = ch - h;
@ -310,19 +319,22 @@ void VideoDisplay::UpdateSize() {
wxSize size(cw, ch); wxSize size(cw, ch);
if (size != GetClientSize()) { if (size != GetClientSize()) {
SetMinClientSize(size); if (freeSize) {
SetMaxClientSize(size); 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 // The sizer makes us use the full width, which at very low zoom
// levels results in stretched video, so after using the sizer to // levels results in stretched video, so after using the sizer to
// update the parent window sizes, reset our size to the correct // update the parent window sizes, reset our size to the correct
// value // value
SetSize(cw, ch); SetSize(cw, ch);
}
SetEvtHandlerEnabled(true);
} }
} }
@ -376,7 +388,7 @@ void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
void VideoDisplay::SetZoom(double value) { void VideoDisplay::SetZoom(double value) {
zoomValue = std::max(value, .125); zoomValue = std::max(value, .125);
zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.)); zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.));
UpdateSize(); UpdateSize(true);
} }
void VideoDisplay::SetZoomFromBox(wxCommandEvent &) { void VideoDisplay::SetZoomFromBox(wxCommandEvent &) {
@ -385,7 +397,7 @@ void VideoDisplay::SetZoomFromBox(wxCommandEvent &) {
double value; double value;
if (strValue.ToDouble(&value)) { if (strValue.ToDouble(&value)) {
zoomValue = value / 100.; zoomValue = value / 100.;
UpdateSize(); UpdateSize(true);
} }
} }

View File

@ -128,7 +128,8 @@ class VideoDisplay : public wxGLCanvas {
void OnVideoOpen(); void OnVideoOpen();
/// @brief Set the size of the display based on the current zoom and video resolution /// @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 /// @brief Set the zoom level to that indicated by the dropdown
void SetZoomFromBox(wxCommandEvent&); void SetZoomFromBox(wxCommandEvent&);