ScummVM API documentation
touchcontrols.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 ANDROID_TOUCHCONTROLS_H_
23 #define ANDROID_TOUCHCONTROLS_H_
24 
25 #include "common/events.h"
26 
27 namespace Graphics {
28 class ManagedSurface;
29 }
30 
32 public:
33  virtual void touchControlInitSurface(const Graphics::ManagedSurface &surf) = 0;
34  virtual void touchControlNotifyChanged() = 0;
35  virtual void touchControlDraw(uint8 alpha, int16 x, int16 y, int16 w, int16 h, const Common::Rect &clip) = 0;
36 
37 protected:
39 };
40 
42 public:
43  // action type
44  enum Action {
45  JACTION_DOWN = 0,
46  JACTION_MOVE = 1,
47  JACTION_UP = 2,
48  JACTION_CANCEL = 3
49  };
50 
51  TouchControls();
52  ~TouchControls();
53 
54  void init(float scale);
55  void setDrawer(TouchControlsDrawer *drawer, int width, int height);
56  void beforeDraw();
57  void draw();
58  void update(Action action, int ptr, int x, int y);
59 
60 private:
61  TouchControlsDrawer *_drawer;
62 
63  unsigned int _screen_width, _screen_height;
64  unsigned int _scale, _scale2;
65 
67 
68  unsigned int _zombieCount;
69 
70  enum State {
71  kFunctionInactive = 0,
72  kFunctionActive = 1,
73  kFunctionZombie = 2
74  };
75 
76  struct Function {
77  virtual bool isInside(int, int) = 0;
78  virtual void touch(int, int, Action) = 0;
79  virtual void draw(uint8 alpha) = 0;
80  virtual void resetState() {}
81 
82  Function(const TouchControls *parent_) :
83  parent(parent_), pointerId(-1),
84  startX(-1), startY(-1),
85  currentX(-1), currentY(-1),
86  lastActivable(0), status(kFunctionInactive) {}
87  virtual ~Function() {}
88 
89  void reset() {
90  pointerId = -1;
91  startX = startY = currentX = currentY = -1;
92  lastActivable = 0;
93  status = kFunctionInactive;
94  resetState();
95  }
96 
97  const TouchControls *parent;
98 
99  int pointerId;
100  uint16 startX, startY;
101  uint16 currentX, currentY;
102  uint32 lastActivable;
103  State status;
104  };
105  Function *getFunctionFromPointerId(int ptr);
106  Function *getZombieFunctionFromPos(int x, int y);
107 
108  enum FunctionId {
109  kFunctionNone = -1,
110  kFunctionLeft = 0,
111  kFunctionRight = 1,
112  kFunctionCenter = 2,
113  kFunctionCount = 3
114  };
115  FunctionId getFunctionId(int x, int y);
116 
117  Function *_functions[kFunctionCount];
118 
119  static void buttonDown(Common::JoystickButton jb);
120  static void buttonUp(Common::JoystickButton jb);
121  static void buttonPress(Common::JoystickButton jb);
122 
132  void drawSurface(uint8 alpha, int x, int y, int offX, int offY, const Common::Rect &clip) const;
133 
134 
135  // Functions implementations
136  struct FunctionLeft : Function {
137  FunctionLeft(const TouchControls *parent) :
138  Function(parent), mask(0) {}
139  void resetState() override { mask = 0; }
140 
141  bool isInside(int, int) override;
142  void touch(int, int, Action) override;
143  void draw(uint8 alpha) override;
144 
145  uint32 mask;
146  void maskToLeftButtons(uint32 oldMask, uint32 newMask);
147  };
148 
149  struct FunctionRight : Function {
150  FunctionRight(const TouchControls *parent) :
151  Function(parent), button(0) {}
152  void resetState() override { button = 0; }
153 
154  bool isInside(int, int) override;
155  void touch(int, int, Action) override;
156  void draw(uint8 alpha) override;
157 
158  uint32 button;
159  };
160 
161  struct FunctionCenter : Function {
162  FunctionCenter(const TouchControls *parent) :
163  Function(parent), button(0) {}
164  void resetState() override { button = 0; }
165 
166  bool isInside(int, int) override;
167  void touch(int, int, Action) override;
168  void draw(uint8 alpha) override;
169 
170  uint32 button;
171  };
172 };
173 
174 #endif
Definition: managed_surface.h:51
Definition: rect.h:144
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: formatinfo.h:28
Definition: touchcontrols.h:41
Definition: touchcontrols.h:31
JoystickButton
Definition: events.h:146