Unverified Commit dde05eb7 authored by Jérémy Viès's avatar Jérémy Viès Committed by Stephen Kitt

Upgrade to gtkmm-3.0

parent c10e47cf
......@@ -45,7 +45,7 @@ elseif(COMPILER_SUPPORTS_CXX0X)
endif()
find_package(PkgConfig REQUIRED)
pkg_search_module(GTKMM REQUIRED gtkmm-2.4)
pkg_search_module(GTKMM REQUIRED gtkmm-3.0)
pkg_search_module(SIGCPP REQUIRED sigc++-2.0)
pkg_search_module(X11 REQUIRED x11)
......
......@@ -19,30 +19,19 @@
#include "axis_widget.hpp"
AxisWidget::AxisWidget(int width, int height)
: Gtk::Alignment(Gtk::ALIGN_CENTER, Gtk::ALIGN_TOP, 0.0f, 0.0f),
: Gtk::Alignment(Gtk::ALIGN_CENTER, Gtk::ALIGN_START, 0.0f, 0.0f),
x(0), y(0)
{
//modify_bg(Gtk::STATE_NORMAL , Gdk::Color("white"));
//modify_fg(Gtk::STATE_NORMAL , Gdk::Color("black"));
add(drawingarea);
drawingarea.signal_expose_event().connect(sigc::mem_fun(this, &AxisWidget::on_my_expose_event));
drawingarea.signal_draw().connect(sigc::mem_fun(this, &AxisWidget::on_draw));
drawingarea.set_size_request(width, height);
}
bool
AxisWidget::on_my_expose_event(GdkEventExpose* event)
AxisWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Glib::RefPtr<Gdk::Window> window = drawingarea.get_window();
if(window)
{
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
if (0)
{
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->clip();
}
int w = drawingarea.get_allocation().get_width() - 10;
int h = drawingarea.get_allocation().get_height() - 10;
int px = w/2 + (w/2 * x);
......@@ -80,7 +69,6 @@ AxisWidget::on_my_expose_event(GdkEventExpose* event)
cr->move_to(px-5, py);
cr->line_to(px+5, py);
cr->stroke();
}
return true;
}
......
......@@ -32,7 +32,7 @@ private:
public:
AxisWidget(int width, int height);
bool on_my_expose_event(GdkEventExpose* event);
bool on_draw(const Cairo::RefPtr<Cairo::Context>& context) override;
void set_x_axis(double x);
void set_y_axis(double x);
......
......@@ -25,13 +25,9 @@ ButtonWidget::ButtonWidget(int width, int height, const std::string& name_)
}
bool
ButtonWidget::on_expose_event(GdkEventExpose* event)
ButtonWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Gtk::DrawingArea::on_expose_event(event);
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
Gtk::DrawingArea::on_draw(cr);
int w = get_allocation().get_width() - 10;
int h = get_allocation().get_height() - 10;
......@@ -55,7 +51,6 @@ ButtonWidget::on_expose_event(GdkEventExpose* event)
else
cr->move_to(w/2-4, h/2+3);
cr->show_text(name);
}
return true;
}
......
......@@ -30,7 +30,7 @@ private:
public:
ButtonWidget(int width, int height, const std::string& name);
bool on_expose_event(GdkEventExpose* event);
bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
void set_down(bool t);
private:
......
......@@ -33,7 +33,6 @@ CalibrateMaximumDialog::CalibrateMaximumDialog(Joystick& joystick_)
joystick.clear_calibration();
set_border_width(5);
set_has_separator(false);
label.set_line_wrap();
get_vbox()->add(label);
add_button(Gtk::Stock::CANCEL, 1);
......
......@@ -38,7 +38,7 @@ private:
public:
CalibrateMaximumDialog(Joystick& joystick);
void on_response(int v);
void on_response(int v) override;
void on_axis_move(int id, int value);
private:
......
......@@ -31,8 +31,7 @@
#include <sstream>
#include <unistd.h>
#include <linux/joystick.h>
#include <glibmm/main.h>
#include <glibmm/convert.h>
#include <glibmm.h>
#include "evdev_helper.hpp"
#include "joystick.hpp"
......@@ -139,6 +138,9 @@ Joystick::get_joysticks()
{
std::ostringstream str;
str << "/dev/input/js" << i;
if (Glib::file_test(str.str(), Glib::FILE_TEST_EXISTS))
{
Joystick joystick(str.str());
joysticks.push_back(JoystickDescription(joystick.get_filename(),
......@@ -146,6 +148,7 @@ Joystick::get_joysticks()
joystick.get_axis_count(),
joystick.get_button_count()));
}
}
catch(std::exception& err)
{
// ok
......
......@@ -38,8 +38,6 @@ JoystickCalibrationWidget::JoystickCalibrationWidget(Joystick& joystick)
buttonbox(Gtk::BUTTONBOX_SPREAD),
calibration_button("Start Calibration")
{
set_has_separator(false);
set_border_width(5);
axis_frame.set_border_width(5);
axis_table.set_border_width(5);
......@@ -69,10 +67,10 @@ JoystickCalibrationWidget::JoystickCalibrationWidget(Joystick& joystick)
{
CalibrationData data;
Gtk::SpinButton& center_min = *Gtk::manage(new Gtk::SpinButton(*Gtk::manage(data.center_min = new Gtk::Adjustment(0, -32768, 32767))));
Gtk::SpinButton& center_max = *Gtk::manage(new Gtk::SpinButton(*Gtk::manage(data.center_max = new Gtk::Adjustment(0, -32768, 32767))));
Gtk::SpinButton& range_min = *Gtk::manage(new Gtk::SpinButton(*Gtk::manage(data.range_min = new Gtk::Adjustment(0, -32768, 32767))));
Gtk::SpinButton& range_max = *Gtk::manage(new Gtk::SpinButton(*Gtk::manage(data.range_max = new Gtk::Adjustment(0, -32768, 32767))));
Gtk::SpinButton& center_min = *Gtk::manage(new Gtk::SpinButton((data.center_min = Gtk::Adjustment::create(0, -32768, 32767))));
Gtk::SpinButton& center_max = *Gtk::manage(new Gtk::SpinButton((data.center_max = Gtk::Adjustment::create(0, -32768, 32767))));
Gtk::SpinButton& range_min = *Gtk::manage(new Gtk::SpinButton((data.range_min = Gtk::Adjustment::create(0, -32768, 32767))));
Gtk::SpinButton& range_max = *Gtk::manage(new Gtk::SpinButton((data.range_max = Gtk::Adjustment::create(0, -32768, 32767))));
Gtk::CheckButton& invert = *(data.invert = Gtk::manage(new Gtk::CheckButton()));
center_min.signal_value_changed().connect(sigc::mem_fun(this, &JoystickCalibrationWidget::on_apply));
......
......@@ -20,6 +20,7 @@
#define HEADER_JOYSTICK_CALIBRATION_WIDGET_HPP
#include <gtkmm/box.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/frame.h>
#include <gtkmm/label.h>
#include <gtkmm/table.h>
......@@ -42,10 +43,10 @@ private:
struct CalibrationData {
Gtk::CheckButton* invert;
Gtk::Adjustment* center_min;
Gtk::Adjustment* center_max;
Gtk::Adjustment* range_min;
Gtk::Adjustment* range_max;
Glib::RefPtr<Gtk::Adjustment> center_min;
Glib::RefPtr<Gtk::Adjustment> center_max;
Glib::RefPtr<Gtk::Adjustment> range_min;
Glib::RefPtr<Gtk::Adjustment> range_max;
};
std::vector<CalibrationData> calibration_data;
......@@ -57,7 +58,7 @@ public:
void on_clear();
void on_apply();
void on_response(int i);
void on_response(int i) override;
void on_calibrate();
private:
......
......@@ -16,7 +16,7 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtkmm/stock.h>
#include <gtkmm.h>
#include "main.hpp"
#include "joystick.hpp"
......@@ -58,11 +58,11 @@ JoystickListWidget::JoystickListWidget()
"devices, you can view the other ones via the top tab.")
//frame("Device List"),
{
set_has_separator(false);
set_default_size(450, 310);
label.set_line_wrap();
scrolled.set_vexpand(true);
scrolled.set_border_width(5);
scrolled.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
scrolled.add(treeview);
......
......@@ -48,7 +48,7 @@ public:
void on_refresh();
void on_properties();
void on_response(int v);
void on_response(int v) override;
void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
private:
......
......@@ -30,7 +30,6 @@ JoystickMapWidget::JoystickMapWidget(Joystick& joystick)
axis_map(joystick, RemapWidget::REMAP_AXIS),
button_map(joystick, RemapWidget::REMAP_BUTTON)
{
set_has_separator(false);
set_border_width(5);
label.set_line_wrap();
......
......@@ -40,7 +40,7 @@ private:
public:
JoystickMapWidget(Joystick& joystick);
void on_response(int v);
void on_response(int v) override;
private:
JoystickMapWidget(const JoystickMapWidget&);
......
......@@ -35,7 +35,7 @@ JoystickTestWidget::JoystickTestWidget(Joystick& joystick_, bool simple_ui)
joystick(joystick_),
m_simple_ui(simple_ui),
label("<b>" + joystick.get_name() + "</b>\nDevice: " + joystick.get_filename() ,
Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER),
Gtk::ALIGN_START, Gtk::ALIGN_START),
axis_frame("Axes"),
button_frame("Buttons"),
mapping_button("Mapping"),
......
......@@ -86,7 +86,7 @@ public:
void on_calibrate();
void on_mapping();
void on_response(int v);
void on_response(int v) override;
private:
JoystickTestWidget(const JoystickTestWidget&);
......
......@@ -17,7 +17,7 @@
*/
#include <iostream>
#include <gtkmm/main.h>
#include <gtkmm.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
......@@ -36,7 +36,8 @@
Main* Main::current_ = 0;
Main::Main(const std::string& datadir_)
: datadir(datadir_),
: Gtk::Application("de.gmx.grumbel.jstest-gtk"),
datadir(datadir_),
m_simple_ui(false),
list_dialog(0)
{
......@@ -105,7 +106,7 @@ Main::on_dialog_hide(Gtk::Dialog* dialog)
}
int
Main::main(int argc, char** argv)
Main::run(int argc, char** argv)
{
typedef std::vector<std::string> DeviceFiles;
DeviceFiles device_files;
......@@ -149,15 +150,12 @@ Main::main(int argc, char** argv)
try
{
Glib::set_application_name("Joystick Test");
Glib::set_prgname("jstest-gtk");
cfg_directory = Glib::build_filename(Glib::get_user_config_dir(), Glib::get_prgname());
if (access(cfg_directory.c_str(), R_OK | W_OK) != 0 &&
mkdir(cfg_directory.c_str(), 0770) != 0)
{
throw std::runtime_error(cfg_directory + ": " + strerror(errno));
}
Gtk::Main kit(&argc, &argv);
if (device_files.empty())
{
......@@ -170,7 +168,7 @@ Main::main(int argc, char** argv)
show_device_property_dialog(*i);
}
}
Gtk::Main::run();
return Gtk::Application::run(*list_dialog, argc, argv);
}
catch(std::exception& err)
{
......@@ -215,8 +213,9 @@ int main(int argc, char** argv)
{
try
{
Main app(find_datadir());
return app.main(argc, argv);
Glib::RefPtr<Main> app = Main::create();
return app->run(argc, argv);
}
catch(std::exception& err)
{
......@@ -225,4 +224,8 @@ int main(int argc, char** argv)
}
}
Glib::RefPtr<Main> Main::create()
{
return Glib::RefPtr<Main>(new Main(find_datadir()));
}
/* EOF */
......@@ -20,12 +20,12 @@
#define HEADER_JSTEST_GTK_MAIN_HPP
#include <vector>
#include <gtkmm/dialog.h>
#include <gtkmm.h>
class Joystick;
class JoystickListWidget;
class Main
class Main : public Gtk::Application
{
private:
static Main* current_;
......@@ -54,7 +54,9 @@ public:
void show_calibration_dialog(Joystick& joystick);
void show_mapping_dialog(Joystick& joystick);
int main(int argc, char** argv);
static Glib::RefPtr<Main> create();
int run(int argc, char** argv) /* override only since gtkmm 3.4 ! */;
std::string get_cfg_directory() const { return cfg_directory; }
std::string get_data_directory() const { return datadir; }
......
......@@ -25,21 +25,9 @@ RudderWidget::RudderWidget(int width, int height)
}
bool
RudderWidget::on_expose_event(GdkEventExpose* event)
RudderWidget::on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr)
{
double p = (pos + 1.0)/2.0;
if (0)
{
get_window()->draw_rectangle(get_style()->get_fg_gc(get_state()),
true,
(get_allocation().get_width() * p) - 4, 0,
9, get_allocation().get_height()-1);
}
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
int w = get_allocation().get_width()-10;
int h = get_allocation().get_height()-10;
......@@ -62,7 +50,6 @@ RudderWidget::on_expose_event(GdkEventExpose* event)
cr->move_to(w * p, 0);
cr->line_to(w * p, h);
cr->stroke();
}
return true;
}
......
......@@ -29,7 +29,7 @@ private:
public:
RudderWidget(int width, int height);
bool on_expose_event(GdkEventExpose* event);
bool on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr) override;
void set_pos(double p);
private:
......
......@@ -28,24 +28,10 @@ ThrottleWidget::ThrottleWidget(int width, int height, bool invert_)
}
bool
ThrottleWidget::on_expose_event(GdkEventExpose* event)
ThrottleWidget::on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr)
{
double p = 1.0 - (pos + 1.0) / 2.0;
if (0)
{
int h = (get_allocation().get_height() * p);
get_window()->draw_rectangle(get_style()->get_fg_gc(get_state()),
true,
0, get_allocation().get_height() - h,
get_allocation().get_width(), h);
}
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
int w = get_allocation().get_width()-10;
int h = get_allocation().get_height()-10;
......@@ -60,7 +46,6 @@ ThrottleWidget::on_expose_event(GdkEventExpose* event)
int dh = h*p;
cr->rectangle(0, h - dh, w, dh);
cr->fill();
}
return true;
}
......
......@@ -30,7 +30,7 @@ private:
public:
ThrottleWidget(int width, int height, bool invert = false);
bool on_expose_event(GdkEventExpose* event);
bool on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr) override;
void set_pos(double p);
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment