2014-01-25 08:24:55 +00:00
|
|
|
/*
|
|
|
|
** keybindings.h
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp 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 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp 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 mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEYBINDINGS_H
|
|
|
|
#define KEYBINDINGS_H
|
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
|
|
|
|
#include <SDL_scancode.h>
|
2014-12-31 15:39:28 +00:00
|
|
|
#include <SDL_joystick.h>
|
2015-09-04 05:53:41 +00:00
|
|
|
#include <SDL_gamecontroller.h>
|
2014-01-25 08:24:55 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
enum AxisDir
|
|
|
|
{
|
|
|
|
Negative,
|
|
|
|
Positive
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SourceType
|
|
|
|
{
|
|
|
|
Invalid,
|
|
|
|
Key,
|
2015-09-04 05:53:41 +00:00
|
|
|
CButton,
|
|
|
|
CAxis,
|
2014-01-25 08:24:55 +00:00
|
|
|
JButton,
|
2014-12-31 15:39:28 +00:00
|
|
|
JAxis,
|
|
|
|
JHat
|
2014-01-25 08:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SourceDesc
|
|
|
|
{
|
|
|
|
SourceType type;
|
|
|
|
|
|
|
|
union Data
|
|
|
|
{
|
|
|
|
/* Keyboard scancode */
|
|
|
|
SDL_Scancode scan;
|
|
|
|
/* Joystick button index */
|
|
|
|
uint8_t jb;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
/* Joystick axis index */
|
|
|
|
uint8_t axis;
|
|
|
|
/* Joystick axis direction */
|
|
|
|
AxisDir dir;
|
|
|
|
} ja;
|
2014-12-31 15:39:28 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
/* Joystick axis index */
|
|
|
|
uint8_t hat;
|
|
|
|
/* Joystick axis direction */
|
|
|
|
uint8_t pos;
|
|
|
|
} jh;
|
2014-01-25 08:24:55 +00:00
|
|
|
} d;
|
|
|
|
|
|
|
|
bool operator==(const SourceDesc &o) const
|
|
|
|
{
|
|
|
|
if (type != o.type)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case Invalid:
|
|
|
|
return true;
|
|
|
|
case Key:
|
|
|
|
return d.scan == o.d.scan;
|
2015-09-04 05:53:41 +00:00
|
|
|
case CButton:
|
2014-01-25 08:24:55 +00:00
|
|
|
case JButton:
|
|
|
|
return d.jb == o.d.jb;
|
2015-09-04 05:53:41 +00:00
|
|
|
case CAxis:
|
2014-01-25 08:24:55 +00:00
|
|
|
case JAxis:
|
|
|
|
return (d.ja.axis == o.d.ja.axis) && (d.ja.dir == o.d.ja.dir);
|
2014-12-31 15:39:28 +00:00
|
|
|
case JHat:
|
|
|
|
return (d.jh.hat == o.d.jh.hat) && (d.jh.pos == o.d.jh.pos);
|
2014-01-25 08:24:55 +00:00
|
|
|
default:
|
|
|
|
assert(!"unreachable");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const SourceDesc &o) const
|
|
|
|
{
|
|
|
|
return !(*this == o);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define JAXIS_THRESHOLD 0x4000
|
|
|
|
|
|
|
|
struct BindingDesc
|
|
|
|
{
|
|
|
|
SourceDesc src;
|
|
|
|
Input::ButtonCode target;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<BindingDesc> BDescVec;
|
|
|
|
struct Config;
|
|
|
|
|
2015-09-03 02:41:25 +00:00
|
|
|
BDescVec genDefaultBindings();
|
2014-01-25 08:24:55 +00:00
|
|
|
|
|
|
|
void storeBindings(const BDescVec &d, const Config &conf);
|
|
|
|
BDescVec loadBindings(const Config &conf);
|
|
|
|
|
|
|
|
#endif // KEYBINDINGS_H
|