ScummVM API documentation
mouse.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 ULTIMA8_KERNEL_MOUSE_H
23 #define ULTIMA8_KERNEL_MOUSE_H
24 
25 #include "common/rect.h"
26 #include "common/stack.h"
27 #include "common/scummsys.h"
28 
29 #include "ultima/ultima8/misc/common_types.h"
30 #include "ultima/ultima8/misc/direction.h"
31 
32 namespace Ultima {
33 namespace Ultima8 {
34 
35 enum MouseButtonState {
36  MBS_DOWN = 0x1,
37  MBS_HANDLED = 0x2 // Mousedown event handled
38 };
39 
40 struct MButton {
41  uint16 _downGump;
42  uint32 _lastDown;
43  uint32 _curDown;
44  Common::Point _downPoint;
45  int _state;
46 
47  MButton() : _downGump(0), _curDown(0), _lastDown(0), _state(MBS_HANDLED)
48  {
49  }
50 
51  bool isState(MouseButtonState state) const {
52  return _state & state;
53  }
54  void setState(MouseButtonState state) {
55  _state |= state;
56  }
57  void clearState(MouseButtonState state) {
58  _state &= ~state;
59  }
60 
62  bool isUnhandledPastTimeout(uint32 now, uint32 timeout) {
63  return !isState(MBS_HANDLED) && _curDown > 0 && (now - _curDown) > timeout;
64  }
65 
67  bool isUnhandledDoubleClick(uint32 timeout) {
68  return !isState(MBS_HANDLED) && _lastDown > 0 && (_curDown - _lastDown) <= timeout;
69  }
70 
71 };
72 
73 class Gump;
74 
75 class Mouse {
76 public:
77  enum MouseButton {
78  BUTTON_NONE = 0,
79  BUTTON_LEFT = 1,
80  BUTTON_RIGHT = 2,
81  BUTTON_MIDDLE = 3,
82  MOUSE_LAST
83  };
84 
85  enum MouseCursor {
86  MOUSE_NORMAL = 0,
87  MOUSE_NONE = 1,
88  MOUSE_TARGET = 2,
89  MOUSE_WAIT = 3,
90  MOUSE_HAND = 4,
91  MOUSE_QUILL = 5,
92  MOUSE_MAGGLASS = 6,
93  MOUSE_CROSS = 7
94  };
95 
96  enum DraggingState {
97  DRAG_NOT = 0,
98  DRAG_OK = 1,
99  DRAG_INVALID = 2,
100  DRAG_TEMPFAIL = 3
101  };
102 private:
103  static Mouse *_instance;
105  int _lastMouseFrame;
106 
110  uint32 _flashingCursorTime;
111 
112  // mouse input state
113  MButton _mouseButton[MOUSE_LAST];
114 
115  uint16 _mouseOverGump;
116  Common::Point _mousePos;
117  Common::Point _draggingOffset;
118  DraggingState _dragging;
119 
120  ObjId _dragging_objId;
121  uint16 _draggingItem_startGump;
122  uint16 _draggingItem_lastGump;
123 
124  int _walkThreshold;
125  int _runThreshold;
126 private:
127  void startDragging(int mx, int my);
128  void moveDragging(int mx, int my);
129  void stopDragging(int mx, int my);
130  int mouseFrameForDir(Direction mousedir) const;
131 
132 public:
133  static Mouse *get_instance() { return _instance; }
134 public:
135  Mouse();
136  ~Mouse();
137 
141  bool buttonDown(MouseButton button);
142 
146  bool buttonUp(MouseButton button);
147 
149  int getMouseLength(int mx, int my) const;
150 
152  int getMouseLength() const {
153  return getMouseLength(_mousePos.x, _mousePos.y);
154  }
155 
157  Direction getMouseDirectionScreen(int mx, int my) const;
158 
160  Direction getMouseDirectionScreen() const {
161  return getMouseDirectionScreen(_mousePos.x, _mousePos.y);
162  }
163 
165  Direction getMouseDirectionWorld(int mx, int my) const;
166 
168  Direction getMouseDirectionWorld() const {
169  return getMouseDirectionWorld(_mousePos.x, _mousePos.y);
170  }
171 
173  void getMouseCoords(int32 &mx, int32 &my) const {
174  mx = _mousePos.x;
175  my = _mousePos.y;
176  }
177 
179  void setMouseCoords(int mx, int my);
180 
181  bool isMouseDownEvent(MouseButton button) const;
182 
184  void popAllCursors();
185 
187  void setMouseCursor(MouseCursor cursor);
188 
190  void flashCrossCursor();
191 
193  void pushMouseCursor(MouseCursor cursor);
194 
196  void popMouseCursor();
197 
199  int getMouseFrame();
200 
201  DraggingState dragging() const { return _dragging; }
202 
203  void setDraggingOffset(int32 x, int32 y) {
204  _draggingOffset.x = x;
205  _draggingOffset.y = y;
206  }
207  void getDraggingOffset(int32 &x, int32 &y) {
208  x = _draggingOffset.x;
209  y = _draggingOffset.y;
210  }
211 
212  uint32 getDoubleClickTime() const;
213 
214  void handleDelayedEvents();
215 
216  Gump *getMouseOverGump() const;
217  void resetMouseOverGump() { _mouseOverGump = 0; }
218 
219  void update();
220 };
221 
222 } // End of namespace Ultima8
223 } // End of namespace Ultima
224 
225 #endif
bool isUnhandledPastTimeout(uint32 now, uint32 timeout)
True if the current state is unhandled and past the double click timeout.
Definition: mouse.h:62
Direction getMouseDirectionScreen() const
get mouse cursor direction on the screen using the current coordinates.
Definition: mouse.h:160
Definition: gump.h:46
int getMouseLength() const
get mouse cursor length for the current coordinates
Definition: mouse.h:152
Definition: detection.h:27
T y
Definition: rect.h:49
void getMouseCoords(int32 &mx, int32 &my) const
get current mouse cursor location
Definition: mouse.h:173
T x
Definition: rect.h:48
Definition: rect.h:144
bool isUnhandledDoubleClick(uint32 timeout)
True if the current state is unhandled and within the double click timeout.
Definition: mouse.h:67
Direction getMouseDirectionWorld() const
get mouse cursor direction in the world using the current coordinates.
Definition: mouse.h:168
Definition: mouse.h:75
Definition: mouse.h:40