mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-23 20:09:46 +03:00
* Outline all the Mouse and Keyboard code.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "GameMods.hpp"
|
||||
|
||||
std::vector<Keyboard::Input> Keyboard::_inputs;
|
||||
std::vector<KeyboardAction> Keyboard::_inputs;
|
||||
int Keyboard::_index = -1;
|
||||
int Keyboard::_states[KEYBOARD_STATES_SIZE];
|
||||
|
||||
@@ -23,10 +23,40 @@ void Keyboard::feed(int down, int key)
|
||||
}
|
||||
#endif
|
||||
|
||||
Input i;
|
||||
i.field_0 = down;
|
||||
i.field_4 = uint8_t(key);
|
||||
_inputs.push_back(i);
|
||||
_inputs.push_back(KeyboardAction(key, down));
|
||||
|
||||
_states[key] = down;
|
||||
}
|
||||
|
||||
bool Keyboard::next()
|
||||
{
|
||||
if (_index + 1 >= _inputs.size())
|
||||
return false;
|
||||
|
||||
_index++;
|
||||
return true;
|
||||
}
|
||||
|
||||
int Keyboard::getEventKey()
|
||||
{
|
||||
return _inputs[_index].field_4;
|
||||
}
|
||||
|
||||
int Keyboard::getEventKeyState()
|
||||
{
|
||||
return _inputs[_index].field_0;
|
||||
}
|
||||
|
||||
bool Keyboard::isKeyDown(int keyCode)
|
||||
{
|
||||
if (keyCode < 0 || keyCode >= KEYBOARD_STATES_SIZE)
|
||||
return false;
|
||||
|
||||
return _states[keyCode] == 1;
|
||||
}
|
||||
|
||||
void Keyboard::reset()
|
||||
{
|
||||
_inputs.clear();
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
@@ -16,21 +16,31 @@
|
||||
|
||||
#define KEYBOARD_STATES_SIZE 256
|
||||
|
||||
struct KeyboardAction
|
||||
{
|
||||
int field_0;
|
||||
uint8_t field_4;
|
||||
|
||||
KeyboardAction(uint8_t key, int state)
|
||||
{
|
||||
field_0 = state;
|
||||
field_4 = key;
|
||||
}
|
||||
};
|
||||
|
||||
class Keyboard
|
||||
{
|
||||
public:
|
||||
//@TODO: Rename this to KeyboardAction
|
||||
struct Input
|
||||
{
|
||||
int field_0;
|
||||
uint8_t field_4;
|
||||
};
|
||||
static void feed(int down, int key);
|
||||
static bool next();
|
||||
static int getEventKey();
|
||||
static int getEventKeyState();
|
||||
static bool isKeyDown(int keyCode);
|
||||
static void reset();
|
||||
|
||||
static std::vector<Input> _inputs;
|
||||
private:
|
||||
static std::vector<KeyboardAction> _inputs;
|
||||
static int _states[KEYBOARD_STATES_SIZE];
|
||||
static int _index;
|
||||
|
||||
// likely inlined
|
||||
static void feed(int down, int key);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
#include "Mouse.hpp"
|
||||
|
||||
std::vector<MouseInput> Mouse::_inputs;
|
||||
std::vector<MouseAction> Mouse::_inputs;
|
||||
int Mouse::_index, Mouse::_x, Mouse::_y;
|
||||
int Mouse::_xOld, Mouse::_yOld, Mouse::_buttonStates[3];
|
||||
|
||||
void Mouse::feed(int x1, int x2, int x3, int x4)
|
||||
{
|
||||
_inputs.push_back(MouseInput(x1, x2, x3, x4));
|
||||
_inputs.push_back(MouseAction(x1, x2, x3, x4));
|
||||
|
||||
if (x1 >= 3)
|
||||
return;
|
||||
@@ -27,3 +27,72 @@ void Mouse::feed(int x1, int x2, int x3, int x4)
|
||||
_x = x3;
|
||||
_y = x4;
|
||||
}
|
||||
|
||||
short Mouse::getX()
|
||||
{
|
||||
return short(_x);
|
||||
}
|
||||
|
||||
short Mouse::getY()
|
||||
{
|
||||
return short(_y);
|
||||
}
|
||||
|
||||
bool Mouse::next()
|
||||
{
|
||||
if (_index + 1 >= int(_inputs.size()))
|
||||
return false;
|
||||
|
||||
_index++;
|
||||
return true;
|
||||
}
|
||||
|
||||
int Mouse::getEventButton()
|
||||
{
|
||||
return _inputs[_index].field_0;
|
||||
}
|
||||
|
||||
bool Mouse::isButtonDown(int btn)
|
||||
{
|
||||
return _buttonStates[btn];
|
||||
}
|
||||
|
||||
void Mouse::reset()
|
||||
{
|
||||
_inputs.clear();
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
MouseAction* Mouse::getEvent()
|
||||
{
|
||||
return &_inputs[_index];
|
||||
}
|
||||
|
||||
int Mouse::getButtonState(int btn)
|
||||
{
|
||||
if (btn <= 0 || btn >= 3)
|
||||
return 0;
|
||||
|
||||
return _buttonStates[btn];
|
||||
}
|
||||
|
||||
void Mouse::setX(int x)
|
||||
{
|
||||
_x = x;
|
||||
}
|
||||
|
||||
void Mouse::setY(int y)
|
||||
{
|
||||
_y = y;
|
||||
}
|
||||
|
||||
void Mouse::reset2()
|
||||
{
|
||||
_xOld = _x;
|
||||
_yOld = _y;
|
||||
}
|
||||
|
||||
int Mouse::getEventButtonState()
|
||||
{
|
||||
return _inputs[_index].field_4;
|
||||
}
|
||||
|
||||
@@ -10,27 +10,32 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct MouseInput
|
||||
struct MouseAction
|
||||
{
|
||||
int field_0;
|
||||
int field_4;
|
||||
int field_8;
|
||||
int field_C;
|
||||
|
||||
MouseInput()
|
||||
MouseAction()
|
||||
{
|
||||
field_0 = 0;
|
||||
field_4 = 0;
|
||||
field_8 = 0;
|
||||
field_C = 0;
|
||||
}
|
||||
MouseInput(int x1, int x2, int x3, int x4)
|
||||
MouseAction(int x1, int x2, int x3, int x4)
|
||||
{
|
||||
field_0 = x1;
|
||||
field_4 = x2;
|
||||
field_8 = x3;
|
||||
field_C = x4;
|
||||
}
|
||||
|
||||
bool isButton()
|
||||
{
|
||||
return field_0 == 1 || field_0 == 2;
|
||||
}
|
||||
};
|
||||
|
||||
class Mouse
|
||||
@@ -38,10 +43,23 @@ class Mouse
|
||||
public:
|
||||
static void feed(int, int, int, int);
|
||||
|
||||
static short getX();
|
||||
static short getY();
|
||||
static bool next();
|
||||
static bool isButtonDown(int btn);
|
||||
static int getButtonState(int btn);
|
||||
static int getEventButton();
|
||||
static int getEventButtonState();
|
||||
static MouseAction* getEvent();
|
||||
static void setX(int x);
|
||||
static void setY(int y);
|
||||
static void reset();
|
||||
static void reset2();
|
||||
|
||||
// @TODO: There's plenty of inlined code here. Out-line it.
|
||||
|
||||
public:
|
||||
static std::vector<MouseInput> _inputs;
|
||||
private:
|
||||
static std::vector<MouseAction> _inputs;
|
||||
static int _index;
|
||||
static int _x, _y;
|
||||
static int _xOld, _yOld;
|
||||
|
||||
Reference in New Issue
Block a user