summaryrefslogtreecommitdiffstats
path: root/game/code/input/button.h
blob: 7c76288b81916753559f63fd8c958aa4f6cd8e73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef BUTTON_H_
#define BUTTON_H_

// An input point, either physical (if storeig in a UserController), or logical (if stored in a Mappable
// (even joysticks are treated as "buttons" by the game)
class Button
{
public:
    Button( void );
    ~Button( void );

    // test the properties of the button
	inline float GetValue( void ) const;
    inline void  SetValue( float fValue );
	inline bool  IsDown( void ) const;
	inline bool  IsUp( void ) const;
	
    // returns number of input ticks since the value of this button changed
	inline unsigned int TimeSinceChange( void ) const; 
    
    // force the change flag to be set without resetting the value
    inline void ForceChange(void);
    
    inline static void Tick(int timeinms) { mTickCount += timeinms; }

protected:
    float mfValue;
    unsigned int mTickCountAtChange; 

    // counter for current number of input ticks (for tracking 
    static unsigned int mTickCount;
};

// Inline member functions
float Button::GetValue( void ) const
{
	return mfValue;
}

void Button::ForceChange(void)
{
    mTickCountAtChange = mTickCount;
}

void Button::SetValue( float fValue )
{
    mTickCountAtChange = mTickCount;
    mfValue = fValue;
}

bool Button::IsDown( void ) const
{
	return mfValue != 0.0f;
}

bool Button::IsUp( void ) const
{
	return mfValue == 0.0f;
}

unsigned int Button::TimeSinceChange( void ) const
{
	return mTickCount - mTickCountAtChange;
}

// nbrooke 15/10/02  :I devirtualized the Button class (there was a lot of hierarchy 
// and virtual functions considering there was only one class avtually used my any other code) 
// but didn't feel like changing a bunch of stuff that was using IButton, thus the typedef
typedef Button IButton;

#endif