2017-10-29 10:28:14 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2015 Dimok
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
****************************************************************************/
|
2018-06-21 20:44:58 +02:00
|
|
|
#include <gui/GuiController.h>
|
2022-02-05 14:28:08 +01:00
|
|
|
#include <gui/GuiElement.h>
|
2018-06-21 20:44:58 +02:00
|
|
|
#include <gui/GuiTrigger.h>
|
2017-10-29 10:28:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the GuiTrigger class.
|
|
|
|
*/
|
|
|
|
GuiTrigger::GuiTrigger()
|
2022-02-05 14:28:08 +01:00
|
|
|
: chan(CHANNEL_ALL), btns(BUTTON_NONE), bClickEverywhere(false), bHoldEverywhere(false), bSelectionClickEverywhere(false), bLastTouched(false) {
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
GuiTrigger::GuiTrigger(uint32_t ch, uint32_t btn, bool clickEverywhere, bool holdEverywhere, bool selectionClickEverywhere)
|
2022-02-05 14:28:08 +01:00
|
|
|
: chan(ch), btns(btn), bClickEverywhere(clickEverywhere), bHoldEverywhere(holdEverywhere), bSelectionClickEverywhere(selectionClickEverywhere), bLastTouched(false) {
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the GuiTrigger class.
|
|
|
|
*/
|
2018-06-21 20:44:58 +02:00
|
|
|
GuiTrigger::~GuiTrigger() {
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a simple trigger. Requires:
|
|
|
|
* - Element is selected
|
|
|
|
* - Trigger button is pressed
|
|
|
|
*/
|
2018-06-21 20:44:58 +02:00
|
|
|
void GuiTrigger::setTrigger(uint32_t ch, uint32_t btn) {
|
|
|
|
chan = ch;
|
|
|
|
btns = btn;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
bool GuiTrigger::left(const GuiController *controller) const {
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->chan & chan) == 0) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_LEFT | STICK_L_LEFT)) {
|
2018-06-21 20:44:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
bool GuiTrigger::right(const GuiController *controller) const {
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->chan & chan) == 0) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_RIGHT | STICK_L_RIGHT)) {
|
2018-06-21 20:44:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
bool GuiTrigger::up(const GuiController *controller) const {
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->chan & chan) == 0) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_UP | STICK_L_UP)) {
|
2018-06-21 20:44:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
bool GuiTrigger::down(const GuiController *controller) const {
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->chan & chan) == 0) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_DOWN | STICK_L_DOWN)) {
|
2018-06-21 20:44:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
int32_t GuiTrigger::clicked(const GuiController *controller) const {
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->chan & chan) == 0) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return CLICKED_NONE;
|
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
int32_t bResult = CLICKED_NONE;
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
if (controller->data.touched && controller->data.validPointer && (btns & VPAD_TOUCH) && !controller->lastData.touched) {
|
2017-10-29 10:28:14 +01:00
|
|
|
bResult = CLICKED_TOUCH;
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
if (controller->data.buttons_d & btns) {
|
2018-06-21 20:44:58 +02:00
|
|
|
bResult = CLICKED_BUTTON;
|
|
|
|
}
|
|
|
|
return bResult;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
bool GuiTrigger::held(const GuiController *controller) const {
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->chan & chan) == 0) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bResult = false;
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
if (controller->data.touched && (btns & VPAD_TOUCH) && controller->data.validPointer && controller->lastData.touched && controller->lastData.validPointer) {
|
2017-10-29 10:28:14 +01:00
|
|
|
bResult = true;
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
if (controller->data.buttons_h & btns) {
|
2018-06-21 20:44:58 +02:00
|
|
|
bResult = true;
|
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
return bResult;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
bool GuiTrigger::released(const GuiController *controller) const {
|
2020-08-13 12:38:07 +02:00
|
|
|
if ((controller->chan & chan) == 0) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:58:19 +02:00
|
|
|
if (clicked(controller) || held(controller)) {
|
2017-10-29 10:28:14 +01:00
|
|
|
return false;
|
2020-08-13 12:58:19 +02:00
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
|
|
|
bool bResult = false;
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
if (!controller->data.touched && (btns & VPAD_TOUCH) && controller->lastData.touched && controller->lastData.validPointer) {
|
2017-10-29 10:28:14 +01:00
|
|
|
bResult = true;
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:38:07 +02:00
|
|
|
if (controller->data.buttons_r & btns) {
|
2018-06-21 20:44:58 +02:00
|
|
|
bResult = true;
|
|
|
|
}
|
2017-10-29 10:28:14 +01:00
|
|
|
|
2018-06-21 20:44:58 +02:00
|
|
|
return bResult;
|
2017-10-29 10:28:14 +01:00
|
|
|
}
|