ScummVM API documentation
message.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 BURIED_MESSAGE_H
23 #define BURIED_MESSAGE_H
24 
25 #include "common/keyboard.h"
26 #include "common/rect.h"
27 
28 namespace Buried {
29 
30 // This is all based on the Windows messaging system
31 // ...but less stupid
32 
33 class Window;
34 
35 enum MessageType {
36  // Actual message types
37  kMessageTypeKeyUp,
38  kMessageTypeKeyDown,
39  kMessageTypeTimer,
40  kMessageTypeMouseMove,
41  kMessageTypeLButtonUp,
42  kMessageTypeLButtonDown,
43  kMessageTypeMButtonUp,
44  kMessageTypeRButtonUp,
45  kMessageTypeRButtonDown,
46  kMessageTypeSetCursor,
47  kMessageTypeEnable,
48 
49  // Ranges of messages
50  kMessageTypeMouseBegin = kMessageTypeMouseMove,
51  kMessageTypeMouseEnd = kMessageTypeRButtonDown,
52  kMessageTypeKeyBegin = kMessageTypeKeyUp,
53  kMessageTypeKeyEnd = kMessageTypeKeyDown
54 };
55 
56 
57 class Message {
58 public:
59  virtual ~Message() {}
60 
61  virtual MessageType getMessageType() const = 0;
62 };
63 
64 // Templated version to make stuff a bit neater
65 template <MessageType type>
66 class MessageTypeIntern : public Message {
67 public:
68  MessageType getMessageType() const { return type; }
69 };
70 
71 // Some common template classes
72 template <MessageType type>
73 class MouseMessage : public MessageTypeIntern<type> {
74 public:
75  MouseMessage(const Common::Point &point, uint flags) : _point(point), _flags(flags) {}
76 
77  Common::Point getPoint() const { return _point; }
78  uint getFlags() const { return _flags; }
79 
80 private:
81  Common::Point _point;
82  uint _flags;
83 };
84 
85 template <MessageType type>
86 class KeyMessage : public MessageTypeIntern<type> {
87 public:
88  KeyMessage(const Common::KeyState &keyState, uint flags) : _keyState(keyState), _flags(flags) {}
89 
90  Common::KeyState getKeyState() const { return _keyState; }
91  uint getFlags() const { return _flags; }
92 
93 private:
94  Common::KeyState _keyState;
95  uint _flags;
96 };
97 
98 // Types for everything that falls under one of the above categories
107 
108 // ...and the rest
109 class SetCursorMessage : public MessageTypeIntern<kMessageTypeSetCursor> {
110 public:
111  // Hit-test is purposely skipped
112  SetCursorMessage(uint message) : _message(message) {}
113 
114  uint getMessage() const { return _message; }
115 
116 private:
117  uint _message;
118 };
119 
120 class TimerMessage : public MessageTypeIntern<kMessageTypeTimer> {
121 public:
122  TimerMessage(uint timer) : _timer(timer) {}
123 
124  uint getTimer() const { return _timer; }
125 
126 private:
127  uint _timer;
128 };
129 
130 class EnableMessage : public MessageTypeIntern<kMessageTypeEnable> {
131 public:
132  EnableMessage(bool enable) : _enable(enable) {}
133 
134  bool getEnable() const { return _enable; }
135 
136 private:
137  bool _enable;
138 };
139 
140 } // End of namespace Buried
141 
142 #endif
Definition: message.h:120
Definition: message.h:66
Definition: message.h:130
Definition: message.h:109
Definition: message.h:73
Definition: message.h:57
Definition: agent_evaluation.h:31
Definition: rect.h:45
Definition: keyboard.h:294
Definition: message.h:86