| 1 |
/* |
| 2 |
** jstest-gtk - A graphical joystick tester |
| 3 |
** Copyright (C) 2009 Ingo Ruhnke <[email protected]> |
| 4 |
** |
| 5 |
** This program is free software: you can redistribute it and/or modify |
| 6 |
** it under the terms of the GNU General Public License as published by |
| 7 |
** the Free Software Foundation, either version 3 of the License, or |
| 8 |
** (at your option) any later version. |
| 9 |
** |
| 10 |
** This program is distributed in the hope that it will be useful, |
| 11 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
** GNU General Public License for more details. |
| 14 |
** |
| 15 |
** You should have received a copy of the GNU General Public License |
| 16 |
** along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <gtkmm/stock.h> |
| 20 |
|
| 21 |
#include "evdev_helper.hpp" |
| 22 |
#include "joystick.hpp" |
| 23 |
#include "joystick_map_widget.hpp" |
| 24 |
|
| 25 |
JoystickMapWidget::JoystickMapWidget(Joystick& joystick) |
| 26 |
: Gtk::Dialog("Mapping: " + joystick.get_name()), |
| 27 |
label("Change the order of axis and button. The order applies directly to the " |
| 28 |
"joystick kernel driver, so it will work in any game, it is however not " |
| 29 |
"persistant across reboots."), |
| 30 |
axis_map(joystick, RemapWidget::REMAP_AXIS), |
| 31 |
button_map(joystick, RemapWidget::REMAP_BUTTON) |
| 32 |
{ |
| 33 |
set_border_width(5); |
| 34 |
label.set_line_wrap(); |
| 35 |
|
| 36 |
hbox.add(axis_map); |
| 37 |
hbox.add(button_map); |
| 38 |
|
| 39 |
get_vbox()->pack_start(label, Gtk::PACK_SHRINK); |
| 40 |
get_vbox()->pack_start(hbox, Gtk::PACK_EXPAND_WIDGET); |
| 41 |
|
| 42 |
add_button(Gtk::Stock::REVERT_TO_SAVED, 1); |
| 43 |
Gtk::Widget* close_button = add_button(Gtk::Stock::CLOSE, 0); |
| 44 |
|
| 45 |
const std::vector<int>& button_mapping = joystick.get_button_mapping(); |
| 46 |
for(std::vector<int>::const_iterator i = button_mapping.begin(); i != button_mapping.end(); ++i) |
| 47 |
{ |
| 48 |
std::ostringstream s; |
| 49 |
s << (i - button_mapping.begin()) << ": " << btn2str(*i); |
| 50 |
button_map.add_entry(*i, s.str()); |
| 51 |
} |
| 52 |
|
| 53 |
const std::vector<int>& axis_mapping = joystick.get_axis_mapping(); |
| 54 |
for(std::vector<int>::const_iterator i = axis_mapping.begin(); i != axis_mapping.end(); ++i) |
| 55 |
{ |
| 56 |
std::ostringstream s; |
| 57 |
s << (i - axis_mapping.begin()) << ": " << abs2str(*i); |
| 58 |
axis_map.add_entry(*i, s.str()); |
| 59 |
} |
| 60 |
|
| 61 |
signal_response().connect(sigc::mem_fun(this, &JoystickMapWidget::on_response)); |
| 62 |
|
| 63 |
close_button->grab_focus(); |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
JoystickMapWidget::on_response(int v) |
| 68 |
{ |
| 69 |
if (v == 0) |
| 70 |
{ |
| 71 |
hide(); |
| 72 |
} |
| 73 |
else if (v == 1) |
| 74 |
{ |
| 75 |
button_map.on_clear(); |
| 76 |
axis_map.on_clear(); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
/* EOF */ |