197 lines
4.8 KiB
C
197 lines
4.8 KiB
C
/*
|
|
* Released into the public domain
|
|
* by Aki Goto <tyatsumi@gmail.com>
|
|
*/
|
|
|
|
#include "multibutton.h"
|
|
|
|
void MultiButton_initialize(struct MultiButton *this, struct Gamepad *gamepad)
|
|
{
|
|
this->buttons[ButtonId_UP] = &gamepad->buttons[ButtonId_UP];
|
|
this->buttons[ButtonId_DOWN] = &gamepad->buttons[ButtonId_DOWN];
|
|
this->buttons[ButtonId_LEFT] = &gamepad->buttons[ButtonId_LEFT];
|
|
this->buttons[ButtonId_RIGHT] = &gamepad->buttons[ButtonId_RIGHT];
|
|
this->buttons[ButtonId_A] = &gamepad->buttons[ButtonId_A];
|
|
this->buttons[ButtonId_B] = &gamepad->buttons[ButtonId_B];
|
|
this->buttons[ButtonId_X] = &gamepad->buttons[ButtonId_X];
|
|
this->buttons[ButtonId_Y] = &gamepad->buttons[ButtonId_Y];
|
|
|
|
this->size = 0;
|
|
this->available = 0;
|
|
|
|
this->sequenceSize = 0;
|
|
this->modifier = Modifier_NONE;
|
|
}
|
|
|
|
void MultiButton_reset(struct MultiButton *this)
|
|
{
|
|
this->size = 0;
|
|
this->sequenceSize = 0;
|
|
this->modifier = Modifier_NONE;
|
|
this->available = 0;
|
|
}
|
|
|
|
void MultiButton_update(struct MultiButton *this, struct js_event *event)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
if (Button_update(this->buttons[i], event)) {
|
|
if (Button_isDown(this->buttons[i])) {
|
|
if (this->size < 8) {
|
|
this->list[this->size] = this->buttons[i];
|
|
this->size++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MultiButton_generate(struct MultiButton *this)
|
|
{
|
|
int i;
|
|
|
|
this->available = 0;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
if (Button_isUp(this->buttons[i])) {
|
|
if (this->size > 0 && this->buttons[i] == this->list[this->size - 1]) {
|
|
if (this->size == 1) {
|
|
if (this->sequenceSize < 1) {
|
|
if (this->sequenceSize < 8) {
|
|
this->sequence[this->sequenceSize] = this->buttons[i];
|
|
this->sequenceSize++;
|
|
}
|
|
} else {
|
|
this->code.modifier = this->modifier;
|
|
this->code.first = this->sequence[0]->id;
|
|
this->code.second = this->buttons[i]->id;
|
|
|
|
this->available = 1;
|
|
this->sequenceSize = 0;
|
|
this->modifier = Modifier_NONE;
|
|
}
|
|
} else {
|
|
if (this->list[0] == this->buttons[i]->shift && Button_isHolded(this->buttons[i]->shift)) {
|
|
int k;
|
|
|
|
this->modifier = Modifier_SHIFT;
|
|
for (k = 1; k < this->size; k++) {
|
|
this->list[k - 1] = this->list[k];
|
|
}
|
|
this->size--;
|
|
if (this->sequenceSize < 8) {
|
|
this->sequence[this->sequenceSize] = this->buttons[i];
|
|
this->sequenceSize++;
|
|
}
|
|
} else if (this->list[0] == this->buttons[i]->control && Button_isHolded(this->buttons[i]->control)) {
|
|
int k;
|
|
|
|
this->modifier = Modifier_CONTROL;
|
|
for (k = 1; k < this->size; k++) {
|
|
this->list[k - 1] = this->list[k];
|
|
}
|
|
this->size--;
|
|
if (this->sequenceSize < 8) {
|
|
this->sequence[this->sequenceSize] = this->buttons[i];
|
|
this->sequenceSize++;
|
|
}
|
|
} else if (this->list[0] == this->buttons[i]->alt && Button_isHolded(this->buttons[i]->alt)) {
|
|
int k;
|
|
|
|
this->modifier = Modifier_ALT;
|
|
for (k = 1; k < this->size; k++) {
|
|
this->list[k - 1] = this->list[k];
|
|
}
|
|
this->size--;
|
|
if (this->sequenceSize < 8) {
|
|
this->sequence[this->sequenceSize] = this->buttons[i];
|
|
this->sequenceSize++;
|
|
}
|
|
} else {
|
|
this->code.modifier = this->modifier;
|
|
this->code.first = this->list[0]->id;
|
|
this->code.second = this->buttons[i]->id;
|
|
this->available = 1;
|
|
this->sequenceSize = 0;
|
|
this->modifier = Modifier_NONE;
|
|
}
|
|
}
|
|
this->size = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MultiSpecial_initialize(struct MultiSpecial *this, struct Gamepad *gamepad)
|
|
{
|
|
this->buttons[0] = &gamepad->buttons[ButtonId_L1];
|
|
this->buttons[1] = &gamepad->buttons[ButtonId_R1];
|
|
|
|
this->size = 0;
|
|
this->available = 0;
|
|
}
|
|
|
|
void MultiSpecial_reset(struct MultiSpecial *this)
|
|
{
|
|
this->size = 0;
|
|
this->available = 0;
|
|
}
|
|
|
|
void MultiSpecial_update(struct MultiSpecial *this, struct js_event *event)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
if (Button_update(this->buttons[i], event)) {
|
|
if (Button_isDown(this->buttons[i])) {
|
|
if (this->size < 8) {
|
|
this->list[this->size] = this->buttons[i];
|
|
this->size++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MultiSpecial_generate(struct MultiSpecial *this)
|
|
{
|
|
int i;
|
|
|
|
this->available = 0;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
if (Button_isUp(this->buttons[i])) {
|
|
if (this->size > 0 && this->buttons[i] == this->list[this->size - 1]) {
|
|
if (this->size == 1) {
|
|
switch (this->buttons[i]->id) {
|
|
default:
|
|
this->code = Special_NONE;
|
|
break;
|
|
case ButtonId_L1:
|
|
this->code = Special_CANCEL;
|
|
break;
|
|
case ButtonId_R1:
|
|
this->code = Special_MODE;
|
|
break;
|
|
}
|
|
} else {
|
|
switch (this->buttons[i]->id) {
|
|
default:
|
|
this->code = Special_NONE;
|
|
break;
|
|
case ButtonId_L1:
|
|
this->code = Special_RESERVED1;
|
|
break;
|
|
case ButtonId_R1:
|
|
this->code = Special_RESERVED2;
|
|
break;
|
|
}
|
|
}
|
|
this->available = 1;
|
|
this->size = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|