| 1 |
// SPDX-FileCopyrightText: 2009 Ingo Ruhnke <[email protected]> |
| 2 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 |
|
| 4 |
#include <gtkmm/stock.h> |
| 5 |
|
| 6 |
#include "evdev_helper.hpp" |
| 7 |
#include "joystick.hpp" |
| 8 |
#include "joystick_map_widget.hpp" |
| 9 |
|
| 10 |
JoystickMapWidget::JoystickMapWidget(Joystick& joystick) |
| 11 |
: Gtk::Dialog("Mapping: " + joystick.get_name()), |
| 12 |
label("Change the order of axis and button. The order applies directly to the " |
| 13 |
"joystick kernel driver, so it will work in any game, it is however not " |
| 14 |
"persistant across reboots."), |
| 15 |
axis_map(joystick, RemapWidget::REMAP_AXIS), |
| 16 |
button_map(joystick, RemapWidget::REMAP_BUTTON) |
| 17 |
{ |
| 18 |
set_border_width(5); |
| 19 |
label.set_line_wrap(); |
| 20 |
|
| 21 |
hbox.add(axis_map); |
| 22 |
hbox.add(button_map); |
| 23 |
|
| 24 |
get_vbox()->pack_start(label, Gtk::PACK_SHRINK); |
| 25 |
get_vbox()->pack_start(hbox, Gtk::PACK_EXPAND_WIDGET); |
| 26 |
|
| 27 |
add_button(Gtk::Stock::REVERT_TO_SAVED, 1); |
| 28 |
Gtk::Widget* close_button = add_button(Gtk::Stock::CLOSE, 0); |
| 29 |
|
| 30 |
const std::vector<int>& button_mapping = joystick.get_button_mapping(); |
| 31 |
for(std::vector<int>::const_iterator i = button_mapping.begin(); i != button_mapping.end(); ++i) |
| 32 |
{ |
| 33 |
std::ostringstream s; |
| 34 |
s << (i - button_mapping.begin()) << ": " << btn2str(*i); |
| 35 |
button_map.add_entry(*i, s.str()); |
| 36 |
} |
| 37 |
|
| 38 |
const std::vector<int>& axis_mapping = joystick.get_axis_mapping(); |
| 39 |
for(std::vector<int>::const_iterator i = axis_mapping.begin(); i != axis_mapping.end(); ++i) |
| 40 |
{ |
| 41 |
std::ostringstream s; |
| 42 |
s << (i - axis_mapping.begin()) << ": " << abs2str(*i); |
| 43 |
axis_map.add_entry(*i, s.str()); |
| 44 |
} |
| 45 |
|
| 46 |
signal_response().connect(sigc::mem_fun(this, &JoystickMapWidget::on_response)); |
| 47 |
|
| 48 |
close_button->grab_focus(); |
| 49 |
} |
| 50 |
|
| 51 |
void |
| 52 |
JoystickMapWidget::on_response(int v) |
| 53 |
{ |
| 54 |
if (v == 0) |
| 55 |
{ |
| 56 |
hide(); |
| 57 |
} |
| 58 |
else if (v == 1) |
| 59 |
{ |
| 60 |
button_map.on_clear(); |
| 61 |
axis_map.on_clear(); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/* EOF */ |