forked from Kolyah35/minecraft-pe-0.6.1
the whole game
This commit is contained in:
75
src/platform/input/Controller.cpp
Executable file
75
src/platform/input/Controller.cpp
Executable file
@@ -0,0 +1,75 @@
|
||||
#include "Controller.h"
|
||||
|
||||
static int _abs(int x) { return x>=0? x:-x; }
|
||||
static float _abs(float x) { return x>=0? x:-x; }
|
||||
|
||||
/*static*/ float Controller::stickValuesX[NUM_STICKS] = {0};
|
||||
/*static*/ float Controller::stickValuesY[NUM_STICKS] = {0};
|
||||
/*static*/ bool Controller::isTouchedValues[NUM_STICKS] = {0};
|
||||
|
||||
bool Controller::isTouched( int stickIndex )
|
||||
{
|
||||
if (!isValidStick(stickIndex)) return false;
|
||||
|
||||
return isTouchedValues[stickIndex-1];
|
||||
}
|
||||
|
||||
void Controller::feed( int stickIndex, int state, float dx, float dy )
|
||||
{
|
||||
if (!isValidStick(stickIndex)) return;
|
||||
|
||||
if (NUM_STICKS == 2)
|
||||
stickIndex = dx<0? 1 : 2;
|
||||
|
||||
isTouchedValues[stickIndex-1] = (state != STATE_RELEASE);
|
||||
|
||||
// @note: Since I don't know where to put the Xperia Play specific
|
||||
// calculations, I put them here! (normally I would probably have
|
||||
// some kind of (XperiaPlay)ControllerReader but it doesn't make much
|
||||
// more sense as long as we cant figure out (in code) whether or not
|
||||
// we actually use an Xperia -> hardcode it here (Note#2, we CAN figure
|
||||
// figure this out, at least by JNI/java-call but we arent doing it)
|
||||
static float offsets[3] = {0, 0.64f, -0.64f};
|
||||
dx = linearTransform(dx + offsets[stickIndex], 0, 2.78f, true);
|
||||
|
||||
stickValuesX[stickIndex-1] = dx;
|
||||
stickValuesY[stickIndex-1] = dy;
|
||||
}
|
||||
|
||||
float Controller::getX( int stickIndex )
|
||||
{
|
||||
if (!isValidStick(stickIndex)) return 0;
|
||||
return stickValuesX[stickIndex-1];
|
||||
}
|
||||
|
||||
float Controller::getY( int stickIndex )
|
||||
{
|
||||
if (!isValidStick(stickIndex)) return 0;
|
||||
return stickValuesY[stickIndex-1];
|
||||
}
|
||||
|
||||
float Controller::getTransformedX( int stickIndex, float deadZone, float scale/*=1.0f*/, bool limit1/*=false*/ )
|
||||
{
|
||||
if (!isValidStick(stickIndex)) return 0;
|
||||
return linearTransform(stickValuesX[stickIndex-1], deadZone, scale, limit1);
|
||||
}
|
||||
|
||||
float Controller::getTransformedY( int stickIndex, float deadZone, float scale/*=1.0f*/, bool limit1/*=false*/ )
|
||||
{
|
||||
if (!isValidStick(stickIndex)) return 0;
|
||||
return linearTransform(stickValuesY[stickIndex-1], deadZone, scale, limit1);
|
||||
}
|
||||
|
||||
float Controller::linearTransform( float value, float deadZone, float scale/*=1.0f*/, bool limit1/*=false*/ )
|
||||
{
|
||||
float deadSigned = value >= 0? deadZone : -deadZone;
|
||||
if (_abs(deadSigned) >= _abs(value)) return 0;
|
||||
float ret = (value - deadSigned) * scale;
|
||||
if (limit1 && _abs(ret) > 1) ret = ret>0.0f? 1.0f : -1.0f;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*static*/
|
||||
bool Controller::isValidStick(int stick) {
|
||||
return stick > 0 && stick <= NUM_STICKS;
|
||||
}
|
||||
33
src/platform/input/Controller.h
Executable file
33
src/platform/input/Controller.h
Executable file
@@ -0,0 +1,33 @@
|
||||
#ifndef CONTROLLER_H__
|
||||
#define CONTROLLER_H__
|
||||
|
||||
#include "../log.h"
|
||||
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
static const int NUM_STICKS = 2;
|
||||
static const int STATE_TOUCH = 1;
|
||||
static const int STATE_RELEASE = 0;
|
||||
static const int STATE_MOVE =-1;
|
||||
|
||||
static bool isTouched(int stickIndex);
|
||||
|
||||
static void feed(int stickIndex, int state, float dx, float dy);
|
||||
|
||||
static float getX(int stickIndex);
|
||||
static float getY(int stickIndex);
|
||||
|
||||
static float getTransformedX(int stickIndex, float deadZone, float scale=1.0f, bool limit1=false);
|
||||
static float getTransformedY(int stickIndex, float deadZone, float scale=1.0f, bool limit1=false);
|
||||
|
||||
private:
|
||||
static bool isValidStick(int stick);
|
||||
static float linearTransform(float value, float deadZone, float scale=1.0f, bool limit1=false);
|
||||
|
||||
static float stickValuesX[NUM_STICKS];
|
||||
static float stickValuesY[NUM_STICKS];
|
||||
static bool isTouchedValues[NUM_STICKS];
|
||||
};
|
||||
|
||||
#endif /*CONTROLLER_H__*/
|
||||
20
src/platform/input/Keyboard.cpp
Executable file
20
src/platform/input/Keyboard.cpp
Executable file
@@ -0,0 +1,20 @@
|
||||
#include "Keyboard.h"
|
||||
|
||||
/*
|
||||
const int KeyboardAction::KEYUP = 0;
|
||||
const int KeyboardAction::KEYDOWN = 1;
|
||||
*/
|
||||
|
||||
int
|
||||
Keyboard::_states[256] = {0};
|
||||
|
||||
std::vector<KeyboardAction>
|
||||
Keyboard::_inputs;
|
||||
std::vector<char>
|
||||
Keyboard::_inputText;
|
||||
|
||||
int
|
||||
Keyboard::_index = -1;
|
||||
|
||||
int
|
||||
Keyboard::_textIndex = -1;
|
||||
137
src/platform/input/Keyboard.h
Executable file
137
src/platform/input/Keyboard.h
Executable file
@@ -0,0 +1,137 @@
|
||||
#ifndef KEYBOARD_H__
|
||||
#define KEYBOARD_H__
|
||||
|
||||
#include <vector>
|
||||
|
||||
/** A keyboard action; key-down or key-up */
|
||||
class KeyboardAction
|
||||
{
|
||||
public:
|
||||
static const int KEYUP = 0;
|
||||
static const int KEYDOWN = 1;
|
||||
|
||||
KeyboardAction(unsigned char keyCode, int state) {
|
||||
this->key = keyCode;
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
int state;
|
||||
unsigned char key;
|
||||
};
|
||||
|
||||
/* Iterators */
|
||||
typedef std::vector<KeyboardAction> KeyboardActionVec;
|
||||
typedef KeyboardActionVec::iterator KeyboardActionIt;
|
||||
typedef KeyboardActionVec::const_iterator KeyboardActionCIt;
|
||||
|
||||
/** A static keyboard class, written to resemble the one in lwjgl somewhat */
|
||||
class Keyboard
|
||||
{
|
||||
public:
|
||||
static const int KEY_A = 65;
|
||||
static const int KEY_B = 66;
|
||||
static const int KEY_C = 67;
|
||||
static const int KEY_D = 68;
|
||||
static const int KEY_E = 69;
|
||||
static const int KEY_F = 70;
|
||||
static const int KEY_G = 71;
|
||||
static const int KEY_H = 72;
|
||||
static const int KEY_I = 73;
|
||||
static const int KEY_J = 74;
|
||||
static const int KEY_K = 75;
|
||||
static const int KEY_L = 76;
|
||||
static const int KEY_M = 77;
|
||||
static const int KEY_N = 78;
|
||||
static const int KEY_O = 79;
|
||||
static const int KEY_P = 80;
|
||||
static const int KEY_Q = 81;
|
||||
static const int KEY_R = 82;
|
||||
static const int KEY_S = 83;
|
||||
static const int KEY_T = 84;
|
||||
static const int KEY_U = 85;
|
||||
static const int KEY_V = 86;
|
||||
static const int KEY_W = 87;
|
||||
static const int KEY_X = 88;
|
||||
static const int KEY_Y = 89;
|
||||
static const int KEY_Z = 90;
|
||||
|
||||
static const int KEY_BACKSPACE = 8;
|
||||
static const int KEY_RETURN = 13;
|
||||
|
||||
static const int KEY_F1 = 112;
|
||||
static const int KEY_F2 = 113;
|
||||
static const int KEY_F3 = 114;
|
||||
static const int KEY_F4 = 115;
|
||||
static const int KEY_F5 = 116;
|
||||
static const int KEY_F6 = 117;
|
||||
static const int KEY_F7 = 118;
|
||||
static const int KEY_F8 = 119;
|
||||
static const int KEY_F9 = 120;
|
||||
static const int KEY_F10 = 121;
|
||||
static const int KEY_F11 = 122;
|
||||
static const int KEY_F12 = 123;
|
||||
|
||||
static const int KEY_ESCAPE = 27;
|
||||
static const int KEY_SPACE = 32;
|
||||
static const int KEY_LSHIFT = 10;
|
||||
|
||||
static bool isKeyDown(int keyCode) {
|
||||
return _states[keyCode] == KeyboardAction::KEYDOWN;
|
||||
}
|
||||
|
||||
static void reset() {
|
||||
_inputs.clear();
|
||||
_inputText.clear();
|
||||
_index = -1;
|
||||
_textIndex = -1;
|
||||
}
|
||||
|
||||
static void feed(unsigned char keyCode, int state) {
|
||||
_inputs.push_back(KeyboardAction(keyCode, state));
|
||||
|
||||
_states[keyCode] = state;
|
||||
}
|
||||
static void feedText(char character) {
|
||||
_inputText.push_back(character);
|
||||
}
|
||||
|
||||
static bool next() {
|
||||
if (_index + 1 >= (int)_inputs.size())
|
||||
return false;
|
||||
|
||||
++_index;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool nextTextChar() {
|
||||
if(_textIndex + 1 >= (int)_inputText.size())
|
||||
return false;
|
||||
++_textIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void rewind() {
|
||||
_index = -1;
|
||||
_textIndex = -1;
|
||||
}
|
||||
|
||||
static int getEventKey() {
|
||||
return _inputs[_index].key;
|
||||
}
|
||||
|
||||
static int getEventKeyState() {
|
||||
return _inputs[_index].state;
|
||||
}
|
||||
static char getChar() {
|
||||
return _inputText[_textIndex];
|
||||
}
|
||||
private:
|
||||
static int _index;
|
||||
static int _textIndex;
|
||||
static int _states[256];
|
||||
static std::vector<KeyboardAction> _inputs;
|
||||
static std::vector<char> _inputText;
|
||||
static bool _inited;
|
||||
};
|
||||
|
||||
#endif//KEYBOARD_H__
|
||||
169
src/platform/input/Mouse.cpp
Executable file
169
src/platform/input/Mouse.cpp
Executable file
@@ -0,0 +1,169 @@
|
||||
#include "Mouse.h"
|
||||
|
||||
//
|
||||
// MouseAction
|
||||
//
|
||||
MouseAction::MouseAction(char actionButtonId, char buttonData, short x, short y, char pointerId)
|
||||
{
|
||||
this->action = actionButtonId;
|
||||
this->data = buttonData;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->dx = this->dy = 0;
|
||||
this->pointerId = pointerId;
|
||||
}
|
||||
|
||||
MouseAction::MouseAction(char actionButtonId, char buttonData, short x, short y, short dx, short dy, char pointerId)
|
||||
{
|
||||
this->action = actionButtonId;
|
||||
this->data = buttonData;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->dx = dx;
|
||||
this->dy = dy;
|
||||
this->pointerId = pointerId;
|
||||
}
|
||||
|
||||
bool MouseAction::isButton() const
|
||||
{
|
||||
return action == ACTION_LEFT || action == ACTION_RIGHT;
|
||||
}
|
||||
|
||||
//
|
||||
// MouseDevice
|
||||
//
|
||||
MouseDevice::MouseDevice()
|
||||
: _index(-1),
|
||||
_x(0), _xOld(0),
|
||||
_y(0), _yOld(0),
|
||||
_dx(DELTA_NOTSET), _dy(DELTA_NOTSET),
|
||||
_firstMovementType(0)
|
||||
{
|
||||
for (int i = 0; i < MAX_NUM_BUTTONS; ++i)
|
||||
_buttonStates[i] = 0;
|
||||
}
|
||||
|
||||
void MouseDevice::reset() {
|
||||
_index = -1;
|
||||
_inputs.clear();
|
||||
_buttonStates[MouseAction::ACTION_WHEEL] = 0;
|
||||
}
|
||||
|
||||
char MouseDevice::getButtonState(int buttonId) {
|
||||
if (buttonId < MouseAction::ACTION_LEFT || buttonId > MouseAction::ACTION_WHEEL)
|
||||
return 0;
|
||||
return _buttonStates[buttonId];
|
||||
}
|
||||
|
||||
bool MouseDevice::isButtonDown(int buttonId) {
|
||||
return getButtonState(buttonId) != 0;
|
||||
}
|
||||
|
||||
/// Was the current movement the first movement after mouse down?
|
||||
bool MouseDevice::wasFirstMovement() {
|
||||
return _firstMovementType == 1;
|
||||
}
|
||||
|
||||
short MouseDevice::getX() { return _x; }
|
||||
short MouseDevice::getY() { return _y; }
|
||||
|
||||
short MouseDevice::getDX() { return (DELTA_NOTSET != _dx)? _dx : _x - _xOld; }
|
||||
short MouseDevice::getDY() { return (DELTA_NOTSET != _dy)? _dy : _y - _yOld; }
|
||||
|
||||
void MouseDevice::reset2() {
|
||||
_xOld = _x;
|
||||
_yOld = _y;
|
||||
_dx = _dy = DELTA_NOTSET;
|
||||
}
|
||||
|
||||
bool MouseDevice::next() {
|
||||
if (_index + 1 >= (int)_inputs.size())
|
||||
return false;
|
||||
|
||||
++_index;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MouseDevice::rewind() {
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
bool MouseDevice::getEventButtonState() {
|
||||
return _inputs[_index].data == MouseAction::DATA_DOWN;
|
||||
}
|
||||
|
||||
char MouseDevice::getEventButton() {
|
||||
return _inputs[_index].action;
|
||||
}
|
||||
|
||||
const MouseAction& MouseDevice::getEvent() { return _inputs[_index]; }
|
||||
|
||||
void MouseDevice::feed(char actionButtonId, char buttonData, short x, short y) {
|
||||
feed(actionButtonId, buttonData, x, y, 0, 0);
|
||||
}
|
||||
|
||||
void MouseDevice::feed(char actionButtonId, char buttonData, short x, short y, short dx, short dy) {
|
||||
|
||||
_inputs.push_back(MouseAction(actionButtonId, buttonData, x, y, dx, dy, 0));
|
||||
|
||||
if (actionButtonId != MouseAction::ACTION_MOVE) {
|
||||
_buttonStates[actionButtonId] = buttonData;
|
||||
|
||||
if (actionButtonId == MouseAction::ACTION_LEFT)
|
||||
_firstMovementType = -1;
|
||||
} else {
|
||||
if (_dx == DELTA_NOTSET) {
|
||||
_dx = _dy = 0;
|
||||
}
|
||||
_dx += dx;
|
||||
_dy += dy;
|
||||
|
||||
if (_firstMovementType == -1)
|
||||
_firstMovementType = 1;
|
||||
else
|
||||
_firstMovementType = 0;
|
||||
}
|
||||
|
||||
_xOld = _x;
|
||||
_yOld = _y;
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
//
|
||||
// Mouse - static class wrapping a MouseDevice
|
||||
//
|
||||
void Mouse::reset() { _instance.reset(); }
|
||||
|
||||
char Mouse::getButtonState(int buttonId) { return _instance.getButtonState(buttonId); }
|
||||
|
||||
bool Mouse::isButtonDown(int buttonId) { return _instance.isButtonDown(buttonId); }
|
||||
|
||||
short Mouse::getX() { return _instance.getX(); }
|
||||
short Mouse::getY() { return _instance.getY(); }
|
||||
|
||||
short Mouse::getDX() { return _instance.getDX(); }
|
||||
short Mouse::getDY() { return _instance.getDY(); }
|
||||
|
||||
void Mouse::reset2() { _instance.reset2(); }
|
||||
|
||||
bool Mouse::next() { return _instance.next(); }
|
||||
void Mouse::rewind() { _instance.rewind(); }
|
||||
|
||||
bool Mouse::getEventButtonState() { return _instance.getEventButtonState(); }
|
||||
|
||||
char Mouse::getEventButton() { return _instance.getEventButton(); }
|
||||
|
||||
const MouseAction& Mouse::getEvent() { return _instance.getEvent(); }
|
||||
|
||||
void Mouse::feed(char actionButtonId, char buttonData, short x, short y) {
|
||||
feed(actionButtonId, buttonData, x, y, 0, 0);
|
||||
}
|
||||
void Mouse::feed(char actionButtonId, char buttonData, short x, short y, short dx, short dy) {
|
||||
//LOGI("Mouse::feed: %d, %d, xy: %d, %d\n", actionButtonId, buttonData, x, y);
|
||||
return _instance.feed(actionButtonId, buttonData, x, y, dx, dy);
|
||||
}
|
||||
|
||||
|
||||
MouseDevice Mouse::_instance;
|
||||
|
||||
112
src/platform/input/Mouse.h
Executable file
112
src/platform/input/Mouse.h
Executable file
@@ -0,0 +1,112 @@
|
||||
#ifndef MOUSE_H__
|
||||
#define MOUSE_H__
|
||||
|
||||
#include <vector>
|
||||
#include "../log.h"
|
||||
|
||||
|
||||
/** A mouse action such as a button press, release or mouse movement */
|
||||
class MouseAction
|
||||
{
|
||||
public:
|
||||
static const char ACTION_MOVE = 0;
|
||||
static const char ACTION_LEFT = 1;
|
||||
static const char ACTION_RIGHT = 2;
|
||||
static const char ACTION_WHEEL = 3;
|
||||
|
||||
static const char DATA_UP = 0;
|
||||
static const char DATA_DOWN = 1;
|
||||
|
||||
MouseAction(char actionButtonId, char buttonData, short x, short y, char pointerId);
|
||||
MouseAction(char actionButtonId, char buttonData, short x, short y, short dx, short dy, char pointerId);
|
||||
|
||||
bool isButton() const;
|
||||
|
||||
short x, y;
|
||||
short dx, dy;
|
||||
char action;
|
||||
char data;
|
||||
char pointerId;
|
||||
};
|
||||
|
||||
/* Iterators */
|
||||
typedef std::vector<MouseAction> MouseActionVec;
|
||||
typedef MouseActionVec::iterator MouseActionIt;
|
||||
typedef MouseActionVec::const_iterator MouseActionCIt;
|
||||
|
||||
|
||||
class MouseDevice
|
||||
{
|
||||
public:
|
||||
static const int MAX_NUM_BUTTONS = 4;
|
||||
|
||||
MouseDevice();
|
||||
|
||||
char getButtonState(int buttonId);
|
||||
bool isButtonDown(int buttonId);
|
||||
|
||||
/// Was the current movement the first movement after mouse down?
|
||||
bool wasFirstMovement();
|
||||
|
||||
short getX();
|
||||
short getY();
|
||||
|
||||
short getDX();
|
||||
short getDY();
|
||||
|
||||
void reset();
|
||||
void reset2();
|
||||
|
||||
bool next();
|
||||
void rewind();
|
||||
|
||||
bool getEventButtonState();
|
||||
char getEventButton();
|
||||
const MouseAction& getEvent();
|
||||
|
||||
void feed(char actionButtonId, char buttonData, short x, short y);
|
||||
void feed(char actionButtonId, char buttonData, short x, short y, short dx, short dy);
|
||||
|
||||
private:
|
||||
int _index;
|
||||
short _x, _y;
|
||||
short _dx, _dy;
|
||||
short _xOld, _yOld;
|
||||
char _buttonStates[MAX_NUM_BUTTONS];
|
||||
std::vector<MouseAction> _inputs;
|
||||
int _firstMovementType;
|
||||
static const int DELTA_NOTSET = -9999;
|
||||
};
|
||||
|
||||
/** A static mouse class, written to resemble the one in lwjgl somewhat
|
||||
UPDATE: which is very silly, since it doesn't support multi touch... */
|
||||
class Mouse
|
||||
{
|
||||
public:
|
||||
static char getButtonState(int buttonId);
|
||||
static bool isButtonDown(int buttonId);
|
||||
|
||||
static short getX();
|
||||
static short getY();
|
||||
|
||||
static short getDX();
|
||||
static short getDY();
|
||||
|
||||
static void reset();
|
||||
static void reset2();
|
||||
|
||||
static bool next();
|
||||
static void rewind();
|
||||
|
||||
static bool getEventButtonState();
|
||||
static char getEventButton();
|
||||
static const MouseAction& getEvent();
|
||||
|
||||
static void feed(char actionButtonId, char buttonData, short x, short y);
|
||||
static void feed(char actionButtonId, char buttonData, short x, short y, short dx, short dy);
|
||||
|
||||
private:
|
||||
static MouseDevice _instance;
|
||||
};
|
||||
|
||||
#endif//MOUSE_H__
|
||||
20
src/platform/input/Multitouch.cpp
Executable file
20
src/platform/input/Multitouch.cpp
Executable file
@@ -0,0 +1,20 @@
|
||||
#include "Multitouch.h"
|
||||
|
||||
int
|
||||
Multitouch::_index = -1,
|
||||
Multitouch::_activePointerCount = 0,
|
||||
Multitouch::_activePointerList[Multitouch::MAX_POINTERS] = {-1},
|
||||
Multitouch::_activePointerThisUpdateCount = 0,
|
||||
Multitouch::_activePointerThisUpdateList[Multitouch::MAX_POINTERS] = {-1};
|
||||
|
||||
bool
|
||||
Multitouch::_wasPressed[Multitouch::MAX_POINTERS] = {false},
|
||||
Multitouch::_wasReleased[Multitouch::MAX_POINTERS] = {false},
|
||||
Multitouch::_wasPressedThisUpdate[Multitouch::MAX_POINTERS] = {false},
|
||||
Multitouch::_wasReleasedThisUpdate[Multitouch::MAX_POINTERS] = {false};
|
||||
|
||||
TouchPointer
|
||||
Multitouch::_pointers[Multitouch::MAX_POINTERS];
|
||||
|
||||
std::vector<MouseAction>
|
||||
Multitouch::_inputs;
|
||||
176
src/platform/input/Multitouch.h
Executable file
176
src/platform/input/Multitouch.h
Executable file
@@ -0,0 +1,176 @@
|
||||
#ifndef MULTITOUCH_H__
|
||||
#define MULTITOUCH_H__
|
||||
|
||||
#include "Mouse.h"
|
||||
#include "../log.h"
|
||||
|
||||
typedef MouseDevice TouchPointer;
|
||||
|
||||
class Multitouch
|
||||
{
|
||||
public:
|
||||
static const int MAX_POINTERS = 12;
|
||||
|
||||
static bool isPointerDown(int pointerId) {
|
||||
return g(pointerId).isButtonDown(1);
|
||||
}
|
||||
|
||||
// Returns the first activeExtended (down OR released) pointer id
|
||||
static int getFirstActivePointerIdEx() {
|
||||
for (int i = 0; i < MAX_POINTERS; ++i)
|
||||
if (_pointers[i].isButtonDown(1)) return i;
|
||||
for (int i = 0; i < MAX_POINTERS; ++i)
|
||||
if (_wasReleased[i]) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Returns the first activeExtended (down OR released) pointer id
|
||||
// Compared to getFirstActivePointerIdEx, this method keeps the state the
|
||||
// tick/render loop, while the former keeps it for a tick.
|
||||
static int getFirstActivePointerIdExThisUpdate() {
|
||||
for (int i = 0; i < MAX_POINTERS; ++i)
|
||||
if (_pointers[i].isButtonDown(1)) return i;
|
||||
for (int i = 0; i < MAX_POINTERS; ++i)
|
||||
if (_wasReleasedThisUpdate[i]) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get a list of all active (i.e. marked as touched/down) pointer ids
|
||||
static int getActivePointerIds(const int** const ids) {
|
||||
*ids = _activePointerList;
|
||||
return _activePointerCount;
|
||||
}
|
||||
|
||||
// Get a list of all active (i.e. marked as touched/down) pointer ids
|
||||
static int getActivePointerIdsThisUpdate(const int** const ids) {
|
||||
*ids = _activePointerThisUpdateList;
|
||||
return _activePointerThisUpdateCount;
|
||||
}
|
||||
|
||||
// Called when no more events will be pushed this update
|
||||
static void commit() {
|
||||
_activePointerCount = 0;
|
||||
_activePointerThisUpdateCount = 0;
|
||||
for (int i = 0; i < MAX_POINTERS; ++i) {
|
||||
bool isDown = _pointers[i].isButtonDown(1);
|
||||
if (isDown) {
|
||||
_activePointerList[_activePointerCount++] = i;
|
||||
_activePointerThisUpdateList[_activePointerThisUpdateCount++] = i;
|
||||
} else if (_wasReleased[i]) {
|
||||
_activePointerThisUpdateList[_activePointerThisUpdateCount++] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static short getX(int pointerId) { return g(pointerId).getX(); }
|
||||
static short getY(int pointerId) { return g(pointerId).getY(); }
|
||||
|
||||
static short getDX(int pointerId) { return g(pointerId).getDX(); }
|
||||
static short getDY(int pointerId) { return g(pointerId).getDY(); }
|
||||
|
||||
static bool wasFirstMovement(int pointerId) { return g(pointerId).wasFirstMovement(); }
|
||||
|
||||
static bool isPressed(int pointerId) {
|
||||
return _wasPressed[_clampPointerId(pointerId)];
|
||||
}
|
||||
static bool isReleased(int pointerId) {
|
||||
return _wasReleased[_clampPointerId(pointerId)];
|
||||
}
|
||||
static bool isPressedThisUpdate(int pointerId) {
|
||||
return _wasPressedThisUpdate[_clampPointerId(pointerId)];
|
||||
}
|
||||
static bool isReleasedThisUpdate(int pointerId) {
|
||||
return _wasReleasedThisUpdate[_clampPointerId(pointerId)];
|
||||
}
|
||||
|
||||
static void reset() {
|
||||
//LOGI("mtouch is reset\n");
|
||||
_inputs.clear();
|
||||
_index = -1;
|
||||
|
||||
for (int i = 0; i < MAX_POINTERS; ++i) {
|
||||
g(i).reset();
|
||||
|
||||
_wasPressed[i] = false;
|
||||
_wasReleased[i] = false;
|
||||
}
|
||||
}
|
||||
static void resetThisUpdate() {
|
||||
for (int i = 0; i < MAX_POINTERS; ++i) {
|
||||
_wasPressedThisUpdate[i] = false;
|
||||
_wasReleasedThisUpdate[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool next() {
|
||||
if (_index + 1 >= (int)_inputs.size())
|
||||
return false;
|
||||
|
||||
++_index;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void rewind() {
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
static MouseAction& getEvent() {
|
||||
return _inputs[_index];
|
||||
}
|
||||
|
||||
static void feed(char actionButtonId, char buttonData, short x, short y, char pointerId) {
|
||||
pointerId = _clampPointerId(pointerId);
|
||||
|
||||
_inputs.push_back(MouseAction(actionButtonId, buttonData, x, y, pointerId));
|
||||
g(pointerId).feed(actionButtonId, buttonData, x, y);
|
||||
|
||||
if (actionButtonId > 0) {
|
||||
if (buttonData == MouseAction::DATA_DOWN) {
|
||||
_wasPressed[pointerId] = true;
|
||||
_wasPressedThisUpdate[pointerId] = true;
|
||||
//LOGI("isPressed %d %d\n", pointerId, isPressed(pointerId));
|
||||
}
|
||||
else if (buttonData == MouseAction::DATA_UP) {
|
||||
_wasReleased[pointerId] = true;
|
||||
_wasReleasedThisUpdate[pointerId] = true;
|
||||
//LOGI("isReleased %d %d\n", pointerId, isReleased(pointerId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int getMaxPointers() {
|
||||
return MAX_POINTERS;
|
||||
}
|
||||
|
||||
private:
|
||||
static TouchPointer& g(int pointerId) {
|
||||
return _pointers[_clampPointerId(pointerId)];
|
||||
}
|
||||
|
||||
static int _clampPointerId(int p) {
|
||||
if (p < 0) return p;
|
||||
if (p >= MAX_POINTERS) return MAX_POINTERS-1;
|
||||
return p;
|
||||
}
|
||||
|
||||
// Between calls to reset()
|
||||
static bool _wasPressed[MAX_POINTERS];
|
||||
static bool _wasReleased[MAX_POINTERS];
|
||||
|
||||
// Between calls to resetThisUpdate()
|
||||
static bool _wasPressedThisUpdate[MAX_POINTERS];
|
||||
static bool _wasReleasedThisUpdate[MAX_POINTERS];
|
||||
|
||||
static TouchPointer _pointers[MAX_POINTERS];
|
||||
static std::vector<MouseAction> _inputs;
|
||||
|
||||
static int _activePointerList[MAX_POINTERS];
|
||||
static int _activePointerCount;
|
||||
|
||||
static int _activePointerThisUpdateList[MAX_POINTERS];
|
||||
static int _activePointerThisUpdateCount;
|
||||
|
||||
static int _index;
|
||||
};
|
||||
|
||||
#endif /*MULTITOUCH_H__*/
|
||||
Reference in New Issue
Block a user