Change zoom to an arbitrary percentage rather than an index into a fixed list of allowed zooms

Originally committed to SVN as r4256.
This commit is contained in:
Thomas Goyne 2010-05-01 01:07:05 +00:00
parent 42781c1c62
commit 61c141a714
4 changed files with 38 additions and 37 deletions

View file

@ -265,7 +265,7 @@ void FrameMain::InitToolbar () {
toAdd += _T("%"); toAdd += _T("%");
choices.Add(toAdd); 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->AddControl(ZoomBox);
Toolbar->AddSeparator(); Toolbar->AddSeparator();
@ -600,7 +600,7 @@ void FrameMain::InitContents() {
videoBox->videoSlider->grid = SubsBox; videoBox->videoSlider->grid = SubsBox;
VideoContext::Get()->grid = SubsBox; VideoContext::Get()->grid = SubsBox;
StartupLog(_T("Reset video zoom")); 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; Search.grid = SubsBox;
// Audio area // Audio area
@ -949,7 +949,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
long videoPos = 0; long videoPos = 0;
long videoAr = 0; long videoAr = 0;
double videoArValue = 0.0; double videoArValue = 0.0;
long videoZoom = 0; double videoZoom = 0.;
// Get AR // Get AR
wxString arString = subs->GetScriptInfo(_T("Video Aspect Ratio")); wxString arString = subs->GetScriptInfo(_T("Video Aspect Ratio"));
@ -962,7 +962,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
// Get new state info // Get new state info
subs->GetScriptInfo(_T("Video Position")).ToLong(&videoPos); 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 curSubsVideo = DecodeRelativePath(subs->GetScriptInfo(_T("Video File")),AssFile::top->filename);
wxString curSubsVFR = DecodeRelativePath(subs->GetScriptInfo(_T("VFR 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); wxString curSubsKeyframes = DecodeRelativePath(subs->GetScriptInfo(_T("Keyframes File")),AssFile::top->filename);
@ -1003,7 +1003,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
LoadVideo(curSubsVideo); LoadVideo(curSubsVideo);
if (VideoContext::Get()->IsLoaded()) { if (VideoContext::Get()->IsLoaded()) {
VideoContext::Get()->SetAspectRatio(videoAr,videoArValue); VideoContext::Get()->SetAspectRatio(videoAr,videoArValue);
videoBox->videoDisplay->SetZoomPos(videoZoom-1); videoBox->videoDisplay->SetZoom(videoZoom);
VideoContext::Get()->JumpToFrame(videoPos); VideoContext::Get()->JumpToFrame(videoPos);
} }
//} //}
@ -1067,7 +1067,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
wxString zoom = _T("6"); wxString zoom = _T("6");
if (VideoContext::Get()->IsLoaded()) { if (VideoContext::Get()->IsLoaded()) {
seekpos = wxString::Format(_T("%i"),videoBox->videoDisplay->GetFrame()); 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(); int arType = VideoContext::Get()->GetAspectRatioType();
if (arType == 4) ar = wxString(_T("c")) + AegiFloatToString(VideoContext::Get()->GetAspectRatioValue()); if (arType == 4) ar = wxString(_T("c")) + AegiFloatToString(VideoContext::Get()->GetAspectRatioValue());
@ -1080,7 +1080,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
// Store video data // Store video data
subs->SetScriptInfo(_T("Video File"),MakeRelativePath(VideoContext::Get()->videoName,AssFile::top->filename)); subs->SetScriptInfo(_T("Video File"),MakeRelativePath(VideoContext::Get()->videoName,AssFile::top->filename));
subs->SetScriptInfo(_T("Video Aspect Ratio"),ar); 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("Video Position"),seekpos);
subs->SetScriptInfo(_T("VFR File"),MakeRelativePath(VFR_Output.GetFilename(),AssFile::top->filename)); subs->SetScriptInfo(_T("VFR File"),MakeRelativePath(VFR_Output.GetFilename(),AssFile::top->filename));
subs->SetScriptInfo(_T("Keyframes File"),MakeRelativePath(VideoContext::Get()->GetKeyFramesName(),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(); int vidx = VideoContext::Get()->GetWidth(), vidy = VideoContext::Get()->GetHeight();
// Set zoom level based on video resolution and window size // Set zoom level based on video resolution and window size
int target_zoom = 7; // 100% double target_zoom = 1.;
wxSize windowSize = GetSize(); wxSize windowSize = GetSize();
if (vidx*3 > windowSize.GetX()*2 || vidy*4 > windowSize.GetY()*3) 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) if (vidx*3 > windowSize.GetX()*4 || vidy*4 > windowSize.GetY()*6)
target_zoom = 1; // 25% target_zoom = .25;
videoBox->videoDisplay->zoomBox->SetSelection(target_zoom); videoBox->videoDisplay->SetZoom(target_zoom);
videoBox->videoDisplay->SetZoomPos(target_zoom);
// Check that the video size matches the script video size specified // Check that the video size matches the script video size specified
int scriptx = SubsBox->ass->GetScriptInfoAsInt(_T("PlayResX")); int scriptx = SubsBox->ass->GetScriptInfoAsInt(_T("PlayResX"));

View file

@ -140,6 +140,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Menu_View_Zoom_100, FrameMain::OnSetZoom100) EVT_MENU(Menu_View_Zoom_100, FrameMain::OnSetZoom100)
EVT_MENU(Menu_View_Zoom_200, FrameMain::OnSetZoom200) EVT_MENU(Menu_View_Zoom_200, FrameMain::OnSetZoom200)
EVT_COMBOBOX(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom) EVT_COMBOBOX(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom)
EVT_TEXT_ENTER(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom)
EVT_MENU(Video_Frame_Play, FrameMain::OnVideoPlay) EVT_MENU(Video_Frame_Play, FrameMain::OnVideoPlay)
EVT_MENU(Menu_Video_Zoom_In, FrameMain::OnZoomIn) EVT_MENU(Menu_Video_Zoom_In, FrameMain::OnZoomIn)
EVT_MENU(Menu_Video_Zoom_Out, FrameMain::OnZoomOut) EVT_MENU(Menu_Video_Zoom_Out, FrameMain::OnZoomOut)
@ -981,8 +982,7 @@ void FrameMain::OnSaveKeyframes (wxCommandEvent &event) {
/// ///
void FrameMain::OnSetZoom50(wxCommandEvent& WXUNUSED(event)) { void FrameMain::OnSetZoom50(wxCommandEvent& WXUNUSED(event)) {
VideoContext::Get()->Stop(); VideoContext::Get()->Stop();
videoBox->videoDisplay->zoomBox->SetSelection(3); videoBox->videoDisplay->SetZoom(.5);
videoBox->videoDisplay->SetZoomPos(3);
} }
@ -991,8 +991,7 @@ void FrameMain::OnSetZoom50(wxCommandEvent& WXUNUSED(event)) {
/// ///
void FrameMain::OnSetZoom100(wxCommandEvent& WXUNUSED(event)) { void FrameMain::OnSetZoom100(wxCommandEvent& WXUNUSED(event)) {
VideoContext::Get()->Stop(); VideoContext::Get()->Stop();
videoBox->videoDisplay->zoomBox->SetSelection(7); videoBox->videoDisplay->SetZoom(1.);
videoBox->videoDisplay->SetZoomPos(7);
} }
@ -1001,8 +1000,7 @@ void FrameMain::OnSetZoom100(wxCommandEvent& WXUNUSED(event)) {
/// ///
void FrameMain::OnSetZoom200(wxCommandEvent& WXUNUSED(event)) { void FrameMain::OnSetZoom200(wxCommandEvent& WXUNUSED(event)) {
VideoContext::Get()->Stop(); VideoContext::Get()->Stop();
videoBox->videoDisplay->zoomBox->SetSelection(15); videoBox->videoDisplay->SetZoom(2.);
videoBox->videoDisplay->SetZoomPos(15);
} }
@ -1011,8 +1009,7 @@ void FrameMain::OnSetZoom200(wxCommandEvent& WXUNUSED(event)) {
/// ///
void FrameMain::OnZoomIn (wxCommandEvent &event) { void FrameMain::OnZoomIn (wxCommandEvent &event) {
VideoContext::Get()->Stop(); VideoContext::Get()->Stop();
videoBox->videoDisplay->zoomBox->SetSelection(videoBox->videoDisplay->zoomBox->GetSelection()+1); videoBox->videoDisplay->SetZoom(videoBox->videoDisplay->GetZoom() + .125);
videoBox->videoDisplay->SetZoomPos(videoBox->videoDisplay->zoomBox->GetSelection());
} }
@ -1021,10 +1018,7 @@ void FrameMain::OnZoomIn (wxCommandEvent &event) {
/// ///
void FrameMain::OnZoomOut (wxCommandEvent &event) { void FrameMain::OnZoomOut (wxCommandEvent &event) {
VideoContext::Get()->Stop(); VideoContext::Get()->Stop();
int selTo = videoBox->videoDisplay->zoomBox->GetSelection()-1; videoBox->videoDisplay->SetZoom(videoBox->videoDisplay->GetZoom() - .125);
if (selTo < 0) selTo = 0;
videoBox->videoDisplay->zoomBox->SetSelection(selTo);
videoBox->videoDisplay->SetZoomPos(videoBox->videoDisplay->zoomBox->GetSelection());
} }
@ -1032,7 +1026,7 @@ void FrameMain::OnZoomOut (wxCommandEvent &event) {
/// @param event /// @param event
/// ///
void FrameMain::OnSetZoom(wxCommandEvent &event) { void FrameMain::OnSetZoom(wxCommandEvent &event) {
videoBox->videoDisplay->SetZoomPos(videoBox->videoDisplay->zoomBox->GetSelection()); videoBox->videoDisplay->SetZoomFromBox();
} }

View file

@ -510,20 +510,23 @@ void VideoDisplay::OnKey(wxKeyEvent &event) {
event.Skip(); event.Skip();
} }
/// @brief Set the zoom level
/// @param value The new zoom level
void VideoDisplay::SetZoom(double value) { void VideoDisplay::SetZoom(double value) {
zoomValue = value; using std::max;
zoomValue = max(value, .125);
zoomBox->SetValue(wxString::Format("%g%%", value * 100.));
UpdateSize(); UpdateSize();
} }
void VideoDisplay::SetZoomFromBox() {
/// @brief Set the position of the zoom dropdown and switch to that zoom wxString strValue = zoomBox->GetValue();
/// @param value The new zoom position strValue.EndsWith(L"%", &strValue);
void VideoDisplay::SetZoomPos(int value) { double value;
if (value < 0) value = 0; if (strValue.ToDouble(&value)) {
if (value > 23) value = 23; zoomValue = value / 100.;
SetZoom(double(value+1)/8.0); UpdateSize();
if (zoomBox->GetSelection() != value) zoomBox->SetSelection(value); }
}
double VideoDisplay::GetZoom() {
return zoomValue;
} }
/// @brief Copy the currently display frame to the clipboard, with subtitles /// @brief Copy the currently display frame to the clipboard, with subtitles

View file

@ -148,8 +148,13 @@ public:
void ShowCursor(bool show); void ShowCursor(bool show);
void ConvertMouseCoords(int &x,int &y); void ConvertMouseCoords(int &x,int &y);
void UpdateSize(); void UpdateSize();
/// @brief Set the zoom level
/// @param value The new zoom level
void SetZoom(double value); 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 SetVisualMode(int mode, bool render = false);
void OnSubTool(wxCommandEvent &event); void OnSubTool(wxCommandEvent &event);