File: Input.hpp

package info (click to toggle)
criticalmass 1%3A1.0.0-1.5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 18,740 kB
  • sloc: ansic: 47,628; cpp: 25,167; sh: 12,025; xml: 3,532; perl: 3,271; makefile: 662; python: 66; awk: 40; lisp: 33
file content (129 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download | duplicates (11)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Description:
//   Input subsystem.
//
// Copyright (C) 2001 Frank Becker
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation;  either version 2 of the License,  or (at your option) any  later
// version.
//
// This program is distributed in the hope that it will be useful,  but  WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
//
#ifndef _Input_hpp_
#define _Input_hpp_

#include <hashMap.hpp>

#include <Singleton.hpp>
#include <Trigger.hpp>
#include <Keys.hpp>
#include <ConfigHandler.hpp>
#include <CallbackManager.hpp>
#include <InterceptorI.hpp>

class Callback;

namespace HASH_NAMESPACE
{
    template<>
	struct hash<Trigger>
    {
	//a simple hash function for Trigger
	int operator()(const Trigger &t) const
	{
	    int hashval;
	    
	    if( t.type == eMotionTrigger)
	    {
		hashval = t.type*1000;
	    }
	    else
	    {
		hashval = t.type*1000+t.data1;
	    }

	    return hashval;
	}
    };
}

class Input: public ConfigHandler
{
friend class Singleton<Input>;
public:
    Input *preinit( void);
    bool init( void);
    bool update( void);

    //used for loading/saving bindings
    virtual void handleLine( const string line);
    virtual void save( ofstream &of);

    //Input takes ownership of callback
    void bindNextTrigger( Callback *cb)
    {
        _bindMode = true;
        _callback = cb;
    }

    bool waitingForBind( void)
    {
        return _bindMode;
    }

    void addCallback( Callback *cb)
    {
	_callbackManager.addCallback( cb);
    }

    void enableInterceptor( InterceptorI *i)
    {
	_interceptor = i;
    }

    void disableInterceptor( void)
    {
	_interceptor = 0;
    }

private:
    virtual ~Input();
    Input( void);
    Input( const Input&);
    Input &operator=(const Input&);

    void bind( Trigger &t, Callback *action);
    bool tryGetTrigger( Trigger &trigger, bool &isDown);
    void updateMouseSettings( void);

    bool _bindMode;
    Callback *_callback;
    CallbackManager _callbackManager;
    Keys _keys;

    hash_map< Trigger, Callback*, hash<Trigger>, equal_to<Trigger> > _callbackMap;

    //stuff for mouse smoothing
    float _memoryDX;
    float _memoryDY;
    float _valDX;
    float _valDY;
    float _dampVal;
    float feedbackFilter( float value, float damp, float &memory)
    {
	//damp of 0 means no filtering
	//damp of 1 means input value is filtered out completely
	return memory = value*(1.0f-damp) + memory*damp;
    }   
    float _sensitivity;

    //intercept raw input
    InterceptorI *_interceptor;
};

typedef Singleton<Input> InputS;

#endif