OpenGL: Added crop option for the aspect ratio option, this way you can keep the aspect ratio in the full screen mode with a 5:4 or 16:10 screen, by sacrificing some visibility on the sides

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2429 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-02-25 05:54:36 +00:00
parent 0cdb2308ab
commit caa34ef305
5 changed files with 72 additions and 29 deletions

View File

@ -48,6 +48,7 @@ void Config::Load()
iniFile.Get("Settings", "StretchToFit", &bStretchToFit, true);
iniFile.Get("Settings", "KeepAR_4_3", &bKeepAR43, false);
iniFile.Get("Settings", "KeepAR_16_9", &bKeepAR169, false);
iniFile.Get("Settings", "Crop", &bCrop, false);
iniFile.Get("Settings", "HideCursor", &bHideCursor, false);
@ -99,6 +100,7 @@ void Config::Save()
iniFile.Set("Settings", "StretchToFit", bStretchToFit);
iniFile.Set("Settings", "KeepAR_4_3", bKeepAR43);
iniFile.Set("Settings", "KeepAR_16_9", bKeepAR169);
iniFile.Set("Settings", "Crop", bCrop);
iniFile.Set("Settings", "HideCursor", bHideCursor);
iniFile.Set("Settings", "Backend", iBackend);

View File

@ -41,7 +41,7 @@ struct Config
// stretch to fit should be split into two options, I think - one for low resolution backbuffer,
// one for ignore aspect ratio. I guess KeepAR sort of does that. Anyway, these should be rethought.
bool bStretchToFit;
bool bKeepAR43, bKeepAR169;
bool bKeepAR43, bKeepAR169, bCrop;
bool bHideCursor;
bool bSafeTextureCache;

View File

@ -37,6 +37,7 @@ BEGIN_EVENT_TABLE(ConfigDialog,wxDialog)
EVT_CHECKBOX(ID_STRETCHTOFIT, ConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(ID_KEEPAR_4_3, ConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(ID_KEEPAR_16_9, ConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(ID_CROP, ConfigDialog::GeneralSettingsChanged)
#ifndef _WIN32
EVT_CHECKBOX(ID_HIDECURSOR, ConfigDialog::GeneralSettingsChanged)
#endif
@ -85,7 +86,8 @@ void ConfigDialog::OnClose(wxCloseEvent& event)
// notice that we don't run wxEntryCleanup(); here so the dll will still be loaded
/* JP: Yes, it seems like Close() does not do that. It only runs EndModal() or something
similar to hide the window. And I don't understand the "Window deletion overview" on
the wxWidgets website. Destroy() doesn't run the destructor either. */
the wxWidgets website. Destroy() doesn't run the destructor either. However running
wxEntryCleanup() from here crashes the process. But we can run it from CloseClick() */
//wxEntryCleanup();
//EndModal(0);
@ -97,11 +99,11 @@ void ConfigDialog::CloseClick(wxCommandEvent& WXUNUSED (event))
{
Console::Print("CloseClick\n");
g_Config.Save();
EndModal(0);
// If we run wxEntryCleanup() the class will be entirely deleted, and the destructor will be run
//g_Config.Save();
//wxEntryCleanup();
//Close();
Close();
}
///////////////////////////////
@ -169,11 +171,13 @@ void ConfigDialog::CreateGUIControls()
m_StretchToFit = new wxCheckBox(m_PageGeneral, ID_STRETCHTOFIT, wxT("Stretch to fit"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_KeepAR43 = new wxCheckBox(m_PageGeneral, ID_KEEPAR_4_3, wxT("Keep 4:3 aspect ratio"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_KeepAR169 = new wxCheckBox(m_PageGeneral, ID_KEEPAR_16_9, wxT("Keep 16:9 aspect ratio"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_Crop = new wxCheckBox(m_PageGeneral, ID_CROP, wxT("Crop"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
// Default values
m_StretchToFit->SetValue(g_Config.bStretchToFit);
m_KeepAR43->SetValue(g_Config.bKeepAR43);
m_KeepAR169->SetValue(g_Config.bKeepAR169);
m_Crop->SetValue(g_Config.bCrop);
#ifndef _WIN32
m_HideCursor = new wxCheckBox(m_PageGeneral, ID_HIDECURSOR, wxT("Hide mouse cursor"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
@ -203,12 +207,15 @@ void ConfigDialog::CreateGUIControls()
"\nwindow instead of changing the internal display resolution. It"
"\nmay result in a slightly blurrier image, but it may also give a higher"
"\nFPS if you have a slow graphics card."));
m_Crop->SetToolTip(wxT(
"Crop the picture instead of creating a letterbox. It will assume that your screen"
"\nis of the 5:4 format if you have selected the 4:3 aspect ratio. It will assume"
"\nthat your screen is of the 16:10 format if you have selected the 16:9 aspect ratio."));
m_FullscreenCB->SetToolTip(wxT(
"Select resolution for the (separate window) fullscreen mode."));
// This almost sounds like an unnecessary option
m_WindowResolutionCB->SetToolTip(wxT(
"Select initial resolution for the separate rendering window."));
// Enhancements
sbEnhancements = new wxStaticBoxSizer(wxVERTICAL, m_PageGeneral, wxT("Enhancements"));
@ -233,27 +240,24 @@ void ConfigDialog::CreateGUIControls()
// Usage: The wxGBPosition() must have a column and row
sGeneral = new wxBoxSizer(wxVERTICAL);
sBasic = new wxGridBagSizer(0, 0);
sBasic->Add(m_Fullscreen, wxGBPosition(0, 0), wxGBSpan(1, 2), wxALL, 5);
sBasic->Add(m_RenderToMainWindow, wxGBPosition(1, 0), wxGBSpan(1, 2), wxALL, 5);
sBasic->Add(m_StretchToFit, wxGBPosition(2, 0), wxGBSpan(1, 2), wxALL, 5);
sBasic->Add(m_Fullscreen, wxGBPosition(0, 0), wxGBSpan(1, 3), wxALL, 5);
sBasic->Add(m_RenderToMainWindow, wxGBPosition(1, 0), wxGBSpan(1, 3), wxALL, 5);
sBasic->Add(m_StretchToFit, wxGBPosition(2, 0), wxGBSpan(1, 3), wxALL, 5);
sBasic->Add(m_KeepAR43, wxGBPosition(3, 0), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(m_KeepAR169, wxGBPosition(3, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(m_Crop, wxGBPosition(3, 2), wxGBSpan(1, 1), wxALL, 5);
// Because of the ifdef here we need this variable for the row number
int Row = 4;
#ifndef _WIN32
sBasic->Add(m_HideCursor, wxGBPosition(4, 0), wxGBSpan(1, 2), wxALL, 5);
sBasic->Add(FSText, wxGBPosition(5, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
sBasic->Add(m_FullscreenCB, wxGBPosition(5, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(WMText, wxGBPosition(6, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
sBasic->Add(m_WindowResolutionCB, wxGBPosition(6, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(BEText, wxGBPosition(7, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
sBasic->Add(m_RenderBackend, wxGBPosition(7, 1), wxGBSpan(1, 1), wxALL, 5);
#else
sBasic->Add(FSText, wxGBPosition(4, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
sBasic->Add(m_FullscreenCB, wxGBPosition(4, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(WMText, wxGBPosition(5, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
sBasic->Add(m_WindowResolutionCB, wxGBPosition(5, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(BEText, wxGBPosition(6, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
sBasic->Add(m_RenderBackend, wxGBPosition(6, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(m_HideCursor, wxGBPosition(Row++, 0), wxGBSpan(1, 3), wxALL, 5);
#endif
sBasic->Add(FSText, wxGBPosition(Row, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(m_FullscreenCB, wxGBPosition(Row++, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(WMText, wxGBPosition(Row, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(m_WindowResolutionCB, wxGBPosition(Row++, 1), wxGBSpan(1, 1), wxALL, 5);
sBasic->Add(BEText, wxGBPosition(Row, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL | wxALL, 5);
sBasic->Add(m_RenderBackend, wxGBPosition(Row++, 1), wxGBSpan(1, 1), wxALL, 5);
sbBasic->Add(sBasic);
sGeneral->Add(sbBasic, 0, wxEXPAND|wxALL, 5);
@ -440,6 +444,9 @@ void ConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
// Don't allow both at the same time
if (g_Config.bKeepAR169) { g_Config.bKeepAR43 = false; m_KeepAR43->SetValue(false); }
break;
case ID_CROP:
g_Config.bCrop = m_Crop->IsChecked();
break;
#ifndef _WIN32
case ID_HIDECURSOR:
g_Config.bHideCursor = m_HideCursor->IsChecked();
@ -559,6 +566,8 @@ void ConfigDialog::UpdateGUI()
// This option is only compatible with the Strech To Fit option
m_KeepAR43->Enable(g_Config.bStretchToFit);
m_KeepAR169->Enable(g_Config.bStretchToFit);
// This is only used together with the aspect ratio options
m_Crop->Enable(g_Config.bStretchToFit && (g_Config.bKeepAR43 || g_Config.bKeepAR169));
// These options are for the separate rendering window
m_Fullscreen->Enable(!g_Config.renderToMainframe);

View File

@ -78,7 +78,7 @@ class ConfigDialog : public wxDialog
wxCheckBox *m_Fullscreen;
wxCheckBox *m_RenderToMainWindow;
wxCheckBox *m_StretchToFit;
wxCheckBox *m_KeepAR43, *m_KeepAR169;
wxCheckBox *m_KeepAR43, *m_KeepAR169, *m_Crop;
#ifndef _WIN32
wxCheckBox *m_HideCursor;
#endif
@ -129,7 +129,7 @@ class ConfigDialog : public wxDialog
ID_FULLSCREEN,
ID_RENDERTOMAINWINDOW,
ID_STRETCHTOFIT,
ID_KEEPAR_4_3, ID_KEEPAR_16_9,
ID_KEEPAR_4_3, ID_KEEPAR_16_9, ID_CROP,
ID_HIDECURSOR,
ID_FSTEXT,
ID_FULLSCREENCB,

View File

@ -924,6 +924,34 @@ void Renderer::Swap(const TRectangle& rc)
}
// -------------------------------------
// -----------------------------------------------------------------------
/* Crop the picture from 4:3 to 5:4 or from 16:9 to 16:10. */
// Output: FloatGLWidth, FloatGLHeight, FloatXOffset, FloatYOffset
// ------------------
if ((g_Config.bKeepAR43 || g_Config.bKeepAR169) && g_Config.bStretchToFit && g_Config.bCrop)
{
float Ratio = g_Config.bKeepAR43 ? ((4.0 / 3.0) / (5.0 / 4.0)) : (((16.0 / 9.0) / (16.0 / 10.0)));
// The width and height we will add
float IncreasedWidth = (Ratio - 1.0) * FloatGLWidth;
float IncreasedHeight = (Ratio - 1.0) * FloatGLHeight;
FloatGLWidth = FloatGLWidth * Ratio;
FloatGLHeight = FloatGLHeight * Ratio;
// Wee need this adjustment to, the -6 adjustment was needed to never show any pixels outside the actual picture
// The result in offset in actual pixels is only around 1 or 2 pixels in a 1280 x 1024 resolution. In 1280 x 1024 the
// picture is only about 2 to 4 pixels (1 up and 1 down for example) to big to produce a minimal margin
// of error, while rather having a full screen and hiding one pixel, than having a one pixel black border. But it seems
// to be just enough in all games I tried.
float WidthRatio = ((float)rc.right - 6.0) / 640.0;
float HeightRatio = ((float)rc.bottom - 6.0) / 480.0;
// Adjust the X and Y offset
FloatXOffset = FloatXOffset - (IncreasedWidth / 2.0 / WidthRatio / Ratio);
FloatYOffset = FloatYOffset - (IncreasedHeight / 2.0 / HeightRatio / Ratio);
//Console::Print("Crop Ratio:%1.2f IncreasedHeight:%3.0f YOffset:%3.0f\n", Ratio, IncreasedHeight, FloatYOffset);
}
// -------------------------------------
// -----------------------------------------------------------------------
/* Adjustments to
FloatGLWidth
@ -987,10 +1015,14 @@ void Renderer::Swap(const TRectangle& rc)
// -----------------------------------------------------------------------
/* Blacken out the borders in the 4:3 or 16:9 aspect ratio modes. Somewhere in BPStructs
0x52 or elsewhere the area outside the actual picture, that we now show with the aspect ratio option
has been filled with either for example white, or have copies of old renderings on it. So we replace
that with blacknes. */
/* Blacken out the borders in the 4:3 or 16:9 aspect ratio modes. Somewhere in BPStructs 0x52 or
elsewhere the area outside the actual picture, that we now show with the aspect ratio option
has been filled with either for example white, or have copies of old renderings on it. So we
replace that with blacknes.
We are not supposed to need this with the Crop option and in full screen, but we can keep it for the
window mode, since the border can still be seen then
*/
// --------------------
if(g_Config.bKeepAR43 || g_Config.bKeepAR169)
{