From 9c71bf0bc12c86a5dd545b6472b0795fd60f05ac Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 7 Apr 2009 21:10:38 +0000 Subject: [PATCH] When applying video defaults, set the aspect ratio to the monitor's. In windowed mode, automatically adjust the window width to make pixels square. --- stepmania/src/ScreenOptionsMasterPrefs.cpp | 4 +- stepmania/src/StepMania.cpp | 58 +++++++++++++------ stepmania/src/arch/ArchHooks/ArchHooks.h | 2 + .../src/arch/ArchHooks/ArchHooks_Win32.cpp | 10 ++++ .../src/arch/ArchHooks/ArchHooks_Win32.h | 1 + 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/stepmania/src/ScreenOptionsMasterPrefs.cpp b/stepmania/src/ScreenOptionsMasterPrefs.cpp index 6233a71fdb..b9e821814a 100644 --- a/stepmania/src/ScreenOptionsMasterPrefs.cpp +++ b/stepmania/src/ScreenOptionsMasterPrefs.cpp @@ -556,7 +556,7 @@ static void RefreshRate( int &sel, bool ToSel, const ConfOption *pConfOption ) static void DisplayAspectRatio( int &sel, bool ToSel, const ConfOption *pConfOption ) { - const float mapping[] = { 3/4.f,1,4/3.0f,16/10.0f,16/9.f, 8/3.f }; + const float mapping[] = { 3/4.f, 1, 4/3.0f, 16/10.0f, 16/9.f, 8/3.f }; MoveMap( sel, pConfOption, ToSel, mapping, ARRAYLEN(mapping) ); } @@ -701,7 +701,7 @@ static void InitializeConfOptions() ADD( ConfOption( "DisplayResolution", DisplayResolutionM, DisplayResolutionChoices ) ); g_ConfOptions.back().m_iEffects = OPT_APPLY_GRAPHICS | OPT_APPLY_ASPECT_RATIO; ADD( ConfOption( "DisplayAspectRatio", DisplayAspectRatio, "|3:4","|1:1","|4:3","|16:10","|16:9","|8:3" ) ); - g_ConfOptions.back().m_iEffects = OPT_APPLY_ASPECT_RATIO; + g_ConfOptions.back().m_iEffects = OPT_APPLY_GRAPHICS | OPT_APPLY_ASPECT_RATIO; // need OPT_APPLY_GRAPHICS because if windowed the width may change to make square pixels ADD( ConfOption( "WideScreen16_10", WideScreen16_10, "Off", "On" ) ); g_ConfOptions.back().m_sPrefName = "DisplayAspectRatio"; g_ConfOptions.back().m_iEffects = OPT_APPLY_ASPECT_RATIO; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 90330043fb..de4d599aae 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -84,21 +84,34 @@ static Preference g_bAllowMultipleInstances( "AllowMultipleInstances", fal void StepMania::GetPreferredVideoModeParams( VideoModeParams ¶msOut ) { + /* + * We can't rely on there being full-screen video modes that give us square pixels + * at non-4:3 aspects. The lowest non-4:3 resolution my new laptop with Radeon supports is 1280x720. + * In most cases, we'll using a 4:3 resolution when full-screen let the monitor stretch to the correct + * aspect. When windowed (no monitor stretching), we will tweak the width so that we get square pixels. + * -Chris + */ + int iWidth = PREFSMAN->m_iDisplayWidth; + if( PREFSMAN->m_bWindowed ) + { + iWidth = PREFSMAN->m_iDisplayHeight * PREFSMAN->m_fDisplayAspectRatio; + } + paramsOut = VideoModeParams( - PREFSMAN->m_bWindowed, - PREFSMAN->m_iDisplayWidth, - PREFSMAN->m_iDisplayHeight, - PREFSMAN->m_iDisplayColorDepth, - PREFSMAN->m_iRefreshRate, - PREFSMAN->m_bVsync, - PREFSMAN->m_bInterlaced, - PREFSMAN->m_bSmoothLines, - PREFSMAN->m_bTrilinearFiltering, - PREFSMAN->m_bAnisotropicFiltering, - CommonMetrics::WINDOW_TITLE, - THEME->GetPathG("Common","window icon"), - PREFSMAN->m_bPAL, - PREFSMAN->m_fDisplayAspectRatio + PREFSMAN->m_bWindowed, + iWidth, + PREFSMAN->m_iDisplayHeight, + PREFSMAN->m_iDisplayColorDepth, + PREFSMAN->m_iRefreshRate, + PREFSMAN->m_bVsync, + PREFSMAN->m_bInterlaced, + PREFSMAN->m_bSmoothLines, + PREFSMAN->m_bTrilinearFiltering, + PREFSMAN->m_bAnisotropicFiltering, + CommonMetrics::WINDOW_TITLE, + THEME->GetPathG("Common","window icon"), + PREFSMAN->m_bPAL, + PREFSMAN->m_fDisplayAspectRatio ); } @@ -131,11 +144,21 @@ static RString GetActualGraphicOptionsString() static void StoreActualGraphicOptions() { - // find out what we actually have + /* Store the settings that RageDisplay was actually able to use so that + * we don't go through the process of auto-detecting a usable video mode + * every time. + */ const VideoModeParams ¶ms = DISPLAY->GetActualVideoModeParams(); PREFSMAN->m_bWindowed .Set( params.windowed ); - PREFSMAN->m_iDisplayWidth .Set( params.width ); - PREFSMAN->m_iDisplayHeight .Set( params.height ); + + /* If we're windowed, we may have tweaked the width based on the aspect ratio. + * Don't save this new value over the preferred value. + */ + if( !PREFSMAN->m_bWindowed ) + { + PREFSMAN->m_iDisplayWidth .Set( params.width ); + PREFSMAN->m_iDisplayHeight .Set( params.height ); + } PREFSMAN->m_iDisplayColorDepth .Set( params.bpp ); if( PREFSMAN->m_iRefreshRate != REFRESH_DEFAULT ) PREFSMAN->m_iRefreshRate.Set( params.rate ); @@ -649,6 +672,7 @@ found_defaults: PREFSMAN->m_iMovieColorDepth.Set( defaults.iMovieColor ); PREFSMAN->m_iMaxTextureResolution.Set( defaults.iTextureSize ); PREFSMAN->m_bSmoothLines.Set( defaults.bSmoothLines ); + PREFSMAN->m_fDisplayAspectRatio.Set( HOOKS->GetDisplayAspectRatio() ); // Update last seen video card PREFSMAN->m_sLastSeenVideoDriver.Set( GetVideoDriverName() ); diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.h b/stepmania/src/arch/ArchHooks/ArchHooks.h index 4140aa08d8..930499418f 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks.h @@ -113,6 +113,8 @@ public: */ virtual bool GoToURL( RString sUrl ); + virtual float GetDisplayAspectRatio() = 0; + private: /* This are helpers for GetMicrosecondsSinceStart on systems with a timer * that may loop or move backwards. */ diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp index 83f75c8556..83ff3f119f 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp @@ -183,6 +183,16 @@ bool ArchHooks_Win32::GoToURL( RString sUrl ) return ::GotoURL( sUrl ); } +float ArchHooks_Win32::GetDisplayAspectRatio() +{ + DEVMODE dm; + ZERO( dm ); + dm.dmSize = sizeof(dm); + BOOL bResult = EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm ); + ASSERT( bResult ); + return dm.dmPelsWidth / (float)dm.dmPelsHeight; +} + /* * (c) 2003-2004 Glenn Maynard, Chris Danford * All rights reserved. diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h index 77a32405ff..b0210eaeca 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h @@ -22,6 +22,7 @@ public: void SetupConcurrentRenderingThread(); bool GoToURL( RString sUrl ); + virtual float GetDisplayAspectRatio(); }; #ifdef ARCH_HOOKS