Files
mcpe/source/client/player/input/Multitouch.cpp
iProgramInCpp 60b21356a1 Integrate touch related development. (#90)
* * Add BuildActionIntention crap

* * Set Client and World projects to use MP compilation

* asd

* * Use the new BuildActionIntention to break and place blocks.

* * Reverse engineer the IArea system.

* * Copy break logic from survival into creative conditionally

* * Reverse IBuildInput and MouseHandler
* Replace the new relative paths in the client project with $(MC_ROOT) again

* * Reverse Multitouch, MouseDevice

* * Reverse a bunch of auxiliary classes for input.

* * Use CustomInputHolder instead of holding inputs manually.

* * Reverse a whole BUNCH of things!

* * Add feedback textures to the gitignore.

* * D-pad now renders! Also loads of other work.

* * More Stuff

* * Finish touch control bug fixing.

* * Finalize work.

* * One last thing..

* * Add a "cramped" mode to the options screen and start menu.

* * Oh, forgot to do something
2023-11-02 00:49:11 +02:00

168 lines
3.0 KiB
C++

/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "Multitouch.hpp"
int Multitouch::_activePointerCount;
int Multitouch::_activePointerList[MAX_TOUCHES];
int Multitouch::_index = -1;
bool Multitouch::_wasPressed[MAX_TOUCHES];
bool Multitouch::_wasReleased[MAX_TOUCHES];
bool Multitouch::_wasPressedThisUpdate[MAX_TOUCHES];
bool Multitouch::_wasReleasedThisUpdate[MAX_TOUCHES];
MouseDevice Multitouch::_pointers[MAX_TOUCHES];
std::vector<MouseAction> Multitouch::_inputs;
int Multitouch::_clampPointerId(int Id)
{
if (Id < 0)
return Id; //! @BUG
if (Id >= MAX_TOUCHES)
return MAX_TOUCHES - 1;
return Id;
}
void Multitouch::commit()
{
_activePointerCount = 0;
for (int i = 0; i < MAX_TOUCHES; i++)
{
if (_pointers[i].isButtonDown(BUTTON_LEFT))
{
_activePointerList[_activePointerCount++] = i;
}
}
}
void Multitouch::feed(MouseButtonType a1, bool a2, int a3, int a4, int fingerId)
{
fingerId = _clampPointerId(fingerId);
MouseAction action(a1, a2, a3, a4, fingerId);
_inputs.push_back(action);
MouseDevice* pDevice = g(fingerId);
pDevice->feed(a1, a2, a3, a4);
if (a1)
{
if (a2)
{
_wasPressed[fingerId] = true;
_wasPressedThisUpdate[fingerId] = true;
}
else if (a2 == 0)
{
_wasReleased[fingerId] = true;
_wasReleasedThisUpdate[fingerId] = true;
}
}
}
MouseDevice* Multitouch::g(int Index)
{
return &_pointers[_clampPointerId(Index)];
}
int Multitouch::getActivePointerIds(const int** out)
{
*out = _activePointerList;
return _activePointerCount;
}
MouseAction* Multitouch::getEvent()
{
return &_inputs[_index];
}
int Multitouch::getFirstActivePointerIdEx()
{
for (int i = 0; i < MAX_TOUCHES; i++)
{
if (_pointers[i].isButtonDown(BUTTON_LEFT))
return i;
}
for (int i = 0; i < MAX_TOUCHES; i++)
{
if (_wasReleased[i])
return i;
}
return -1;
}
int Multitouch::getFirstActivePointerIdExThisUpdate()
{
for (int i = 0; i < MAX_TOUCHES; i++)
{
if (_pointers[i].isButtonDown(BUTTON_LEFT))
return i;
}
for (int i = 0; i < MAX_TOUCHES; i++)
{
if (_wasReleasedThisUpdate[i])
return i;
}
return -1;
}
int Multitouch::getX(int fingerId)
{
return g(fingerId)->getX();
}
int Multitouch::getY(int fingerId)
{
return g(fingerId)->getY();
}
bool Multitouch::isPressed(int fingerId)
{
return _wasPressed[_clampPointerId(fingerId)];
}
bool Multitouch::next()
{
if (_index + 1 >= _inputs.size())
return false;
_index++;
return true;
}
void Multitouch::reset()
{
_inputs.clear();
_index = -1;
for (int i = 0; i < MAX_TOUCHES; i++)
{
g(i)->reset();
_wasPressed[i] = 0;
_wasReleased[i] = 0;
}
}
void Multitouch::resetThisUpdate()
{
for (int i = 0; i < MAX_TOUCHES; i++)
{
_wasPressedThisUpdate[i] = 0;
_wasReleasedThisUpdate[i] = 0;
}
}
void Multitouch::rewind()
{
_index = -1;
}