Debian Codegraph @

src/joystick_map_widget.cpp

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