209 lines
7.0 KiB
C
209 lines
7.0 KiB
C
/*
|
|
This file is part of Furui.
|
|
|
|
Furui 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.
|
|
|
|
Furui 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 Furui. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "padkey_multibutton.h"
|
|
|
|
void padkey_multibutton_initialize(struct padkey_multibutton *multibutton, struct padkey_gamepad *gamepad)
|
|
{
|
|
multibutton->buttons[PADKEY_BUTTON_ID_UP] = &gamepad->buttons[PADKEY_BUTTON_ID_UP];
|
|
multibutton->buttons[PADKEY_BUTTON_ID_DOWN] = &gamepad->buttons[PADKEY_BUTTON_ID_DOWN];
|
|
multibutton->buttons[PADKEY_BUTTON_ID_LEFT] = &gamepad->buttons[PADKEY_BUTTON_ID_LEFT];
|
|
multibutton->buttons[PADKEY_BUTTON_ID_RIGHT] = &gamepad->buttons[PADKEY_BUTTON_ID_RIGHT];
|
|
multibutton->buttons[PADKEY_BUTTON_ID_WEST] = &gamepad->buttons[PADKEY_BUTTON_ID_WEST];
|
|
multibutton->buttons[PADKEY_BUTTON_ID_EAST] = &gamepad->buttons[PADKEY_BUTTON_ID_EAST];
|
|
multibutton->buttons[PADKEY_BUTTON_ID_NORTH] = &gamepad->buttons[PADKEY_BUTTON_ID_NORTH];
|
|
multibutton->buttons[PADKEY_BUTTON_ID_SOUTH] = &gamepad->buttons[PADKEY_BUTTON_ID_SOUTH];
|
|
|
|
multibutton->length = 0;
|
|
multibutton->available = 0;
|
|
|
|
multibutton->sequence_length = 0;
|
|
multibutton->modifier = PADKEY_MODIFIER_NONE;
|
|
}
|
|
|
|
void padkey_multibutton_reset(struct padkey_multibutton *multibutton)
|
|
{
|
|
multibutton->length = 0;
|
|
multibutton->sequence_length = 0;
|
|
multibutton->modifier = PADKEY_MODIFIER_NONE;
|
|
multibutton->available = 0;
|
|
}
|
|
|
|
void padkey_multibutton_update(struct padkey_multibutton *multibutton, unsigned int type, unsigned int code, int value)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
if (padkey_button_update(multibutton->buttons[i], type, code, value)) {
|
|
if (padkey_button_is_down(multibutton->buttons[i])) {
|
|
if (multibutton->length < 8) {
|
|
multibutton->list[multibutton->length] = multibutton->buttons[i];
|
|
multibutton->length++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void padkey_multibutton_generate(struct padkey_multibutton *multibutton)
|
|
{
|
|
int i;
|
|
|
|
multibutton->available = 0;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
if (padkey_button_is_up(multibutton->buttons[i])) {
|
|
if (multibutton->length > 0 && multibutton->buttons[i] == multibutton->list[multibutton->length - 1]) {
|
|
if (multibutton->length == 1) {
|
|
if (multibutton->sequence_length < 1) {
|
|
if (multibutton->sequence_length < 8) {
|
|
multibutton->sequence[multibutton->sequence_length] = multibutton->buttons[i];
|
|
multibutton->sequence_length++;
|
|
}
|
|
} else {
|
|
multibutton->code.modifier = multibutton->modifier;
|
|
multibutton->code.first = multibutton->sequence[0]->id;
|
|
multibutton->code.second = multibutton->buttons[i]->id;
|
|
|
|
multibutton->available = 1;
|
|
multibutton->sequence_length = 0;
|
|
multibutton->modifier = PADKEY_MODIFIER_NONE;
|
|
}
|
|
} else {
|
|
if (multibutton->list[0] == multibutton->buttons[i]->shift && padkey_button_is_holded(multibutton->buttons[i]->shift)) {
|
|
int k;
|
|
|
|
multibutton->modifier = PADKEY_MODIFIER_SHIFT;
|
|
for (k = 1; k < multibutton->length; k++) {
|
|
multibutton->list[k - 1] = multibutton->list[k];
|
|
}
|
|
multibutton->length--;
|
|
if (multibutton->sequence_length < 8) {
|
|
multibutton->sequence[multibutton->sequence_length] = multibutton->buttons[i];
|
|
multibutton->sequence_length++;
|
|
}
|
|
} else if (multibutton->list[0] == multibutton->buttons[i]->control && padkey_button_is_holded(multibutton->buttons[i]->control)) {
|
|
int k;
|
|
|
|
multibutton->modifier = PADKEY_MODIFIER_CONTROL;
|
|
for (k = 1; k < multibutton->length; k++) {
|
|
multibutton->list[k - 1] = multibutton->list[k];
|
|
}
|
|
multibutton->length--;
|
|
if (multibutton->sequence_length < 8) {
|
|
multibutton->sequence[multibutton->sequence_length] = multibutton->buttons[i];
|
|
multibutton->sequence_length++;
|
|
}
|
|
} else if (multibutton->list[0] == multibutton->buttons[i]->alt && padkey_button_is_holded(multibutton->buttons[i]->alt)) {
|
|
int k;
|
|
|
|
multibutton->modifier = PADKEY_MODIFIER_ALT;
|
|
for (k = 1; k < multibutton->length; k++) {
|
|
multibutton->list[k - 1] = multibutton->list[k];
|
|
}
|
|
multibutton->length--;
|
|
if (multibutton->sequence_length < 8) {
|
|
multibutton->sequence[multibutton->sequence_length] = multibutton->buttons[i];
|
|
multibutton->sequence_length++;
|
|
}
|
|
} else {
|
|
multibutton->code.modifier = multibutton->modifier;
|
|
multibutton->code.first = multibutton->list[0]->id;
|
|
multibutton->code.second = multibutton->buttons[i]->id;
|
|
multibutton->available = 1;
|
|
multibutton->sequence_length = 0;
|
|
multibutton->modifier = PADKEY_MODIFIER_NONE;
|
|
}
|
|
}
|
|
multibutton->length = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void padkey_multispecial_initialize(struct padkey_multispecial *multispecial, struct padkey_gamepad *gamepad)
|
|
{
|
|
multispecial->buttons[0] = &gamepad->buttons[PADKEY_BUTTON_ID_SELECT];
|
|
multispecial->buttons[1] = &gamepad->buttons[PADKEY_BUTTON_ID_START];
|
|
|
|
multispecial->length = 0;
|
|
multispecial->available = 0;
|
|
}
|
|
|
|
void padkey_multispecial_reset(struct padkey_multispecial *multispecial)
|
|
{
|
|
multispecial->length = 0;
|
|
multispecial->available = 0;
|
|
}
|
|
|
|
void padkey_multispecial_update(struct padkey_multispecial *multispecial, unsigned int type, unsigned int code, int value)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
if (padkey_button_update(multispecial->buttons[i], type, code, value)) {
|
|
if (padkey_button_is_down(multispecial->buttons[i])) {
|
|
if (multispecial->length < 8) {
|
|
multispecial->list[multispecial->length] = multispecial->buttons[i];
|
|
multispecial->length++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void padkey_multispecial_generate(struct padkey_multispecial *multispecial)
|
|
{
|
|
int i;
|
|
|
|
multispecial->available = 0;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
if (padkey_button_is_up(multispecial->buttons[i])) {
|
|
if (multispecial->length > 0 && multispecial->buttons[i] == multispecial->list[multispecial->length - 1]) {
|
|
if (multispecial->length == 1) {
|
|
switch (multispecial->buttons[i]->id) {
|
|
default:
|
|
multispecial->code = PADKEY_SPECIAL_NONE;
|
|
break;
|
|
case PADKEY_BUTTON_ID_SELECT:
|
|
multispecial->code = PADKEY_SPECIAL_MODE;
|
|
break;
|
|
case PADKEY_BUTTON_ID_START:
|
|
multispecial->code = PADKEY_SPECIAL_CANCEL;
|
|
break;
|
|
}
|
|
} else {
|
|
switch (multispecial->buttons[i]->id) {
|
|
default:
|
|
multispecial->code = PADKEY_SPECIAL_NONE;
|
|
break;
|
|
case PADKEY_BUTTON_ID_SELECT:
|
|
multispecial->code = PADKEY_SPECIAL_RESERVED1;
|
|
break;
|
|
case PADKEY_BUTTON_ID_START:
|
|
multispecial->code = PADKEY_SPECIAL_RESERVED2;
|
|
break;
|
|
}
|
|
}
|
|
multispecial->available = 1;
|
|
multispecial->length = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|