/src/ois/includes/mac/MacKeyboard.h

https://bitbucket.org/cabalistic/ogredeps/ · C Header · 102 lines · 43 code · 24 blank · 35 comment · 0 complexity · 27d0b2f872a37d125678bd0f481e5353 MD5 · raw file

  1. /*
  2. The zlib/libpng License
  3. Copyright (c) 2006 Chris Snyder
  4. This software is provided 'as-is', without any express or implied warranty. In no event will
  5. the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose, including commercial
  7. applications, and to alter it and redistribute it freely, subject to the following
  8. restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that
  10. you wrote the original software. If you use this software in a product,
  11. an acknowledgment in the product documentation would be appreciated but is
  12. not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source distribution.
  16. */
  17. #ifndef OIS_MacKeyboard_H
  18. #define OIS_MacKeyboard_H
  19. #include "OISKeyboard.h"
  20. #include "mac/MacHelpers.h"
  21. #include "mac/MacPrereqs.h"
  22. #include <Carbon/Carbon.h>
  23. namespace OIS
  24. {
  25. class MacKeyboard : public Keyboard
  26. {
  27. public:
  28. MacKeyboard( InputManager* creator, bool buffered, bool repeat );
  29. virtual ~MacKeyboard();
  30. // Sets buffered mode
  31. virtual void setBuffered( bool buffered );
  32. // unbuffered keydown check
  33. virtual bool isKeyDown( KeyCode key ) const;
  34. // This will send listener events if buffered is on.
  35. // Note that in the mac implementation, unbuffered input is
  36. // automatically updated without calling this.
  37. virtual void capture();
  38. // Copies the current key buffer
  39. virtual void copyKeyStates( char keys[256] ) const;
  40. // Returns a description of the given key
  41. virtual std::string& getAsString( KeyCode key );
  42. virtual Interface* queryInterface( Interface::IType type ) { return 0; }
  43. // Public but reserved for internal use:
  44. virtual void _initialize();
  45. void _keyDownCallback( EventRef theEvent );
  46. void _keyUpCallback( EventRef theEvent );
  47. void _modChangeCallback( EventRef theEvent );
  48. protected:
  49. // just to get this out of the way
  50. void populateKeyConversion();
  51. // updates the keybuffer and optionally the eventStack
  52. void injectEvent(KeyCode kc, unsigned int time, MacEventType type, unsigned int txt = 0 );
  53. typedef std::map<UInt32, KeyCode> VirtualtoOIS_KeyMap;
  54. VirtualtoOIS_KeyMap keyConversion;
  55. std::string getString;
  56. char KeyBuffer[256];
  57. UInt32 prevModMask;
  58. // "universal procedure pointers" - required reference for callbacks
  59. EventHandlerUPP keyDownUPP;
  60. EventHandlerUPP keyUpUPP;
  61. EventHandlerUPP keyModUPP;
  62. // so we can delete the handlers on destruction
  63. EventHandlerRef keyDownEventRef;
  64. EventHandlerRef keyUpEventRef;
  65. EventHandlerRef keyModEventRef;
  66. // buffered events, fifo stack
  67. typedef std::list<MacKeyStackEvent> eventStack;
  68. eventStack pendingEvents;
  69. bool useRepeat;
  70. };
  71. }
  72. #endif