Updated German translation
[dasher.git] / Src / DasherCore / DynamicButtons.cpp
blob83c75fd4c40a81ff50bdb45098e8b11afa800e61
1 // DynamicButtons.cpp
2 //
3 // Copyright (c) 2007 The Dasher Team
4 //
5 // This file is part of Dasher.
6 //
7 // Dasher is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // Dasher is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with Dasher; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "DasherInterfaceBase.h"
22 #include "DynamicButtons.h"
24 using namespace Dasher;
26 CDynamicButtons::CDynamicButtons(CSettingsUser *pCreator, CDasherInterfaceBase *pInterface, CFrameRate *pFramerate, ModuleID_t iID, const char *szName)
27 : CDynamicFilter(pCreator, pInterface, pFramerate, iID, szName), m_pModel(NULL) {
28 m_bDecorationChanged = true;
29 m_bKeyDown = false;
30 pause();
33 void CDynamicButtons::Timer(unsigned long iTime, CDasherView *pDasherView, CDasherInput *pInput, CDasherModel *pModel, CExpansionPolicy **pol) {
34 if (isPaused()) return;
35 if (isReversing()) {
36 OneStepTowards(pModel, 41943,2048, iTime, FrameSpeedMul(pModel, iTime));
37 } else {
38 //moving forwards. Check auto speed control...
39 if (GetBoolParameter(BP_AUTO_SPEEDCONTROL) && m_uSpeedControlTime < iTime) {
40 if (m_uSpeedControlTime > 0) //has actually been set?
41 SetLongParameter(LP_MAX_BITRATE, GetLongParameter(LP_MAX_BITRATE) * (1.0 + GetLongParameter(LP_DYNAMIC_SPEED_INC)/100.0));
42 m_uSpeedControlTime = iTime + 1000*GetLongParameter(LP_DYNAMIC_SPEED_FREQ);
44 TimerImpl(iTime, pDasherView, pModel, pol);
48 void CDynamicButtons::KeyDown(unsigned long iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel) {
50 if(((iId == 0) || (iId == 1) || (iId == 100)) && !GetBoolParameter(BP_BACKOFF_BUTTON))
51 return;
53 if(m_bKeyDown)
54 return;
56 // Pass the basic key down event to the handler
57 ButtonEvent(iTime, iId, 0, pModel);
59 m_iHeldId = iId;
60 m_bKeyDown = true;
63 void CDynamicButtons::KeyUp(unsigned long iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel) {
64 if (iId == m_iHeldId) m_bKeyDown = false;
67 void CDynamicButtons::ButtonEvent(unsigned long iTime, int iButton, int iType, CDasherModel *pModel) {
69 // TODO: Check that state diagram implemented here is what we
70 // decided upon
72 // What happens next depends on the state:
73 if (isPaused()) {
74 //Any button causes a restart
75 if(CUserLogBase *pUserLog=m_pInterface->GetUserLogPtr())
76 pUserLog->KeyDown(iButton, iType, 1);
77 run(iTime);
78 } else if (isReversing()) {
79 //Any button pauses
80 if(CUserLogBase *pUserLog=m_pInterface->GetUserLogPtr())
81 pUserLog->KeyDown(iButton, iType, 2);
82 m_pInterface->Done();
83 pause();
84 } else {
85 //running; examine event/button-press type
86 switch(iType) {
87 case 0: //single press
88 if((iButton == 0) || (iButton == 100)) {
89 //dedicated pause button
90 if(CUserLogBase *pUserLog=m_pInterface->GetUserLogPtr())
91 pUserLog->KeyDown(iButton, iType, 2);
92 m_pInterface->Done();
93 pause();
94 break;
96 else if(iButton == 1) {
97 //dedicated reverse button
98 if(CUserLogBase *pUserLog=m_pInterface->GetUserLogPtr())
99 pUserLog->KeyDown(iButton, iType, 6);
100 reverse(iTime);
101 break;
103 //else - any non-special button - fall through
104 default: //or, Any special kind of event - long, double, triple, ...
105 ActionButton(iTime, iButton, iType, pModel);
110 void CDynamicButtons::pause() {
111 CDynamicFilter::pause();
112 if (m_pModel) m_pModel->AbortOffset();
115 void CDynamicButtons::reverse(unsigned long iTime) {
116 m_bForwards=false;
117 if (isPaused()) CDynamicFilter::run(iTime);
118 if (GetBoolParameter(BP_AUTO_SPEEDCONTROL)) {
119 //treat reversing as a sign of distress --> slow down!
120 SetLongParameter(LP_MAX_BITRATE, GetLongParameter(LP_MAX_BITRATE) *
121 (1.0 - GetLongParameter(LP_DYNAMIC_SPEED_DEC)/100.0));
125 void CDynamicButtons::run(unsigned long iTime) {
126 m_bForwards=true;
127 if (isPaused()) CDynamicFilter::run(iTime); //wasn't running previously
128 m_uSpeedControlTime = 0; //will be set in Timer()
131 void CDynamicButtons::ApplyOffset(CDasherModel *pModel, int iOffset) {
132 (m_pModel=pModel)->Offset(iOffset);