aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranz Koch <franz.koch@elements-net.de>2012-11-22 11:17:13 +0100
committerJonathan Marshall <jmarshall@never.you.mind>2012-12-01 14:45:20 +1300
commitd81240b610da378f4a79a118891317de47b5c4bc (patch)
treeff5d935e5ed38cbffc398655da94f03181cab37d
parent09c5bd6005f5cd5a0eb2f51bf21cf95acbb1ce35 (diff)
[input] use shared/unified method to trigger an input action and remove code duplication
-rw-r--r--xbmc/Application.cpp70
-rw-r--r--xbmc/Application.h1
2 files changed, 26 insertions, 45 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp
index 3d838f6b09..ef185689bf 100644
--- a/xbmc/Application.cpp
+++ b/xbmc/Application.cpp
@@ -2523,23 +2523,7 @@ bool CApplication::OnKey(const CKey& key)
if (!key.IsAnalogButton())
CLog::Log(LOGDEBUG, "%s: %s pressed, action is %s", __FUNCTION__, g_Keyboard.GetKeyName((int) key.GetButtonCode()).c_str(), action.GetName().c_str());
- bool bResult = false;
-
- // play sound before the action unless the button is held,
- // where we execute after the action as held actions aren't fired every time.
- if(action.GetHoldTime())
- {
- bResult = OnAction(action);
- if(bResult)
- g_audioManager.PlayActionSound(action);
- }
- else
- {
- g_audioManager.PlayActionSound(action);
- bResult = OnAction(action);
- }
-
- return bResult;
+ return ExecuteInputAction(action);
}
// OnAppCommand is called in response to a XBMC_APPCOMMAND event.
@@ -3007,10 +2991,9 @@ bool CApplication::ProcessGamepad(float frameTime)
if (CButtonTranslator::GetInstance().TranslateJoystickString(iWin, g_Joystick.GetJoystick().c_str(), bid, JACTIVE_BUTTON, actionID, actionName, fullrange))
{
CAction action(actionID, 1.0f, 0.0f, actionName);
- g_audioManager.PlayActionSound(action);
g_Joystick.Reset();
g_Mouse.SetActive(false);
- return OnAction(action);
+ return ExecuteInputAction(action);
}
else
{
@@ -3036,10 +3019,9 @@ bool CApplication::ProcessGamepad(float frameTime)
}
CAction action(actionID, fullrange ? (g_Joystick.GetAmount() + 1.0f)/2.0f : fabs(g_Joystick.GetAmount()), 0.0f, actionName);
- g_audioManager.PlayActionSound(action);
g_Joystick.Reset();
g_Mouse.SetActive(false);
- return OnAction(action);
+ return ExecuteInputAction(action);
}
else
{
@@ -3068,10 +3050,9 @@ bool CApplication::ProcessGamepad(float frameTime)
if (bid && CButtonTranslator::GetInstance().TranslateJoystickString(iWin, g_Joystick.GetJoystick().c_str(), bid, JACTIVE_HAT, actionID, actionName, fullrange))
{
CAction action(actionID, 1.0f, 0.0f, actionName);
- g_audioManager.PlayActionSound(action);
g_Joystick.Reset();
g_Mouse.SetActive(false);
- return OnAction(action);
+ return ExecuteInputAction(action);
}
}
#endif
@@ -3269,35 +3250,34 @@ bool CApplication::ProcessJoystickEvent(const std::string& joystickName, int wKe
// Translate using regular joystick translator.
if (CButtonTranslator::GetInstance().TranslateJoystickString(iWin, joystickName.c_str(), wKeyID, isAxis ? JACTIVE_AXIS : JACTIVE_BUTTON, actionID, actionName, fullRange))
- {
- CAction action(actionID, fAmount, 0.0f, actionName, holdTime);
- bool bResult = false;
-
- // play sound before the action unless the button is held,
- // where we execute after the action as held actions aren't fired every time.
- if(action.GetHoldTime())
- {
- bResult = OnAction(action);
- if(bResult)
- g_audioManager.PlayActionSound(action);
- }
- else
- {
- g_audioManager.PlayActionSound(action);
- bResult = OnAction(action);
- }
-
- return bResult;
- }
+ return ExecuteInputAction( CAction(actionID, fAmount, 0.0f, actionName, holdTime) );
else
- {
CLog::Log(LOGDEBUG, "ERROR mapping joystick action. Joystick: %s %i",joystickName.c_str(), wKeyID);
- }
#endif
return false;
}
+bool CApplication::ExecuteInputAction(CAction action)
+{
+ bool bResult = false;
+
+ // play sound before the action unless the button is held,
+ // where we execute after the action as held actions aren't fired every time.
+ if(action.GetHoldTime())
+ {
+ bResult = OnAction(action);
+ if(bResult)
+ g_audioManager.PlayActionSound(action);
+ }
+ else
+ {
+ g_audioManager.PlayActionSound(action);
+ bResult = OnAction(action);
+ }
+ return bResult;
+}
+
int CApplication::GetActiveWindowID(void)
{
// Get the currently active window
diff --git a/xbmc/Application.h b/xbmc/Application.h
index 650fc87690..33d500df50 100644
--- a/xbmc/Application.h
+++ b/xbmc/Application.h
@@ -447,6 +447,7 @@ protected:
bool ProcessEventServer(float frameTime);
bool ProcessPeripherals(float frameTime);
bool ProcessJoystickEvent(const std::string& joystickName, int button, bool isAxis, float fAmount, unsigned int holdTime = 0);
+ bool ExecuteInputAction(CAction action);
int GetActiveWindowID(void);
float NavigationIdleTime();