From 768f74ae3c8f1a6e810046b7dcb6104d9111a3b8 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 13 Aug 2010 05:51:17 +0000 Subject: [PATCH] Make VideoDisplay set its initial zoom itself rather than FrameMain Originally committed to SVN as r4739. --- aegisub/src/dialog_detached_video.cpp | 2 +- aegisub/src/frame_main.cpp | 5 +---- aegisub/src/video_box.cpp | 5 ++--- aegisub/src/video_box.h | 3 ++- aegisub/src/video_display.cpp | 26 +++++++++++++++++++------- aegisub/src/video_display.h | 19 +++++++++++++++---- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/aegisub/src/dialog_detached_video.cpp b/aegisub/src/dialog_detached_video.cpp index d76debee0..1d06d6858 100644 --- a/aegisub/src/dialog_detached_video.cpp +++ b/aegisub/src/dialog_detached_video.cpp @@ -75,7 +75,7 @@ DialogDetachedVideo::DialogDetachedVideo(FrameMain *par, const wxSize &initialDi wxPanel *panel = new wxPanel(this,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL | wxCLIP_CHILDREN); // Video area; - videoBox = new VideoBox(panel, true); + videoBox = new VideoBox(panel, true, NULL); videoBox->videoDisplay->freeSize = true; videoBox->videoDisplay->SetClientSize(initialDisplaySize); videoBox->videoSlider->grid = par->SubsGrid; diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 4e76147b3..5205e9edf 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -579,9 +579,8 @@ void FrameMain::InitContents() { // Video area; StartupLog(_T("Create video box")); - videoBox = new VideoBox(Panel, false); + videoBox = new VideoBox(Panel, false, ZoomBox); TopSizer->Add(videoBox,0,wxEXPAND,0); - videoBox->videoDisplay->zoomBox = ZoomBox; // Subtitles area StartupLog(_T("Create subtitles grid")); @@ -589,8 +588,6 @@ void FrameMain::InitContents() { BottomSizer->Add(SubsGrid,1,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,0); videoBox->videoSlider->grid = SubsGrid; VideoContext::Get()->grid = SubsGrid; - StartupLog(_T("Reset video zoom")); - videoBox->videoDisplay->SetZoom(OPT_GET("Video/Default Zoom")->GetInt() * .125 + .125); Search.grid = SubsGrid; // Audio area diff --git a/aegisub/src/video_box.cpp b/aegisub/src/video_box.cpp index 7d5155d08..a90e89735 100644 --- a/aegisub/src/video_box.cpp +++ b/aegisub/src/video_box.cpp @@ -63,7 +63,7 @@ /// @param parent /// @param isDetached /// -VideoBox::VideoBox(wxWindow *parent, bool isDetached) +VideoBox::VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox) : wxPanel (parent,-1) { // Parent @@ -114,9 +114,8 @@ VideoBox::VideoBox(wxWindow *parent, bool isDetached) visualToolBar->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); // Display - videoDisplay = new VideoDisplay(this,videoSlider,VideoPosition,VideoSubsPos,videoPage,-1,wxDefaultPosition,wxDefaultSize,wxSUNKEN_BORDER); + videoDisplay = new VideoDisplay(this,videoSlider,VideoPosition,VideoSubsPos,zoomBox,videoPage,-1,wxDefaultPosition,wxDefaultSize,wxSUNKEN_BORDER); VideoContext::Get()->AddDisplay(videoDisplay); - videoDisplay->Reset(); // Set display videoSlider->Display = videoDisplay; diff --git a/aegisub/src/video_box.h b/aegisub/src/video_box.h index 998974470..1871863a2 100644 --- a/aegisub/src/video_box.h +++ b/aegisub/src/video_box.h @@ -54,6 +54,7 @@ class VideoDisplay; class VideoSlider; class ToggleBitmap; class FrameMain; +class wxComboBox; @@ -104,7 +105,7 @@ public: /// DOCME VideoSlider *videoSlider; - VideoBox (wxWindow *parent, bool isDetached); + VideoBox (wxWindow *parent, bool isDetached, wxComboBox *zoomBox); DECLARE_EVENT_TABLE() }; diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index 8a2fde812..24aed631c 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -122,16 +122,25 @@ public: #define E(cmd) cmd; if (GLenum err = glGetError()) throw OpenGlException(L###cmd, err) -using std::min; - -VideoDisplay::VideoDisplay(VideoBox *box, VideoSlider *ControlSlider, wxTextCtrl *PositionDisplay, wxTextCtrl *SubsPosition, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) +VideoDisplay::VideoDisplay( + VideoBox *box, + VideoSlider *ControlSlider, + wxTextCtrl *PositionDisplay, + wxTextCtrl *SubsPosition, + wxComboBox *zoomBox, + wxWindow* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) : wxGLCanvas (parent, id, attribList, pos, size, style, name) , alwaysShowTools(OPT_GET("Tool/Visual/Always Show")) , origSize(size) , currentFrame(-1) , w(8), h(8), viewport_x(0), viewport_width(0), viewport_bottom(0), viewport_top(0), viewport_height(0) , locked(false) -, zoomValue(1.0) +, zoomValue(OPT_GET("Video/Default Zoom")->GetInt() * .125 + .125) , ControlSlider(ControlSlider) , SubsPosition(SubsPosition) , PositionDisplay(PositionDisplay) @@ -140,9 +149,11 @@ VideoDisplay::VideoDisplay(VideoBox *box, VideoSlider *ControlSlider, wxTextCtrl , toolBar(box->visualSubToolBar) , scriptW(INT_MIN) , scriptH(INT_MIN) +, zoomBox(zoomBox) , box(box) , freeSize(false) { + if (zoomBox) zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.)); box->Bind(wxEVT_COMMAND_TOOL_CLICKED, &VideoDisplay::OnMode, this, Video_Mode_Standard, Video_Mode_Vector_Clip); VideoContext::Get()->Bind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this); SetCursor(wxNullCursor); @@ -265,7 +276,7 @@ void VideoDisplay::Render() try { assert(w > 0); videoOut->Render(viewport_x, viewport_bottom, viewport_width, viewport_height); - E(glViewport(0, min(viewport_bottom, 0), w, h)); + E(glViewport(0, std::min(viewport_bottom, 0), w, h)); E(glMatrixMode(GL_PROJECTION)); E(glLoadIdentity()); @@ -394,7 +405,7 @@ void VideoDisplay::UpdateSize() { w = con->GetAspectRatioType() == 0 ? vidW * zoomValue : vidH * zoomValue * con->GetAspectRatioValue(); // Cap the canvas size to the window size - int cw = min(w, maxW), ch = min(h, maxH); + int cw = std::min(w, maxW), ch = std::min(h, maxH); viewport_x = 0; viewport_bottom = ch - h; @@ -513,10 +524,11 @@ void VideoDisplay::OnKey(wxKeyEvent &event) { void VideoDisplay::SetZoom(double value) { zoomValue = std::max(value, .125); - zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.)); + if (zoomBox) zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.)); UpdateSize(); } void VideoDisplay::SetZoomFromBox() { + if (!zoomBox) return; wxString strValue = zoomBox->GetValue(); strValue.EndsWith(L"%", &strValue); double value; diff --git a/aegisub/src/video_display.h b/aegisub/src/video_display.h index 8b3711c18..036dd3ad7 100644 --- a/aegisub/src/video_display.h +++ b/aegisub/src/video_display.h @@ -169,13 +169,13 @@ class VideoDisplay : public wxGLCanvas { VideoState video; + /// The dropdown box for selecting zoom levels + wxComboBox *zoomBox; + public: /// The VideoBox this display is contained in VideoBox *box; - /// The dropdown box for selecting zoom levels - wxComboBox *zoomBox; - /// Whether the display can be freely resized by the user bool freeSize; @@ -186,7 +186,18 @@ public: /// @param size Window size. wxDefaultSize is (-1, -1) which indicates that wxWidgets should generate a default size for the window. If no suitable size can be found, the window will be sized to 20x20 pixels so that the window is visible but obviously not correctly sized. /// @param style Window style. /// @param name Window name. - VideoDisplay(VideoBox *box, VideoSlider *ControlSlider, wxTextCtrl *PositionDisplay, wxTextCtrl *SubsPosition, wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr); + VideoDisplay( + VideoBox *box, + VideoSlider *ControlSlider, + wxTextCtrl *PositionDisplay, + wxTextCtrl *SubsPosition, + wxComboBox *zoomBox, + wxWindow* parent, + wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxPanelNameStr); ~VideoDisplay(); /// @brief Reset the size of the display to the video size void Reset();