diff options
author | David Robillard <d@drobilla.net> | 2020-11-27 17:58:05 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-27 21:42:52 +0100 |
commit | 671f6e378274e0c4842dd2cc23d47efb17978181 (patch) | |
tree | c7b62780a1fcddd7e7f9b1c67696713a747aafc4 | |
parent | c9201b59713f400c72f5a160c2e858987d466351 (diff) | |
download | patchage-671f6e378274e0c4842dd2cc23d47efb17978181.tar.gz patchage-671f6e378274e0c4842dd2cc23d47efb17978181.tar.bz2 patchage-671f6e378274e0c4842dd2cc23d47efb17978181.zip |
Move Legend implementation to a separate source file
-rw-r--r-- | src/Legend.cpp | 85 | ||||
-rw-r--r-- | src/Legend.hpp | 62 | ||||
-rw-r--r-- | wscript | 1 |
3 files changed, 94 insertions, 54 deletions
diff --git a/src/Legend.cpp b/src/Legend.cpp new file mode 100644 index 0000000..f57cc1e --- /dev/null +++ b/src/Legend.cpp @@ -0,0 +1,85 @@ +/* This file is part of Patchage. + * Copyright 2014-2020 David Robillard <d@drobilla.net> + * + * Patchage is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Patchage is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License + * along with Patchage. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "Legend.hpp" + +#include "Configuration.hpp" + +#include <gtkmm/box.h> +#include <gtkmm/colorbutton.h> +#include <gtkmm/label.h> +#include <sigc++/sigc++.h> + +#include <string> + +Legend::Legend(const Configuration& configuration) +{ + add_button(PortType::jack_audio, + "Audio", + configuration.get_port_color(PortType::jack_audio)); + +#ifdef HAVE_JACK_METADATA + add_button(PortType::jack_cv, + "CV", + configuration.get_port_color(PortType::jack_cv)); + add_button(PortType::jack_osc, + "OSC", + configuration.get_port_color(PortType::jack_osc)); +#endif + + add_button(PortType::jack_midi, + "MIDI", + configuration.get_port_color(PortType::jack_midi)); + + add_button(PortType::alsa_midi, + "ALSA MIDI", + configuration.get_port_color(PortType::alsa_midi)); + + show_all_children(); +} + +void +Legend::add_button(const PortType id, const std::string& label, uint32_t rgba) +{ + Gdk::Color col; + col.set_rgb(((rgba >> 24) & 0xFF) * 0x100, + ((rgba >> 16) & 0xFF) * 0x100, + ((rgba >> 8) & 0xFF) * 0x100); + + auto* box = new Gtk::HBox(); + auto* but = new Gtk::ColorButton(col); + but->set_use_alpha(false); + but->signal_color_set().connect( + sigc::bind(sigc::mem_fun(this, &Legend::on_color_set), id, label, but)); + + box->pack_end(*Gtk::manage(but)); + box->pack_end(*Gtk::manage(new Gtk::Label(label)), false, false, 2); + + this->pack_start(*Gtk::manage(box), false, false, 6); +} + +void +Legend::on_color_set(const PortType id, + const std::string& label, + const Gtk::ColorButton* but) +{ + const Gdk::Color col = but->get_color(); + const uint32_t rgba = + (((col.get_red() / 0x100) << 24) | ((col.get_green() / 0x100) << 16) | + ((col.get_blue() / 0x100) << 8) | 0xFF); + + signal_color_changed.emit(id, label, rgba); +} diff --git a/src/Legend.hpp b/src/Legend.hpp index cb05faf..c1563e9 100644 --- a/src/Legend.hpp +++ b/src/Legend.hpp @@ -1,5 +1,5 @@ /* This file is part of Patchage. - * Copyright 2014 David Robillard <http://drobilla.net> + * Copyright 2014-2020 David Robillard <d@drobilla.net> * * Patchage is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -21,66 +21,20 @@ #include <gtkmm/box.h> #include <gtkmm/colorbutton.h> -#include <gtkmm/label.h> +#include <sigc++/sigc++.h> + +#include <string> class Legend : public Gtk::HBox { public: - explicit Legend(const Configuration& configuration) - { - add_button(PortType::jack_audio, - "Audio", - configuration.get_port_color(PortType::jack_audio)); - -#ifdef HAVE_JACK_METADATA - add_button(PortType::jack_cv, - "CV", - configuration.get_port_color(PortType::jack_cv)); - add_button(PortType::jack_osc, - "OSC", - configuration.get_port_color(PortType::jack_osc)); -#endif - - add_button(PortType::jack_midi, - "MIDI", - configuration.get_port_color(PortType::jack_midi)); - - add_button(PortType::alsa_midi, - "ALSA MIDI", - configuration.get_port_color(PortType::alsa_midi)); + explicit Legend(const Configuration& configuration); - show_all_children(); - } + void add_button(PortType id, const std::string& label, uint32_t rgba); - void add_button(const PortType id, const std::string& label, uint32_t rgba) - { - Gdk::Color col; - col.set_rgb(((rgba >> 24) & 0xFF) * 0x100, - ((rgba >> 16) & 0xFF) * 0x100, - ((rgba >> 8) & 0xFF) * 0x100); - auto* box = new Gtk::HBox(); - auto* but = new Gtk::ColorButton(col); - but->set_use_alpha(false); - but->signal_color_set().connect(sigc::bind( - sigc::mem_fun(this, &Legend::on_color_set), id, label, but)); - - box->pack_end(*Gtk::manage(but)); - box->pack_end(*Gtk::manage(new Gtk::Label(label)), false, false, 2); - - this->pack_start(*Gtk::manage(box), false, false, 6); - } - - void on_color_set(const PortType id, + void on_color_set(PortType id, const std::string& label, - const Gtk::ColorButton* but) - { - const Gdk::Color col = but->get_color(); - const uint32_t rgba = (((col.get_red() / 0x100) << 24) | - ((col.get_green() / 0x100) << 16) | - ((col.get_blue() / 0x100) << 8) | 0xFF); - - signal_color_changed.emit(id, label, rgba); - } + const Gtk::ColorButton* but); sigc::signal<void, PortType, std::string, uint32_t> signal_color_changed; }; @@ -237,6 +237,7 @@ def build(bld): install_path = '${BINDIR}') prog.source = ''' src/Configuration.cpp + src/Legend.cpp src/Patchage.cpp src/PatchageCanvas.cpp src/PatchageEvent.cpp |