Updated German translation
[dasher.git] / Src / DasherCore / DynamicButtons.h
blobf6d0386dd6f2b1f82def577c803d26c9fa4a9d5d
1 // DynamicFilter.h
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 #ifndef __DynamicButtons_h__
22 #define __DynamicButtons_h__
24 #include "DynamicFilter.h"
26 /// \ingroup InputFilter
27 /// @{
28 namespace Dasher {
29 ///filter with three states: paused, reversing, running. Button 1 is dedicated reverse
30 /// button (subclasses may also call reverse()); when reversing, any key pauses,
31 /// then any key restarts.
32 class CDynamicButtons : public CDynamicFilter {
33 public:
34 CDynamicButtons(CSettingsUser *pCreator, CDasherInterfaceBase *pInterface, CFrameRate *pFramerate, ModuleID_t iID, const char *szName);
36 ///when reversing, backs off; when paused, does nothing; when running, delegates to TimerImpl
37 virtual void Timer(unsigned long Time, CDasherView *pView, CDasherInput *pInput, CDasherModel *m_pDasherModel, CExpansionPolicy **pol);
39 virtual void KeyDown(unsigned long iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel);
40 virtual void KeyUp(unsigned long iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel);
42 protected:
43 ///Called when a key event is detected - could be a single press (a la KeyDown/KeyUp),
44 /// but is also called with explicit indication of "long" or other types of press,
45 /// avoiding need for subclasses to try to detect these manually. In the default implementation:
46 /// if paused, any key restarts; if reversing, any key pauses; if running, short presses
47 /// of button 0 or 100 act as a dedicated reverse button, and button 1 pauses; any other
48 /// press type or button is passed onto ActionButton.
49 /// \param iType 0=normal press, 1=long press; see also CButtonMultiPress.
50 virtual void ButtonEvent(unsigned long iTime, int iButton, int iType, CDasherModel *pModel);
52 ///Called to handle key events when the Filter is running forwards normally.
53 /// Short presses of buttons 0, 100 and 1 have been handled already, but all
54 /// other buttons/press-types will be passed here.
55 /// \param iType 0=normal press, 1=long press; see also CButtonMultiPress.
56 virtual void ActionButton(unsigned long iTime, int iButton, int iType, CDasherModel *pModel) = 0;
58 ///Whether a key (any that we might respond to) is held down.
59 /// If so, m_iHeldId identifies the key in question. We need this
60 /// not just for detecting long-presses etc. (in subclasses), and
61 /// ignoring presses of other keys while the first is down, but also
62 /// simply to filter out key-repeat events (=multiple keydown without a keyup)
63 bool m_bKeyDown;
65 ///if m_bKeyDown is true, identifies the key that was first pressed
66 /// that is currently still held down.
67 int m_iHeldId;
69 bool m_bDecorationChanged;
70 bool isReversing() {return !isPaused() && !m_bForwards;}
71 bool isRunning() {return !isPaused() && m_bForwards;}
72 virtual void pause();
73 virtual void reverse(unsigned long iTime);
74 virtual void run(unsigned long iTime);
76 virtual void TimerImpl(unsigned long Time, CDasherView *m_pDasherView, CDasherModel *m_pDasherModel, CExpansionPolicy **pol) = 0;
78 ///Subclasses should all this (rather than pModel->Offset()) to offset the model
79 /// (it also stores the model, to abort the offset upon pause if necessary)
80 void ApplyOffset(CDasherModel *pModel, int iOffset);
82 private:
83 bool m_bForwards;
84 unsigned long m_uSpeedControlTime;
85 CDasherModel *m_pModel;
88 #endif