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 
28 public:
29  virtual void touchControlNotifyChanged() = 0;
30  virtual void touchControlDraw(int16 x, int16 y, int16 w, int16 h, const Common::Rect &clip) = 0;
31 
32 protected:
34 };
35 
37 public:
38  // action type
39  enum Action {
40  JACTION_DOWN = 0,
41  JACTION_MOVE = 1,
42  JACTION_UP = 2,
43  JACTION_CANCEL = 3
44  };
45 
46  TouchControls();
47 
48  void init(TouchControlsDrawer *drawer, int width, int height);
49  void draw();
50  void update(Action action, int ptr, int x, int y);
51 
52 private:
53  TouchControlsDrawer *_drawer;
54 
55  int _screen_width, _screen_height;
56 
57  enum Function {
58  kFunctionNone = -1,
59  kFunctionJoystick = 0,
60  kFunctionCenter = 1,
61  kFunctionRight = 2,
62  kFunctionMax = 2
63  };
64  Function getFunction(int x, int y);
65 
66  struct Pointer {
67  Pointer() : id(-1), startX(-1), startY(-1),
68  currentX(-1), currentY(-1),
69  function(kFunctionNone), active(false) {}
70  void reset() {
71  id = -1;
72  startX = startY = currentX = currentY = -1;
73  function = kFunctionNone;
74  active = false;
75  }
76 
77  int id;
78  uint16 startX, startY;
79  uint16 currentX, currentY;
80  Function function;
81  bool active;
82  };
83 
84  enum { kNumPointers = 5 };
85  Pointer _pointers[kNumPointers];
86 
87  Pointer *getPointerFromId(int ptr, bool createNotFound);
88  Pointer *findPointerFromFunction(Function function);
89 
90  struct FunctionState {
91  FunctionState() : main(Common::JOYSTICK_BUTTON_INVALID),
92  modifier(Common::JOYSTICK_BUTTON_INVALID) {}
93  void reset() {
94  main = Common::JOYSTICK_BUTTON_INVALID;
95  modifier = Common::JOYSTICK_BUTTON_INVALID;
96  clip = Common::Rect();
97  }
98 
100  Common::JoystickButton modifier;
101  Common::Rect clip;
102  };
103 
104  FunctionState _functionStates[kFunctionMax + 1];
105 
106  void buttonDown(Common::JoystickButton jb);
107  void buttonUp(Common::JoystickButton jb);
108  void buttonPress(Common::JoystickButton jb);
109 
110  /* Functions implementations */
111  struct FunctionBehavior {
112  void (*touchToState)(int, int, TouchControls::FunctionState &);
113  bool pressOnRelease;
114  float xRatio;
115  float yRatio;
116  };
117  static FunctionBehavior functionBehaviors[TouchControls::kFunctionMax + 1];
118 
119  static void touchToJoystickState(int dX, int dY, FunctionState &state);
120  static void touchToCenterState(int dX, int dY, FunctionState &state);
121  static void touchToRightState(int dX, int dY, FunctionState &state);
122 };
123 
124 #endif
Definition: rect.h:144
Definition: touchcontrols.h:36
Definition: touchcontrols.h:27
JoystickButton
Definition: events.h:146