From 4bcb9b5834725e50bc49fc1afa1e7f887f691505 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Thu, 26 Feb 2009 00:11:51 +0000 Subject: [PATCH] Emulated Wiimote IR pointer: Made it compatible with the new aspect ratio options in the OpenGL plugin. It will now load the same settings that the OpenGL plugin use. So if you change the settings there, you'll have to open the Wiimote configuration window so that the new settings are loaded for it to. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2439 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/MusicMod.sln | 2 + Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 3 +- Source/Plugins/Plugin_Wiimote/Src/Config.cpp | 12 ++ Source/Plugins/Plugin_Wiimote/Src/Config.h | 3 + .../Plugins/Plugin_Wiimote/Src/ConfigDlg.cpp | 34 ++++- Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.h | 11 +- .../Plugin_Wiimote/Src/ConfigRecording.cpp | 21 ++- .../Plugin_Wiimote/Src/EmuDefinitions.h | 7 +- Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp | 126 ++++++++++++++++-- 9 files changed, 188 insertions(+), 31 deletions(-) diff --git a/Source/MusicMod.sln b/Source/MusicMod.sln index 12b35b0661..7ee626eeeb 100644 --- a/Source/MusicMod.sln +++ b/Source/MusicMod.sln @@ -59,6 +59,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dolphin", "Core\DolphinWX\D {48AD7E0A-25B1-4974-A1E3-03F8C438D34F} = {48AD7E0A-25B1-4974-A1E3-03F8C438D34F} {CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160} = {CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160} {0318BA30-EF48-441A-9E10-DC85EFAE39F0} = {0318BA30-EF48-441A-9E10-DC85EFAE39F0} + {8D612734-FAA5-4B8A-804F-4DEA2367D495} = {8D612734-FAA5-4B8A-804F-4DEA2367D495} {71B16F46-0B00-4EDA-B253-D6D9D03A215C} = {71B16F46-0B00-4EDA-B253-D6D9D03A215C} {33546D62-7F34-4EA6-A88E-D538B36E16BF} = {33546D62-7F34-4EA6-A88E-D538B36E16BF} {3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63} @@ -372,6 +373,7 @@ Global {8D612734-FAA5-4B8A-804F-4DEA2367D495}.Release JITIL|x64.ActiveCfg = Release|x64 {8D612734-FAA5-4B8A-804F-4DEA2367D495}.Release JITIL|x64.Build.0 = Release|x64 {8D612734-FAA5-4B8A-804F-4DEA2367D495}.Release|Win32.ActiveCfg = Release|Win32 + {8D612734-FAA5-4B8A-804F-4DEA2367D495}.Release|Win32.Build.0 = Release|Win32 {8D612734-FAA5-4B8A-804F-4DEA2367D495}.Release|x64.ActiveCfg = Release|x64 {8D612734-FAA5-4B8A-804F-4DEA2367D495}.Release|x64.Build.0 = Release|x64 {ADF64291-57ED-4B7A-AB76-37B4A991504B}.Debug|Win32.ActiveCfg = Debug|Win32 diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index a84e58b6fb..c396427c02 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -932,9 +932,10 @@ void Renderer::Swap(const TRectangle& rc) 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 + // The width and height we will add (calculate this before FloatGLWidth and FloatGLHeight is adjusted) float IncreasedWidth = (Ratio - 1.0) * FloatGLWidth; float IncreasedHeight = (Ratio - 1.0) * FloatGLHeight; + // The new width and height 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 diff --git a/Source/Plugins/Plugin_Wiimote/Src/Config.cpp b/Source/Plugins/Plugin_Wiimote/Src/Config.cpp index c1f67faca1..d85476ef4b 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/Config.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/Config.cpp @@ -198,6 +198,18 @@ void Config::Load(bool ChangePad) iniFile.Get(SectionName.c_str(), "PitchInvert", &WiiMoteEmu::PadMapping[i].bPitchInvert, false); } // ============================= + + // ================================================================== + /* Load a few screen settings to. If these are added to the DirectX plugin it's probably + better to place them in the main Dolphin.ini file */ + // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ + iniFile.Load(FULL_CONFIG_DIR "gfx_opengl.ini"); + iniFile.Get("Settings", "KeepAR_4_3", &bKeepAR43, false); + iniFile.Get("Settings", "KeepAR_16_9", &bKeepAR169, false); + iniFile.Get("Settings", "Crop", &bCrop, false); + // ============================= + + // Logging Console::Print("Load()\n"); } diff --git a/Source/Plugins/Plugin_Wiimote/Src/Config.h b/Source/Plugins/Plugin_Wiimote/Src/Config.h index 5d60f8c70c..2366c69e84 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/Config.h +++ b/Source/Plugins/Plugin_Wiimote/Src/Config.h @@ -84,6 +84,9 @@ struct Config PadTrigger Trigger; PadNunchuck Nunchuck; PadClassicController ClassicController; + + // Screen size settings + bool bKeepAR43, bKeepAR169, bCrop; }; extern Config g_Config; diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.cpp b/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.cpp index d760d7b131..bc8b33b8b0 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.cpp @@ -568,8 +568,8 @@ void ConfigDialog::CreateGUIControls() // General and basic Settings // ---------------- - // Configuration controls - static const int TxtW = 50, TxtH = 19, ChW = 261, BtW = 75, BtH = 20; + // Configuration controls sizes + static const int TxtW = 50, TxtH = 19, ChW = 257, BtW = 75, BtH = 20; // Basic Settings m_WiimoteOnline[i] = new wxCheckBox(m_Controller[i], IDC_WIMOTE_ON, wxT("Wiimote On"), wxDefaultPosition, wxSize(ChW, -1)); @@ -615,13 +615,18 @@ void ConfigDialog::CreateGUIControls() m_TextScreenHeight[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Height: 000")); m_TextScreenLeft[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Left: 000")); m_TextScreenTop[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Top: 000")); - + m_TextAR[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Aspect Ratio")); + m_SliderWidth[i] = new wxSlider(m_Controller[i], IDS_WIDTH, 0, 100, 923, wxDefaultPosition, wxSize(75, -1)); m_SliderHeight[i] = new wxSlider(m_Controller[i], IDS_HEIGHT, 0, 0, 727, wxDefaultPosition, wxSize(75, -1)); m_SliderLeft[i] = new wxSlider(m_Controller[i], IDS_LEFT, 0, 100, 500, wxDefaultPosition, wxSize(75, -1)); m_SliderTop[i] = new wxSlider(m_Controller[i], IDS_TOP, 0, 0, 500, wxDefaultPosition, wxSize(75, -1)); //m_ScreenSize = new wxCheckBox(m_Controller[i], IDC_SCREEN_SIZE, wxT("Adjust screen size and position"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); + m_CheckAR43[i] = new wxCheckBox(m_Controller[i], wxID_ANY, wxT("4:3"), wxDefaultPosition, wxSize(-1, -1), 0, wxDefaultValidator); + m_CheckAR169[i] = new wxCheckBox(m_Controller[i], wxID_ANY, wxT("16:9"), wxDefaultPosition, wxSize(-1, -1), 0, wxDefaultValidator); + m_Crop[i] = new wxCheckBox(m_Controller[i], wxID_ANY, wxT("Crop"), wxDefaultPosition, wxSize(-1, -1), 0, wxDefaultValidator); + // Sizers m_SizerIRPointerWidth[i] = new wxBoxSizer(wxHORIZONTAL); m_SizerIRPointerWidth[i]->Add(m_TextScreenLeft[i], 0, wxEXPAND | (wxTOP), 3); @@ -635,10 +640,28 @@ void ConfigDialog::CreateGUIControls() m_SizerIRPointerHeight[i]->Add(m_TextScreenHeight[i], 0, wxEXPAND | (wxTOP), 3); m_SizerIRPointerHeight[i]->Add(m_SliderHeight[i], 0, wxEXPAND | (wxLEFT), 0); + m_SizerIRPointerScreen[i] = new wxBoxSizer(wxHORIZONTAL); + m_SizerIRPointerScreen[i]->Add(m_TextAR[i], 0, wxEXPAND | (wxTOP), 0); + m_SizerIRPointerScreen[i]->Add(m_CheckAR43[i], 0, wxEXPAND | (wxLEFT), 5); + m_SizerIRPointerScreen[i]->Add(m_CheckAR169[i], 0, wxEXPAND | (wxLEFT), 5); + m_SizerIRPointerScreen[i]->Add(m_Crop[i], 0, wxEXPAND | (wxLEFT), 5); + m_SizerIRPointer[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("IR pointer")); //m_SizerIRPointer[i]->Add(m_ScreenSize[i], 0, wxEXPAND | (wxALL), 5); m_SizerIRPointer[i]->Add(m_SizerIRPointerWidth[i], 0, wxEXPAND | (wxLEFT | wxDOWN | wxRIGHT), 5); m_SizerIRPointer[i]->Add(m_SizerIRPointerHeight[i], 0, wxEXPAND | (wxLEFT | wxDOWN | wxRIGHT), 5); + m_SizerIRPointer[i]->Add(m_SizerIRPointerScreen[i], 0, wxEXPAND | (wxLEFT | wxDOWN | wxRIGHT), 5); + + // Default values + m_CheckAR43[i]->SetValue(g_Config.bKeepAR43); + m_CheckAR169[i]->SetValue(g_Config.bKeepAR169); + m_Crop[i]->SetValue(g_Config.bCrop); + + // These are changed from the graphics plugin settings, so they are just here to show the loaded status + m_TextAR[i]->Enable(false); + m_CheckAR43[i]->Enable(false); + m_CheckAR169[i]->Enable(false); + m_Crop[i]->Enable(false); // Tool tips //m_ScreenSize[i]->SetToolTip(wxT("Use the adjusted screen size.")); @@ -976,10 +999,11 @@ void ConfigDialog::CreateGUIControls() // Row 3 Sizers // ----------------------------- m_HorizControllers[i] = new wxBoxSizer(wxHORIZONTAL); - m_HorizControllers[i]->AddStretchSpacer(); + //m_HorizControllers[i]->AddStretchSpacer(); + m_HorizControllers[i]->AddSpacer(17); m_HorizControllers[i]->Add(m_gAnalogLeft[i]); m_HorizControllers[i]->Add(m_gAnalogRight[i], 0, (wxLEFT), 5); - m_HorizControllers[i]->AddStretchSpacer(); + //m_HorizControllers[i]->AddStretchSpacer(); /////////////////////////// diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.h b/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.h index 27c5912e8c..d4ffa1931d 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.h +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.h @@ -86,7 +86,7 @@ class ConfigDialog : public wxDialog wxBoxSizer *m_MainSizer, *m_sMain[4], *m_SizeParent[4], *m_sRecordingMain; // Emulated Wiimote key settings - wxBoxSizer *m_SizerIRPointerWidth[4], *m_SizerIRPointerHeight[4], + wxBoxSizer *m_SizerIRPointerWidth[4], *m_SizerIRPointerHeight[4], *m_SizerIRPointerScreen[4], *m_SizeBasicPadding[4], *m_SizeEmuPadding[4], *m_SizeRealPadding[4], *m_SizeExtensionsPadding[4], *m_SizeBasicGeneral[4], *m_SizeBasicGeneralLeft[4], *m_SizeBasicGeneralRight[4], *m_HorizControllers[4], *m_gC2SDeadZone[4], *m_gCircle2Square[4], *m_gCircle2SquareVert[4], *m_gDeadZone[4], *m_gDeadZoneHoriz[4], *m_HorizControllerTiltParent[4], *m_HorizControllerTilt[4], *m_TiltHoriz[4], @@ -124,7 +124,7 @@ class ConfigDialog : public wxDialog *m_bCcDl[4], *m_bCcDu[4], *m_bCcDr[4], *m_bCcDd[4], *m_bCcLl[4], *m_bCcLu[4], *m_bCcLr[4], *m_bCcLd[4], *m_bCcRl[4], *m_bCcRu[4], *m_bCcRr[4], *m_bCcRd[4]; - wxStaticText *m_TextScreenWidth[4], *m_TextScreenHeight[4], *m_TextScreenLeft[4], *m_TextScreenTop[4], + wxStaticText *m_TextScreenWidth[4], *m_TextScreenHeight[4], *m_TextScreenLeft[4], *m_TextScreenTop[4], *m_TextAR[4], *m_tAnalogX[8], *m_tAnalogY[8], *m_TiltTextRoll[4], *m_TiltTextPitch[4], *m_CheckC2SLabel[4], *m_ComboDeadZoneLabel[4], *m_TStatusLeftIn[4], *m_TStatusLeftOut[4], *m_TStatusRightIn[4], *m_TStatusRightOut[4], *m_TriggerStatusL[4], *m_TriggerStatusR[4], *m_TriggerStatusLx[4], *m_TriggerStatusRx[4], @@ -147,9 +147,10 @@ class ConfigDialog : public wxDialog wxSlider *m_SliderWidth[4], *m_SliderHeight[4], *m_SliderLeft[4], *m_SliderTop[4]; // Emulated Wiimote settings - wxCheckBox *m_SidewaysDPad[4], *m_WiimoteOnline[4]; - wxCheckBox *m_CheckC2S[4], *m_TiltInvertRoll[4], *m_TiltInvertPitch[4]; - wxCheckBox *m_WiiMotionPlusConnected[4], *m_NunchuckConnected[4], *m_ClassicControllerConnected[4], *m_BalanceBoardConnected[4], *m_GuitarHeroGuitarConnected[4], *m_GuitarHeroWorldTourDrumsConnected[4]; + wxCheckBox *m_SidewaysDPad[4], *m_WiimoteOnline[4], + *m_CheckC2S[4], *m_TiltInvertRoll[4], *m_TiltInvertPitch[4], + *m_WiiMotionPlusConnected[4], *m_NunchuckConnected[4], *m_ClassicControllerConnected[4], *m_BalanceBoardConnected[4], *m_GuitarHeroGuitarConnected[4], *m_GuitarHeroWorldTourDrumsConnected[4], + *m_CheckAR43[4], *m_CheckAR169[4], *m_Crop[4]; wxComboBox *m_TiltComboInput[4], *m_TiltComboRangeRoll[4], *m_TiltComboRangePitch[4], *m_Joyname[4], *m_ComboDiagonal[4], *m_ComboDeadZoneLeft[4], *m_ComboDeadZoneRight[4], *m_TriggerType[4], *m_NunchuckComboStick[4], *m_CcComboLeftStick[4], *m_CcComboRightStick[4], *m_CcComboTriggers[4]; diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp index d480957724..bfc7b71a9d 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigRecording.cpp @@ -259,7 +259,9 @@ void ConfigDialog::CreateGUIControlsRecording() wxBoxSizer * sRealRecord[RECORDING_ROWS + 1]; wxStaticText * m_TextRec = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Rec."), wxDefaultPosition, wxSize(80, -1), wxALIGN_CENTRE); - wxStaticText * m_TextHotKey = new wxStaticText(m_PageRecording, wxID_ANY, wxT("HotKey"), wxDefaultPosition, wxSize(170, -1), wxALIGN_CENTRE); + wxStaticText * m_TextHotKeyWm = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Wiim."), wxDefaultPosition, wxSize(32, -1), wxALIGN_CENTRE); + wxStaticText * m_TextHotKeyNc = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Nunc."), wxDefaultPosition, wxSize(32, -1), wxALIGN_CENTRE); + wxStaticText * m_TextHotKeyIR = new wxStaticText(m_PageRecording, wxID_ANY, wxT("IR"), wxDefaultPosition, wxSize(32, -1), wxALIGN_CENTRE); wxStaticText * m_TextMovement = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Movement name"), wxDefaultPosition, wxSize(200, -1), wxALIGN_CENTRE); wxStaticText * m_TextGame = new wxStaticText(m_PageRecording, wxID_ANY, wxT("Game name"), wxDefaultPosition, wxSize(200, -1), wxALIGN_CENTRE); wxStaticText * m_TextIRBytes = new wxStaticText(m_PageRecording, wxID_ANY, wxT("IR"), wxDefaultPosition, wxSize(20, -1), wxALIGN_CENTRE); @@ -270,11 +272,16 @@ void ConfigDialog::CreateGUIControlsRecording() m_TextRec->SetToolTip(wxT( "To record a movement first press this button, then start the recording by pressing 'A' on the Wiimote and stop the recording\n" "by letting go of 'A'")); - m_TextHotKey->SetToolTip( - wxT("Select a hotkey for playback of 1. Wiimote movements, 2. Nunchuck movements, 3. IR data. You can combine it with an" - " option Shift, Ctrl, or Alt switch." + m_TextHotKeyWm->SetToolTip(wxT( + "Select a hotkey for playback of Wiimote movements. You can combine it with an" + " optional Shift, Ctrl, or Alt switch." )); - m_TextRecSpeed->SetToolTip(wxT("Recording speed in average measurements per second")); + m_TextHotKeyNc->SetToolTip(wxT( + "Select a hotkey for playback of Nunchuck movements")); + m_TextHotKeyIR->SetToolTip(wxT( + "Select a hotkey for playback of Nunchuck movements")); + m_TextRecSpeed->SetToolTip(wxT( + "Recording speed in average measurements per second")); m_TextPlaySpeed->SetToolTip(wxT( "Playback speed: A playback speed of 100 means that the playback occurs at the same rate as it was recorded. (You can see the\n" "current update rate in the Status window above when a game is running.) However, if your framerate is only at 50% of full speed\n" @@ -286,7 +293,9 @@ void ConfigDialog::CreateGUIControlsRecording() sRealRecord[0] = new wxBoxSizer(wxHORIZONTAL); sRealRecord[0]->Add(m_TextRec, 0, wxEXPAND | (wxLEFT), 5); - sRealRecord[0]->Add(m_TextHotKey, 0, wxEXPAND | (wxLEFT), 5); + sRealRecord[0]->Add(m_TextHotKeyWm, 0, wxEXPAND | (wxLEFT), 62); + sRealRecord[0]->Add(m_TextHotKeyNc, 0, wxEXPAND | (wxLEFT), 5); + sRealRecord[0]->Add(m_TextHotKeyIR, 0, wxEXPAND | (wxLEFT), 5); sRealRecord[0]->Add(m_TextMovement, 0, wxEXPAND | (wxLEFT), 5); sRealRecord[0]->Add(m_TextGame, 0, wxEXPAND | (wxLEFT), 5); sRealRecord[0]->Add(m_TextIRBytes, 0, wxEXPAND | (wxLEFT), 5); diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h index 1ddf5154ed..95eba711f1 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h @@ -134,14 +134,11 @@ static const u8 wireless_nunchuck_calibration[] = 0, 126, 0xed, 0x43 }; -/* Classic Controller calibration. 0x80 is the neutral for the analog triggers and - sticks. The left analog range is 0x1c - 0xe4 and the right is 0x28 - 0xd8. - We use this range because it's closest to the GC controller range. */ +/* Classic Controller calibration */ static const u8 classic_calibration[] = { - //0xe4,0x1c,0x80, 0xe4,0x1c,0x80, 0xd8,0x28,0x80, 0xd8,0x28,0x80, // Old calibration 0xff,0x00,0x80, 0xff,0x00,0x80, 0xff,0x00,0x80, 0xff,0x00,0x80, - 0x00,0x00, 0x95,0xea + 0x00,0x00, 0x51,0xa6 }; diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp index 9abba9539e..ef55643b08 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp @@ -69,23 +69,115 @@ void GetMousePos(float& x, float& y) // Get the cursor position relative to the upper left corner of the rendering window ScreenToClient(g_WiimoteInitialize.hWnd, &point); - // Get the size of the rendering window. In my case top and left was zero. + // Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.) RECT Rect; GetClientRect(g_WiimoteInitialize.hWnd, &Rect); // Width and height is the size of the rendering window - int width = Rect.right - Rect.left; - int height = Rect.bottom - Rect.top; + float WinWidth = (float)(Rect.right - Rect.left); + float WinHeight = (float)(Rect.bottom - Rect.top); + float XOffset = 0, YOffset = 0; + float PictureWidth = WinWidth, PictureHeight = WinHeight; - // Return the mouse position as a fraction of one - x = point.x / (float)width; - y = point.y / (float)height; + // ----------------------------------------------------------------------- + /* Calculate the actual picture size and location */ + // Output: PictureWidth, PictureHeight, XOffset, YOffset + // ------------------ + if (g_Config.bKeepAR43 || g_Config.bKeepAR169) + { + // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio + float Ratio = WinWidth / WinHeight / (g_Config.bKeepAR43 ? (4.0f / 3.0f) : (16.0f / 9.0f)); + // Check if height or width is the limiting factor. If ratio > 1 the picture is to wide and have to limit the width. + if (Ratio > 1) + { + // ------------------------------------------------ + // Calculate the new width and height for glViewport, this is not the actual size of either the picture or the screen + // ---------------- + PictureWidth = WinWidth / Ratio; + // -------------------- + + // ------------------------------------------------ + // Calculate the new X offset + // ---------------- + // Move the left of the picture to the middle of the screen + XOffset = XOffset + WinWidth / 2.0; + // Then remove half the picture height to move it to the horizontal center + XOffset = XOffset - PictureWidth / 2.0; + // -------------------- + } + // The window is to high, we have to limit the height + else + { + // ------------------------------------------------ + // Calculate the new width and height for glViewport, this is not the actual size of either the picture or the screen + // ---------------- + // Invert the ratio to make it > 1 + Ratio = 1.0 / Ratio; + PictureHeight = WinHeight / Ratio; + // -------------------- + + // ------------------------------------------------ + // Calculate the new Y offset + // ---------------- + // Move the top of the picture to the middle of the screen + YOffset = YOffset + WinHeight / 2.0; + // Then remove half the picture height to move it to the vertical center + YOffset = YOffset - PictureHeight / 2.0; + // -------------------- + } + // Logging + /* + Console::ClearScreen(); + Console::Print("Screen Width:%4.0f Height:%4.0f Ratio:%1.2f\n", WinWidth, WinHeight, Ratio); + Console::Print("Picture Width:%4.1f Height:%4.1f YOffset:%4.0f XOffset:%4.0f\n", PictureWidth, PictureHeight, YOffset, XOffset); + Console::Print("----------------------------------------------------------------\n"); + */ + } + // ------------------------------------- + + // ----------------------------------------------------------------------- + /* Crop the picture from 4:3 to 5:4 or from 16:9 to 16:10. */ + // Output: PictureWidth, PictureHeight, XOffset, YOffset + // ------------------ + if ((g_Config.bKeepAR43 || g_Config.bKeepAR169) && 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 (calculate this before PictureWidth and PictureHeight is adjusted) + float IncreasedWidth = (Ratio - 1.0) * PictureWidth; + float IncreasedHeight = (Ratio - 1.0) * PictureHeight; + + // The new width and height + PictureWidth = PictureWidth * Ratio; + PictureHeight = PictureHeight * Ratio; + + // Adjust the X and Y offset + XOffset = XOffset - (IncreasedWidth / 2.0); + YOffset = YOffset - (IncreasedHeight / 2.0); + + // Logging + /* + Console::Print("Crop Ratio:%1.2f IncrWidth:%3.0f IncrHeight:%3.0f\n", Ratio, IncreasedWidth, IncreasedHeight); + Console::Print("Picture Width:%4.1f Height:%4.1f YOffset:%4.0f XOffset:%4.0f\n", PictureWidth, PictureHeight, YOffset, XOffset); + Console::Print("----------------------------------------------------------------\n"); + */ + } + // ------------------------------------- + + // Return the mouse position as a fraction of one, inside the picture, with (0.0, 0.0) being the upper left corner of the picture + x = ((float)point.x - XOffset) / PictureWidth; + y = ((float)point.y - YOffset) / PictureHeight; + + // ---------------------------------------------------------- + // Logging + // ------------- /* - Console::ClearScreen(); - Console::Print("GetCursorPos: %i %i\n", point.x, point.y); + Console::Print("GetCursorPos: %i %i\n", point.x, point.y); Console::Print("GetClientRect: %i %i %i %i\n", Rect.left, Rect.right, Rect.top, Rect.bottom); - Console::Print("x and y: %f %f\n", x, y); + Console::Print("Position X:%1.2f Y:%1.2f\n", x, y); */ + // --------------------------- + #else // TODO fix on linux x = 0.5f; @@ -117,6 +209,22 @@ void WriteCrypted16(u8* _baseBlock, u16 _address, u16 _value) // ================ +// =================================================== +/* Calculate Extenstion Regisister Calibration Checksum */ +// This function is not currently used, it's just here to show how the values in EmuDefinitions.h are calculated. +// ---------------- +void GetCalibrationChecksum() +{ + u8 sum = 0; + for (int i = 0; i < sizeof(nunchuck_calibration) - 2; i++) + sum += nunchuck_calibration[i]; + u8 Check1 = sum + 0x55; + u8 Check2 = sum + 0xaa; + Console::Print("0x%02x 0x%02x", Check1, Check2); +} +// ================ + + // =================================================== /* Load pre-recorded movements */ // ----------------