From 5721836d4483c6e00049234bf990f473f1dbbbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Oct 2013 16:44:12 +0200 Subject: [PATCH] Add basic haptic feedback to on-screen touch buttons. --- Core/Config.cpp | 2 ++ Core/Config.h | 13 +++++++------ UI/GameSettingsScreen.cpp | 5 +++-- UI/GamepadEmu.cpp | 17 ++++++++++++++--- UI/GamepadEmu.h | 1 - native | 2 +- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 8396d78afb..e58a03e700 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -188,6 +188,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) sound->Get("LowLatency", &bLowLatencyAudio, false); IniFile::Section *control = iniFile.GetOrCreateSection("Control"); + control->Get("HapticFeedback", &bHapticFeedback, true); control->Get("ShowAnalogStick", &bShowAnalogStick, true); #ifdef BLACKBERRY control->Get("ShowTouchControls", &bShowTouchControls, pixel_xres != pixel_yres); @@ -356,6 +357,7 @@ void Config::Save() { sound->Set("LowLatency", bLowLatencyAudio); IniFile::Section *control = iniFile.GetOrCreateSection("Control"); + control->Set("HapticFeedback", bHapticFeedback); control->Set("ShowAnalogStick", bShowAnalogStick); control->Set("ShowTouchControls", bShowTouchControls); // control->Set("KeyMapping",iMappingMap); diff --git a/Core/Config.h b/Core/Config.h index a9494ed537..ec273637ab 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -36,7 +36,6 @@ public: bool bAutoRun; // start immediately bool bBrowse; // when opening the emulator, immediately show a file browser - // General int iNumWorkerThreads; bool bScreenshotsAsPNG; @@ -103,10 +102,15 @@ public: int iSFXVolume; int iBGMVolume; - // UI + // Controls bool bShowTouchControls; - bool bShowDebuggerOnLoad; bool bShowAnalogStick; + bool bHapticFeedback; + int iTouchButtonOpacity; + float fButtonScale; + + // UI + bool bShowDebuggerOnLoad; int iShowFPSCounter; bool bShowDebugStats; bool bAccelerometerToAnalogHoriz; @@ -117,9 +121,6 @@ public: bool bGridView2; bool bGridView3; - // Control - int iTouchButtonOpacity; - float fButtonScale; // GLES backend-specific hacks. Not saved to the ini file, do not add checkboxes. Will be made into diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 04a655d0b3..6c73ee317c 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -196,7 +196,7 @@ void GameSettingsScreen::CreateViews() { audioSettings->Add(new PopupSliderChoice(&g_Config.iSFXVolume, 0, 8, a->T("SFX volume"), screenManager())); audioSettings->Add(new PopupSliderChoice(&g_Config.iBGMVolume, 0, 8, a->T("BGM volume"), screenManager())); - + audioSettings->Add(new CheckBox(&g_Config.bEnableSound, a->T("Enable Sound"))); audioSettings->Add(new CheckBox(&g_Config.bEnableAtrac3plus, a->T("Enable Atrac3+"))); audioSettings->Add(new CheckBox(&g_Config.bLowLatencyAudio, a->T("Low latency audio"))); @@ -210,6 +210,7 @@ void GameSettingsScreen::CreateViews() { controlsSettings->Add(new ItemHeader(ms->T("Controls"))); controlsSettings->Add(new Choice(c->T("Control Mapping")))->OnClick.Handle(this, &GameSettingsScreen::OnControlMapping); #ifdef USING_GLES2 + controlsSettings->Add(new CheckBox(&g_Config.bHapticFeedback, c->T("HapticFeedback", "Haptic Feedback (vibration)"))); controlsSettings->Add(new CheckBox(&g_Config.bAccelerometerToAnalogHoriz, c->T("Tilt", "Tilt to Analog (horizontal)"))); controlsSettings->Add(new PopupSliderChoice(&g_Config.iTiltSensitivity, 10, 200, c->T("Tilt Sensitivity"), screenManager())); #endif @@ -218,7 +219,7 @@ void GameSettingsScreen::CreateViews() { controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonOpacity, 0, 100, c->T("Button Opacity"), screenManager())); controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fButtonScale, 0.80, 2.0, c->T("Button Scaling"), screenManager())); controlsSettings->Add(new CheckBox(&g_Config.bShowAnalogStick, c->T("Show Left Analog Stick"))); - + // System ViewGroup *systemSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); LinearLayout *systemSettings = new LinearLayout(ORIENT_VERTICAL); diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 1a802acd4e..1c7cb933f6 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -17,6 +17,7 @@ #include "GamepadEmu.h" #include "base/colorutil.h" +#include "base/NativeApp.h" #include "math/math_util.h" #include "ui/virtual_input.h" #include "ui/ui_context.h" @@ -56,7 +57,7 @@ void MultiTouchButton::Touch(const TouchInput &input) { void MultiTouchButton::Draw(UIContext &dc) { float opacity = g_Config.iTouchButtonOpacity / 100.0f; - + float scale = scale_; if (IsDown()) { scale *= 2.0f; @@ -84,6 +85,9 @@ void PSPButton::Touch(const TouchInput &input) { MultiTouchButton::Touch(input); bool down = pointerDownMask_ != 0; if (down && !lastDown) { + if (g_Config.bHapticFeedback) { + Vibrate(HAPTIC_VIRTUAL_KEY); + } __CtrlButtonDown(pspButtonBit_); } else if (lastDown && !down) { __CtrlButtonUp(pspButtonBit_); @@ -158,8 +162,15 @@ void PSPCross::ProcessTouch(float x, float y, bool down) { int released = (~down_) & lastDown; static const int dir[4] = {CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP}; for (int i = 0; i < 4; i++) { - if (pressed & dir[i]) __CtrlButtonDown(dir[i]); - if (released & dir[i]) __CtrlButtonUp(dir[i]); + if (pressed & dir[i]) { + if (g_Config.bHapticFeedback) { + Vibrate(HAPTIC_VIRTUAL_KEY); + } + __CtrlButtonDown(dir[i]); + } + if (released & dir[i]) { + __CtrlButtonUp(dir[i]); + } } } diff --git a/UI/GamepadEmu.h b/UI/GamepadEmu.h index 440cda06c5..c29783db4f 100644 --- a/UI/GamepadEmu.h +++ b/UI/GamepadEmu.h @@ -67,7 +67,6 @@ class PSPButton : public MultiTouchButton { public: PSPButton(int pspButtonBit, int bgImg, int img, float scale, UI::LayoutParams *layoutParams) : MultiTouchButton(bgImg, img, scale, layoutParams), pspButtonBit_(pspButtonBit) { - } virtual void Touch(const TouchInput &input); virtual bool IsDown(); diff --git a/native b/native index c0c8df6155..9aa30a69f6 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit c0c8df61551fa4d7c205e84b23510bbfb8f065c4 +Subproject commit 9aa30a69f6f4d64b7d5e9d492e857b8eb03e7b7c