Debian Codegraph @

xbmc/games/controllers/guicontrols/GUIThrottleButton.cpp

raw
1 /*
2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "GUIThrottleButton.h"
10
11 #include "guilib/LocalizeStrings.h"
12
13 #include <string>
14
15 using namespace KODI;
16 using namespace GAME;
17
18 CGUIThrottleButton::CGUIThrottleButton(const CGUIButtonControl& buttonTemplate,
19 IConfigurationWizard* wizard,
20 const CPhysicalFeature& feature,
21 unsigned int index)
22 : CGUIFeatureButton(buttonTemplate, wizard, feature, index)
23 {
24 Reset();
25 }
26
27 bool CGUIThrottleButton::PromptForInput(CEvent& waitEvent)
28 {
29 using namespace JOYSTICK;
30
31 bool bInterrupted = false;
32
33 // Get the prompt for the current analog stick direction
34 std::string strPrompt;
35 std::string strWarn;
36 switch (m_state)
37 {
38 case STATE::THROTTLE_UP:
39 strPrompt = g_localizeStrings.Get(35092); // "Move %s up"
40 strWarn = g_localizeStrings.Get(35093); // "Move %s up (%d)"
41 break;
42 case STATE::THROTTLE_DOWN:
43 strPrompt = g_localizeStrings.Get(35094); // "Move %s down"
44 strWarn = g_localizeStrings.Get(35095); // "Move %s down (%d)"
45 break;
46 default:
47 break;
48 }
49
50 if (!strPrompt.empty())
51 {
52 bInterrupted = DoPrompt(strPrompt, strWarn, m_feature.Label(), waitEvent);
53
54 if (!bInterrupted)
55 m_state = STATE::FINISHED; // Not interrupted, must have timed out
56 else
57 m_state = GetNextState(m_state); // Interrupted by input, proceed
58 }
59
60 return bInterrupted;
61 }
62
63 bool CGUIThrottleButton::IsFinished(void) const
64 {
65 return m_state >= STATE::FINISHED;
66 }
67
68 JOYSTICK::THROTTLE_DIRECTION CGUIThrottleButton::GetThrottleDirection(void) const
69 {
70 using namespace JOYSTICK;
71
72 switch (m_state)
73 {
74 case STATE::THROTTLE_UP:
75 return THROTTLE_DIRECTION::UP;
76 case STATE::THROTTLE_DOWN:
77 return THROTTLE_DIRECTION::DOWN;
78 default:
79 break;
80 }
81
82 return THROTTLE_DIRECTION::NONE;
83 }
84
85 void CGUIThrottleButton::Reset(void)
86 {
87 m_state = STATE::THROTTLE_UP;
88 }