/* ** keybindings.h ** ** This file is part of mkxp. ** ** Copyright (C) 2014 Jonas Kulla ** ** 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 . */ #ifndef KEYBINDINGS_H #define KEYBINDINGS_H #include "input.h" #include #include #include #include enum AxisDir { Negative, Positive }; enum SourceType { Invalid, Key, JButton, JAxis }; 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; } 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; case JButton: return d.jb == o.d.jb; case JAxis: return (d.ja.axis == o.d.ja.axis) && (d.ja.dir == o.d.ja.dir); 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 BDescVec; struct Config; BDescVec genDefaultBindings(const Config &conf); void storeBindings(const BDescVec &d, const Config &conf); BDescVec loadBindings(const Config &conf); #endif // KEYBINDINGS_H