1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ANDROID_TOUCHCONTROLS_H_
#define ANDROID_TOUCHCONTROLS_H_
#include "common/events.h"
namespace Graphics {
class ManagedSurface;
}
class TouchControlsDrawer {
public:
virtual void touchControlInitSurface(const Graphics::ManagedSurface &surf) = 0;
virtual void touchControlNotifyChanged() = 0;
virtual void touchControlDraw(uint8 alpha, int16 x, int16 y, int16 w, int16 h, const Common::Rect &clip) = 0;
protected:
~TouchControlsDrawer() {}
};
class TouchControls {
public:
// action type
enum Action {
JACTION_DOWN = 0,
JACTION_MOVE = 1,
JACTION_UP = 2,
JACTION_CANCEL = 3
};
TouchControls();
~TouchControls();
void init(float scale);
void setDrawer(TouchControlsDrawer *drawer, int width, int height);
void beforeDraw();
void draw();
void update(Action action, int ptr, int x, int y);
private:
TouchControlsDrawer *_drawer;
unsigned int _screen_width, _screen_height;
unsigned int _scale, _scale2;
Graphics::ManagedSurface *_svg;
unsigned int _zombieCount;
enum State {
kFunctionInactive = 0,
kFunctionActive = 1,
kFunctionZombie = 2
};
struct Function {
virtual bool isInside(int, int) = 0;
virtual void touch(int, int, Action) = 0;
virtual void draw(uint8 alpha) = 0;
virtual void resetState() {}
Function(const TouchControls *parent_) :
parent(parent_), pointerId(-1),
startX(-1), startY(-1),
currentX(-1), currentY(-1),
lastActivable(0), status(kFunctionInactive) {}
virtual ~Function() {}
void reset() {
pointerId = -1;
startX = startY = currentX = currentY = -1;
lastActivable = 0;
status = kFunctionInactive;
resetState();
}
const TouchControls *parent;
int pointerId;
uint16 startX, startY;
uint16 currentX, currentY;
uint32 lastActivable;
State status;
};
Function *getFunctionFromPointerId(int ptr);
Function *getZombieFunctionFromPos(int x, int y);
enum FunctionId {
kFunctionNone = -1,
kFunctionLeft = 0,
kFunctionRight = 1,
kFunctionCenter = 2,
kFunctionCount = 3
};
FunctionId getFunctionId(int x, int y);
Function *_functions[kFunctionCount];
static void buttonDown(Common::JoystickButton jb);
static void buttonUp(Common::JoystickButton jb);
static void buttonPress(Common::JoystickButton jb);
/**
* Draws a part of the joystick surface on the screen
*
* @param x The left coordinate in fixed-point screen pixels
* @param y The top coordinate in fixed-point screen pixels
* @param offX The left offset in SVG pixels
* @param offY The top offset in SVG pixels
* @param clip The clipping rectangle in source surface in SVG pixels
*/
void drawSurface(uint8 alpha, int x, int y, int offX, int offY, const Common::Rect &clip) const;
// Functions implementations
struct FunctionLeft : Function {
FunctionLeft(const TouchControls *parent) :
Function(parent), mask(0) {}
void resetState() override { mask = 0; }
bool isInside(int, int) override;
void touch(int, int, Action) override;
void draw(uint8 alpha) override;
uint32 mask;
void maskToLeftButtons(uint32 oldMask, uint32 newMask);
};
struct FunctionRight : Function {
FunctionRight(const TouchControls *parent) :
Function(parent), button(0) {}
void resetState() override { button = 0; }
bool isInside(int, int) override;
void touch(int, int, Action) override;
void draw(uint8 alpha) override;
uint32 button;
};
struct FunctionCenter : Function {
FunctionCenter(const TouchControls *parent) :
Function(parent), button(0) {}
void resetState() override { button = 0; }
bool isInside(int, int) override;
void touch(int, int, Action) override;
void draw(uint8 alpha) override;
uint32 button;
};
};
#endif
|