MacKeyboard.h 3.16 KB
Newer Older
1
2
/*
 The zlib/libpng License
Ben Hymers's avatar
Ben Hymers committed
3
4
5

 Copyright (c) 2006 Chris Snyder

6
7
 This software is provided 'as-is', without any express or implied warranty. In no event will
 the authors be held liable for any damages arising from the use of this software.
Ben Hymers's avatar
Ben Hymers committed
8
9

 Permission is granted to anyone to use this software for any purpose, including commercial
10
11
 applications, and to alter it and redistribute it freely, subject to the following
 restrictions:
Ben Hymers's avatar
Ben Hymers committed
12
13
14
15

 1. The origin of this software must not be misrepresented; you must not claim that
 you wrote the original software. If you use this software in a product,
 an acknowledgment in the product documentation would be appreciated but is
16
 not required.
Ben Hymers's avatar
Ben Hymers committed
17
18

 2. Altered source versions must be plainly marked as such, and must not be
19
 misrepresented as being the original software.
Ben Hymers's avatar
Ben Hymers committed
20

21
22
23
24
25
26
27
28
29
30
31
32
33
 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef OIS_MacKeyboard_H
#define OIS_MacKeyboard_H

#include "OISKeyboard.h"
#include "mac/MacHelpers.h"
#include "mac/MacPrereqs.h"

#include <Carbon/Carbon.h>

namespace OIS
{
Ben Hymers's avatar
Ben Hymers committed
34

35
36
37
38
39
    class MacKeyboard : public Keyboard
    {
    public:
        MacKeyboard( InputManager* creator, bool buffered, bool repeat );
        virtual ~MacKeyboard();
Ben Hymers's avatar
Ben Hymers committed
40

41
42
        // Sets buffered mode
        virtual void setBuffered( bool buffered );
Ben Hymers's avatar
Ben Hymers committed
43

44
45
        // unbuffered keydown check
        virtual bool isKeyDown( KeyCode key ) const;
Ben Hymers's avatar
Ben Hymers committed
46

47
48
49
50
        // This will send listener events if buffered is on.
        // Note that in the mac implementation, unbuffered input is
        // automatically updated without calling this.
        virtual void capture();
Ben Hymers's avatar
Ben Hymers committed
51

52
53
        // Copies the current key buffer
        virtual void copyKeyStates( char keys[256] ) const;
Ben Hymers's avatar
Ben Hymers committed
54

55
56
        // Returns a description of the given key
        virtual std::string& getAsString( KeyCode key );
57
        virtual KeyCode getAsKeyCode( std::string str ) {/*TODO: Implement OS version*/;}
Ben Hymers's avatar
Ben Hymers committed
58

59
        virtual Interface* queryInterface( Interface::IType type ) { return 0; }
Ben Hymers's avatar
Ben Hymers committed
60
61


62
63
64
65
66
        // Public but reserved for internal use:
        virtual void _initialize();
        void _keyDownCallback( EventRef theEvent );
        void _keyUpCallback( EventRef theEvent );
        void _modChangeCallback( EventRef theEvent );
Ben Hymers's avatar
Ben Hymers committed
67

68
69
70
71

    protected:
        // just to get this out of the way
        void populateKeyConversion();
Ben Hymers's avatar
Ben Hymers committed
72

73
74
        // updates the keybuffer and optionally the eventStack
        void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt = 0 );
Ben Hymers's avatar
Ben Hymers committed
75

76
77
        typedef std::map<UInt32, KeyCode> VirtualtoOIS_KeyMap;
        VirtualtoOIS_KeyMap keyConversion;
Ben Hymers's avatar
Ben Hymers committed
78

79
        std::string getString;
Ben Hymers's avatar
Ben Hymers committed
80

81
82
        char KeyBuffer[256];
        UInt32 prevModMask;
Ben Hymers's avatar
Ben Hymers committed
83
84


85
86
87
88
        // "universal procedure pointers" - required reference for callbacks
        EventHandlerUPP keyDownUPP;
        EventHandlerUPP keyUpUPP;
        EventHandlerUPP keyModUPP;
Ben Hymers's avatar
Ben Hymers committed
89

90
91
92
93
        // so we can delete the handlers on destruction
        EventHandlerRef keyDownEventRef;
        EventHandlerRef keyUpEventRef;
        EventHandlerRef keyModEventRef;
Ben Hymers's avatar
Ben Hymers committed
94

95
96
97
        // buffered events, fifo stack
        typedef std::list<MacKeyStackEvent> eventStack;
        eventStack pendingEvents;
Ben Hymers's avatar
Ben Hymers committed
98

99
        bool useRepeat;
Ben Hymers's avatar
Ben Hymers committed
100

101
102
103
    };
}
#endif