diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 0893dc347..aa22ada6c 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -265,7 +265,7 @@ void FrameMain::InitToolbar () { toAdd += _T("%"); choices.Add(toAdd); } - ZoomBox = new wxComboBox(Toolbar,Toolbar_Zoom_Dropdown,_T("75%"),wxDefaultPosition,wxDefaultSize,choices,wxCB_READONLY); + ZoomBox = new wxComboBox(Toolbar,Toolbar_Zoom_Dropdown,_T("75%"),wxDefaultPosition,wxDefaultSize,choices,wxCB_DROPDOWN); Toolbar->AddControl(ZoomBox); Toolbar->AddSeparator(); @@ -600,7 +600,7 @@ void FrameMain::InitContents() { videoBox->videoSlider->grid = SubsBox; VideoContext::Get()->grid = SubsBox; StartupLog(_T("Reset video zoom")); - videoBox->videoDisplay->SetZoomPos(Options.AsInt(_T("Video Default Zoom"))); + videoBox->videoDisplay->SetZoom(Options.AsInt(_T("Video Default Zoom")) * .125 + .125); Search.grid = SubsBox; // Audio area @@ -949,7 +949,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) { long videoPos = 0; long videoAr = 0; double videoArValue = 0.0; - long videoZoom = 0; + double videoZoom = 0.; // Get AR wxString arString = subs->GetScriptInfo(_T("Video Aspect Ratio")); @@ -962,7 +962,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) { // Get new state info subs->GetScriptInfo(_T("Video Position")).ToLong(&videoPos); - subs->GetScriptInfo(_T("Video Zoom")).ToLong(&videoZoom); + subs->GetScriptInfo(_T("Video Zoom Percent")).ToDouble(&videoZoom); wxString curSubsVideo = DecodeRelativePath(subs->GetScriptInfo(_T("Video File")),AssFile::top->filename); wxString curSubsVFR = DecodeRelativePath(subs->GetScriptInfo(_T("VFR File")),AssFile::top->filename); wxString curSubsKeyframes = DecodeRelativePath(subs->GetScriptInfo(_T("Keyframes File")),AssFile::top->filename); @@ -1003,7 +1003,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) { LoadVideo(curSubsVideo); if (VideoContext::Get()->IsLoaded()) { VideoContext::Get()->SetAspectRatio(videoAr,videoArValue); - videoBox->videoDisplay->SetZoomPos(videoZoom-1); + videoBox->videoDisplay->SetZoom(videoZoom); VideoContext::Get()->JumpToFrame(videoPos); } //} @@ -1067,7 +1067,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) { wxString zoom = _T("6"); if (VideoContext::Get()->IsLoaded()) { seekpos = wxString::Format(_T("%i"),videoBox->videoDisplay->GetFrame()); - zoom = wxString::Format(_T("%i"),videoBox->videoDisplay->zoomBox->GetSelection()+1); + zoom = wxString::Format(_T("%f"),videoBox->videoDisplay->GetZoom()); int arType = VideoContext::Get()->GetAspectRatioType(); if (arType == 4) ar = wxString(_T("c")) + AegiFloatToString(VideoContext::Get()->GetAspectRatioValue()); @@ -1080,7 +1080,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) { // Store video data subs->SetScriptInfo(_T("Video File"),MakeRelativePath(VideoContext::Get()->videoName,AssFile::top->filename)); subs->SetScriptInfo(_T("Video Aspect Ratio"),ar); - subs->SetScriptInfo(_T("Video Zoom"),zoom); + subs->SetScriptInfo(_T("Video Zoom Percent"),zoom); subs->SetScriptInfo(_T("Video Position"),seekpos); subs->SetScriptInfo(_T("VFR File"),MakeRelativePath(VFR_Output.GetFilename(),AssFile::top->filename)); subs->SetScriptInfo(_T("Keyframes File"),MakeRelativePath(VideoContext::Get()->GetKeyFramesName(),AssFile::top->filename)); @@ -1161,14 +1161,13 @@ void FrameMain::LoadVideo(wxString file,bool autoload) { int vidx = VideoContext::Get()->GetWidth(), vidy = VideoContext::Get()->GetHeight(); // Set zoom level based on video resolution and window size - int target_zoom = 7; // 100% + double target_zoom = 1.; wxSize windowSize = GetSize(); if (vidx*3 > windowSize.GetX()*2 || vidy*4 > windowSize.GetY()*3) - target_zoom = 3; // 50% + target_zoom = .5; if (vidx*3 > windowSize.GetX()*4 || vidy*4 > windowSize.GetY()*6) - target_zoom = 1; // 25% - videoBox->videoDisplay->zoomBox->SetSelection(target_zoom); - videoBox->videoDisplay->SetZoomPos(target_zoom); + target_zoom = .25; + videoBox->videoDisplay->SetZoom(target_zoom); // Check that the video size matches the script video size specified int scriptx = SubsBox->ass->GetScriptInfoAsInt(_T("PlayResX")); diff --git a/aegisub/src/frame_main_events.cpp b/aegisub/src/frame_main_events.cpp index ac8fea470..11e3accce 100644 --- a/aegisub/src/frame_main_events.cpp +++ b/aegisub/src/frame_main_events.cpp @@ -140,6 +140,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame) EVT_MENU(Menu_View_Zoom_100, FrameMain::OnSetZoom100) EVT_MENU(Menu_View_Zoom_200, FrameMain::OnSetZoom200) EVT_COMBOBOX(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom) + EVT_TEXT_ENTER(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom) EVT_MENU(Video_Frame_Play, FrameMain::OnVideoPlay) EVT_MENU(Menu_Video_Zoom_In, FrameMain::OnZoomIn) EVT_MENU(Menu_Video_Zoom_Out, FrameMain::OnZoomOut) @@ -981,8 +982,7 @@ void FrameMain::OnSaveKeyframes (wxCommandEvent &event) { /// void FrameMain::OnSetZoom50(wxCommandEvent& WXUNUSED(event)) { VideoContext::Get()->Stop(); - videoBox->videoDisplay->zoomBox->SetSelection(3); - videoBox->videoDisplay->SetZoomPos(3); + videoBox->videoDisplay->SetZoom(.5); } @@ -991,8 +991,7 @@ void FrameMain::OnSetZoom50(wxCommandEvent& WXUNUSED(event)) { /// void FrameMain::OnSetZoom100(wxCommandEvent& WXUNUSED(event)) { VideoContext::Get()->Stop(); - videoBox->videoDisplay->zoomBox->SetSelection(7); - videoBox->videoDisplay->SetZoomPos(7); + videoBox->videoDisplay->SetZoom(1.); } @@ -1001,8 +1000,7 @@ void FrameMain::OnSetZoom100(wxCommandEvent& WXUNUSED(event)) { /// void FrameMain::OnSetZoom200(wxCommandEvent& WXUNUSED(event)) { VideoContext::Get()->Stop(); - videoBox->videoDisplay->zoomBox->SetSelection(15); - videoBox->videoDisplay->SetZoomPos(15); + videoBox->videoDisplay->SetZoom(2.); } @@ -1011,8 +1009,7 @@ void FrameMain::OnSetZoom200(wxCommandEvent& WXUNUSED(event)) { /// void FrameMain::OnZoomIn (wxCommandEvent &event) { VideoContext::Get()->Stop(); - videoBox->videoDisplay->zoomBox->SetSelection(videoBox->videoDisplay->zoomBox->GetSelection()+1); - videoBox->videoDisplay->SetZoomPos(videoBox->videoDisplay->zoomBox->GetSelection()); + videoBox->videoDisplay->SetZoom(videoBox->videoDisplay->GetZoom() + .125); } @@ -1021,10 +1018,7 @@ void FrameMain::OnZoomIn (wxCommandEvent &event) { /// void FrameMain::OnZoomOut (wxCommandEvent &event) { VideoContext::Get()->Stop(); - int selTo = videoBox->videoDisplay->zoomBox->GetSelection()-1; - if (selTo < 0) selTo = 0; - videoBox->videoDisplay->zoomBox->SetSelection(selTo); - videoBox->videoDisplay->SetZoomPos(videoBox->videoDisplay->zoomBox->GetSelection()); + videoBox->videoDisplay->SetZoom(videoBox->videoDisplay->GetZoom() - .125); } @@ -1032,7 +1026,7 @@ void FrameMain::OnZoomOut (wxCommandEvent &event) { /// @param event /// void FrameMain::OnSetZoom(wxCommandEvent &event) { - videoBox->videoDisplay->SetZoomPos(videoBox->videoDisplay->zoomBox->GetSelection()); + videoBox->videoDisplay->SetZoomFromBox(); } diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index 590735971..7393a93fd 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -510,20 +510,23 @@ void VideoDisplay::OnKey(wxKeyEvent &event) { event.Skip(); } -/// @brief Set the zoom level -/// @param value The new zoom level void VideoDisplay::SetZoom(double value) { - zoomValue = value; + using std::max; + zoomValue = max(value, .125); + zoomBox->SetValue(wxString::Format("%g%%", value * 100.)); UpdateSize(); } - -/// @brief Set the position of the zoom dropdown and switch to that zoom -/// @param value The new zoom position -void VideoDisplay::SetZoomPos(int value) { - if (value < 0) value = 0; - if (value > 23) value = 23; - SetZoom(double(value+1)/8.0); - if (zoomBox->GetSelection() != value) zoomBox->SetSelection(value); +void VideoDisplay::SetZoomFromBox() { + wxString strValue = zoomBox->GetValue(); + strValue.EndsWith(L"%", &strValue); + double value; + if (strValue.ToDouble(&value)) { + zoomValue = value / 100.; + UpdateSize(); + } +} +double VideoDisplay::GetZoom() { + return zoomValue; } /// @brief Copy the currently display frame to the clipboard, with subtitles diff --git a/aegisub/src/video_display.h b/aegisub/src/video_display.h index c24f018b0..edc00dcec 100644 --- a/aegisub/src/video_display.h +++ b/aegisub/src/video_display.h @@ -148,8 +148,13 @@ public: void ShowCursor(bool show); void ConvertMouseCoords(int &x,int &y); void UpdateSize(); + /// @brief Set the zoom level + /// @param value The new zoom level void SetZoom(double value); - void SetZoomPos(int pos); + /// @brief Set the zoom level to that indicated by the dropdown + void SetZoomFromBox(); + /// @brief Get the current zoom level + double GetZoom(); void SetVisualMode(int mode, bool render = false); void OnSubTool(wxCommandEvent &event);