From 921c2352ef3e5ac72b9aaa810cfeaf594e8c3a5c Mon Sep 17 00:00:00 2001 From: "avihal@gmail.com" Date: Tue, 5 Apr 2011 15:28:49 +0000 Subject: [PATCH] GS Window: Add proper zoom control and get rid of the "automatic" 4-pixel zoom in stretch-mode. Zoom = 100: Exact fit to window without cropping anything. Zoom above/below 100: Zoom In/Out. Zoom = 0: Automatic zoom in until the black-bars are gone. Keyboard: NUMPAD-PLUS: Zoom-In, NUMPAD-MINUS: Zoom-Out, NUMPAD-*: Toggle 100/0 git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4531 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/gui/AppConfig.cpp | 2 + pcsx2/gui/AppConfig.h | 1 + pcsx2/gui/FrameForGS.cpp | 28 +++++++++++++- pcsx2/gui/GlobalCommands.cpp | 51 ++++++++++++++++++++++++++ pcsx2/gui/Panels/ConfigurationPanels.h | 2 + pcsx2/gui/Panels/GSWindowPanel.cpp | 18 ++++++++- 6 files changed, 100 insertions(+), 2 deletions(-) diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index 3b30aa7a72..2ff1ffd414 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -712,6 +712,7 @@ AppConfig::GSWindowOptions::GSWindowOptions() DisableScreenSaver = true; AspectRatio = AspectRatio_4_3; + Zoom = 100; WindowSize = wxSize( 640, 480 ); WindowPos = wxDefaultPosition; @@ -765,6 +766,7 @@ void AppConfig::GSWindowOptions::LoadSave( IniInterface& ini ) }; ini.EnumEntry( L"AspectRatio", AspectRatio, AspectRatioNames, AspectRatio ); + IniEntry( Zoom ); if( ini.IsLoading() ) SanityCheck(); } diff --git a/pcsx2/gui/AppConfig.h b/pcsx2/gui/AppConfig.h index 76a72c3986..5ba6af946f 100644 --- a/pcsx2/gui/AppConfig.h +++ b/pcsx2/gui/AppConfig.h @@ -189,6 +189,7 @@ public: bool DisableScreenSaver; AspectRatioType AspectRatio; + Fixed100 Zoom; wxSize WindowSize; wxPoint WindowPos; diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 8b23ecbb0e..028c80f424 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -47,6 +47,10 @@ void GSPanel::InitDefaultAccelerators() m_Accels->Map( AAC( WXK_F6 ), "GSwindow_CycleAspectRatio" ); + m_Accels->Map( AAC( WXK_NUMPAD_ADD ), "GSwindow_ZoomIn" ); + m_Accels->Map( AAC( WXK_NUMPAD_SUBTRACT ), "GSwindow_ZoomOut" ); + m_Accels->Map( AAC( WXK_NUMPAD_MULTIPLY ), "GSwindow_ZoomToggle" ); + m_Accels->Map( AAC( WXK_ESCAPE ), "Sys_Suspend" ); m_Accels->Map( AAC( WXK_F8 ), "Sys_TakeSnapshot" ); m_Accels->Map( AAC( WXK_F8 ).Shift(), "Sys_TakeSnapshot"); @@ -127,6 +131,28 @@ void GSPanel::DoResize() wxSize client = GetParent()->GetClientSize(); wxSize viewport = client; + double clientAr = (double)client.GetWidth()/(double)client.GetHeight(); + + double targetAr = clientAr; + if( g_Conf->GSWindow.AspectRatio == AspectRatio_4_3 ) + targetAr = 4.0/3.0; + else if( g_Conf->GSWindow.AspectRatio == AspectRatio_16_9 ) + targetAr = 16.0/9.0; + + double arr = targetAr / clientAr; + + if( arr < 1 ) + viewport.x = (int)( (double)viewport.x*arr + 0.5); + else if( arr > 1 ) + viewport.y = (int)( (double)viewport.y/arr + 0.5); + + float zoom = g_Conf->GSWindow.Zoom.ToFloat()/100.0; + if( zoom == 0 )//auto zoom in untill black-bars are gone (while keeping the aspect ratio). + zoom = max( (float)arr, (float)(1.0/arr) ); + + viewport.Scale(zoom, zoom); +/* + switch( g_Conf->GSWindow.AspectRatio ) { case AspectRatio_Stretch: @@ -151,7 +177,7 @@ void GSPanel::DoResize() viewport.x = (int)(client.y * (16.0/9.0)); break; } - +*/ SetSize( viewport ); CenterOnParent(); } diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index 5fc8d2edee..de71fa94db 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -176,6 +176,39 @@ namespace Implementations AppApplySettings(); } + void SetZoom(float zoom) + { + if( zoom < 0 ) + return; + g_Conf->GSWindow.Zoom = zoom; + Console.WriteLn(L"GSwindow: set zoom: %f", zoom); + AppApplySettings(); + } + + + void GSwindow_ZoomIn() + { + float z = g_Conf->GSWindow.Zoom.ToFloat(); + if( z==0 ) z = 100; + z++; + SetZoom( z ); + } + void GSwindow_ZoomOut() + { + float z = g_Conf->GSWindow.Zoom.ToFloat(); + if( z==0 ) z = 100; + z--; + SetZoom( z ); + } + void GSwindow_ZoomToggle() + { + float z = g_Conf->GSWindow.Zoom.ToFloat(); + if( z==100 ) z = 0; + else z = 100; + + SetZoom( z ); + } + void Sys_Suspend() { CoreThread.Suspend(); @@ -338,6 +371,24 @@ static const GlobalCommandDescriptor CommandDeclarations[] = NULL, }, + { "GSwindow_ZoomIn", + Implementations::GSwindow_ZoomIn, + NULL, + NULL, + }, + + { "GSwindow_ZoomOut", + Implementations::GSwindow_ZoomOut, + NULL, + NULL, + }, + + { "GSwindow_ZoomToggle", + Implementations::GSwindow_ZoomToggle, + NULL, + NULL, + }, + { "Sys_Suspend", Implementations::Sys_Suspend, NULL, diff --git a/pcsx2/gui/Panels/ConfigurationPanels.h b/pcsx2/gui/Panels/ConfigurationPanels.h index 43e66d86f2..a9186bbc83 100644 --- a/pcsx2/gui/Panels/ConfigurationPanels.h +++ b/pcsx2/gui/Panels/ConfigurationPanels.h @@ -264,6 +264,8 @@ namespace Panels protected: wxComboBox* m_combo_AspectRatio; + wxTextCtrl* m_text_Zoom; + pxCheckBox* m_check_CloseGS; pxCheckBox* m_check_SizeLock; pxCheckBox* m_check_VsyncEnable; diff --git a/pcsx2/gui/Panels/GSWindowPanel.cpp b/pcsx2/gui/Panels/GSWindowPanel.cpp index 2d5e5e4df8..edc0397691 100644 --- a/pcsx2/gui/Panels/GSWindowPanel.cpp +++ b/pcsx2/gui/Panels/GSWindowPanel.cpp @@ -32,6 +32,8 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) _("Widescreen (16:9)") }; + m_text_Zoom = CreateNumericalTextCtrl( this, 5 ); + m_combo_AspectRatio = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, ArraySize(aspect_ratio_labels), aspect_ratio_labels, wxCB_READONLY ); @@ -50,6 +52,14 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) m_check_DclickFullscreen = new pxCheckBox( this, _("Double-click toggles fullscreen mode") ); //m_check_ExclusiveFS = new pxCheckBox( this, _("Use exclusive fullscreen mode (if available)") ); + m_text_Zoom->SetToolTip( pxEt( "!ContextTip:Window:Zoom", + L"Zoom = 100: Fit the entire image to the window without any cropping.\n" + L"Above/Below 100: Zoom In/Out\n" + L"0: Automatic-Zoom-In untill the black-bars are gone (Aspect ratio is kept, some of the image goes out of screen).\n" + L" NOTE: Some games draw their own black-bars, which will not be removed with '0'.\n\n" + L"Keyboard: NUMPAD-PLUS: Zoom-In, NUMPAD-MINUS: Zoom-Out, NUMPAD-*: Toggle 100/0" + ) ); + m_check_VsyncEnable->SetToolTip( pxEt( "!ContextTip:Window:Vsync", L"Vsync eliminates screen tearing but typically has a big performance hit. " L"It usually only applies to fullscreen mode, and may not work with all GS plugins." @@ -102,6 +112,10 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) s_AspectRatio += Label(_("Custom Window Size:"))| pxMiddle; s_AspectRatio += s_customsize | pxAlignRight; + s_AspectRatio += Label(_("Zoom:")) | StdExpand(); + s_AspectRatio += m_text_Zoom; + + *this += s_AspectRatio | StdExpand(); *this += m_check_SizeLock; *this += m_check_HideMouse; @@ -109,7 +123,7 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) *this += new wxStaticLine( this ) | StdExpand(); *this += m_check_Fullscreen; - *this += m_check_DclickFullscreen;; + *this += m_check_DclickFullscreen; //*this += m_check_ExclusiveFS; *this += new wxStaticLine( this ) | StdExpand(); @@ -141,6 +155,7 @@ void Panels::GSWindowSettingsPanel::ApplyConfigToGui( AppConfig& configToApply, m_check_SizeLock ->SetValue( conf.DisableResizeBorders ); m_combo_AspectRatio ->SetSelection( (int)conf.AspectRatio ); + m_text_Zoom ->SetValue( conf.Zoom.ToString() ); m_check_DclickFullscreen ->SetValue ( conf.IsToggleFullscreenOnDoubleClick ); @@ -166,6 +181,7 @@ void Panels::GSWindowSettingsPanel::Apply() appconf.DisableResizeBorders = m_check_SizeLock ->GetValue(); appconf.AspectRatio = (AspectRatioType)m_combo_AspectRatio->GetSelection(); + appconf.Zoom = Fixed100::FromString( m_text_Zoom->GetValue() ); gsconf.VsyncEnable = m_check_VsyncEnable->GetValue(); gsconf.ManagedVsync = m_check_ManagedVsync->GetValue();