Debian Codegraph @

src/joystick_map_widget.cpp

raw ◀ ▶
1 Debian patch touch this file
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. To make the order "
29 "persistent, you can use the jscal-store command provided by the joystick "
30 "package."),
31 axis_map(joystick, RemapWidget::REMAP_AXIS),
32 button_map(joystick, RemapWidget::REMAP_BUTTON)
33 {
34 set_border_width(5);
35 label.set_line_wrap();
36
37 hbox.add(axis_map);
38 hbox.add(button_map);
39
40 get_vbox()->pack_start(label, Gtk::PACK_SHRINK);
41 get_vbox()->pack_start(hbox, Gtk::PACK_EXPAND_WIDGET);
42
43 add_button(Gtk::Stock::REVERT_TO_SAVED, 1);
44 Gtk::Widget* close_button = add_button(Gtk::Stock::CLOSE, 0);
45
46 const std::vector<int>& button_mapping = joystick.get_button_mapping();
47 for(std::vector<int>::const_iterator i = button_mapping.begin(); i != button_mapping.end(); ++i)
48 {
49 std::ostringstream s;
50 s << (i - button_mapping.begin()) << ": " << btn2str(*i);
51 button_map.add_entry(*i, s.str());
52 }
53
54 const std::vector<int>& axis_mapping = joystick.get_axis_mapping();
55 for(std::vector<int>::const_iterator i = axis_mapping.begin(); i != axis_mapping.end(); ++i)
56 {
57 std::ostringstream s;
58 s << (i - axis_mapping.begin()) << ": " << abs2str(*i);
59 axis_map.add_entry(*i, s.str());
60 }
61
62 signal_response().connect(sigc::mem_fun(this, &JoystickMapWidget::on_response));
63
64 close_button->grab_focus();
65 }
66
67 void
68 JoystickMapWidget::on_response(int v)
69 {
70 if (v == 0)
71 {
72 hide();
73 }
74 else if (v == 1)
75 {
76 button_map.on_clear();
77 axis_map.on_clear();
78 }
79 }
80
81 /* EOF */