ScummVM API documentation
key_handler_controller.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program 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 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA4_CONTROLLERS_KEY_HANDLER_CONTROLLER_H
23 #define ULTIMA4_CONTROLLERS_KEY_HANDLER_CONTROLLER_H
24 
25 #include "ultima/ultima4/controllers/controller.h"
26 
27 namespace Ultima {
28 namespace Ultima4 {
29 
33 class KeyHandler {
34 public:
35  virtual ~KeyHandler() {}
36 
37  /* Typedefs */
38  typedef bool (*Callback)(int, void *);
39 
41  typedef struct ReadBuffer {
42  int (*_handleBuffer)(Common::String *);
43  Common::String *_buffer;
44  int _bufferLen;
45  int _screenX, _screenY;
46  } ReadBuffer;
47 
49  typedef struct GetChoice {
50  Common::String _choices;
51  int (*_handleChoice)(int);
52  } GetChoice;
53 
54  /* Constructors */
55  KeyHandler(Callback func, void *data = nullptr, bool asyncronous = true);
56 
62  static bool globalHandler(int key);
63 
64  /* Static default key handler functions */
68  static bool defaultHandler(int key, void *data);
69 
73  static bool ignoreKeys(int key, void *data);
74 
75  /* Operators */
76  bool operator==(Callback cb) const;
77 
78  /* Member functions */
87  bool handle(int key);
88 
92  virtual bool isKeyIgnored(int key);
93 
94 protected:
95  Callback _handler;
96  bool _async;
97  void *_data;
98 };
99 
105 public:
108 
109  bool keyPressed(int key) override;
110  KeyHandler *getKeyHandler();
111 
112 private:
113  KeyHandler *_handler;
114 };
115 
116 } // End of namespace Ultima4
117 } // End of namespace Ultima
118 
119 #endif
Definition: str.h:59
Definition: controller.h:35
struct Ultima::Ultima4::KeyHandler::GetChoice GetChoice
Definition: detection.h:27
static bool globalHandler(int key)
virtual bool isKeyIgnored(int key)
struct Ultima::Ultima4::KeyHandler::ReadBuffer ReadBuffer
Definition: key_handler_controller.h:49
Definition: key_handler_controller.h:33
static bool ignoreKeys(int key, void *data)
Definition: key_handler_controller.h:104
Definition: key_handler_controller.h:41
static bool defaultHandler(int key, void *data)