2011-10-26 17:01:14 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Paul Davis
|
|
|
|
|
|
|
|
This program 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 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __gtk2_ardour_ardour_button_h__
|
|
|
|
#define __gtk2_ardour_ardour_button_h__
|
|
|
|
|
2011-11-03 17:35:20 -04:00
|
|
|
#include <list>
|
2011-10-26 17:01:14 -04:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2011-10-29 11:54:30 -04:00
|
|
|
#include <gtkmm/action.h>
|
|
|
|
|
|
|
|
#include "pbd/signals.h"
|
2015-05-24 15:45:39 -04:00
|
|
|
#include "gtkmm2ext/ardour_icon.h"
|
2011-10-29 11:54:30 -04:00
|
|
|
#include "gtkmm2ext/binding_proxy.h"
|
2011-11-24 00:36:31 -05:00
|
|
|
#include "gtkmm2ext/activatable.h"
|
2011-12-07 08:57:45 -05:00
|
|
|
#include "gtkmm2ext/cairo_widget.h"
|
2011-10-26 17:01:14 -04:00
|
|
|
|
2011-11-24 00:36:31 -05:00
|
|
|
class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
|
2011-10-26 17:01:14 -04:00
|
|
|
{
|
2014-09-05 18:41:56 -04:00
|
|
|
public:
|
2011-10-27 07:53:16 -04:00
|
|
|
enum Element {
|
|
|
|
Edge = 0x1,
|
|
|
|
Body = 0x2,
|
|
|
|
Text = 0x4,
|
|
|
|
Indicator = 0x8,
|
2014-08-22 12:45:34 -04:00
|
|
|
unused = 0x10,
|
2014-03-23 19:11:42 -04:00
|
|
|
Menu = 0x20,
|
2014-08-29 15:08:49 -04:00
|
|
|
Inactive = 0x40, // no _action is defined AND state is not used
|
2017-02-17 12:26:30 -05:00
|
|
|
VectorIcon = 0x80,
|
|
|
|
IconRenderCallback = 0x100,
|
2015-04-07 15:47:04 -04:00
|
|
|
};
|
|
|
|
|
2017-02-17 12:26:30 -05:00
|
|
|
typedef void (* rendercallback_t) (cairo_t*, int, int, uint32_t, void*);
|
|
|
|
|
2011-10-27 07:53:16 -04:00
|
|
|
static Element default_elements;
|
|
|
|
static Element led_default_elements;
|
2011-10-29 11:54:30 -04:00
|
|
|
static Element just_led_default_elements;
|
2011-10-27 07:53:16 -04:00
|
|
|
|
|
|
|
ArdourButton (Element e = default_elements);
|
2011-11-03 17:35:20 -04:00
|
|
|
ArdourButton (const std::string&, Element e = default_elements);
|
2011-10-26 17:01:14 -04:00
|
|
|
virtual ~ArdourButton ();
|
|
|
|
|
2011-11-07 14:14:31 -05:00
|
|
|
enum Tweaks {
|
2014-09-03 12:56:31 -04:00
|
|
|
Square = 0x1,
|
2014-09-07 12:50:34 -04:00
|
|
|
TrackHeader = 0x2,
|
2016-06-14 11:47:25 -04:00
|
|
|
OccasionalText = 0x4,
|
|
|
|
unused4 = 0x8,
|
2011-11-07 14:14:31 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Tweaks tweaks() const { return _tweaks; }
|
|
|
|
void set_tweaks (Tweaks);
|
|
|
|
|
2011-11-03 17:35:20 -04:00
|
|
|
void set_active_state (Gtkmm2ext::ActiveState);
|
|
|
|
void set_visual_state (Gtkmm2ext::VisualState);
|
|
|
|
|
2015-03-16 23:02:59 -04:00
|
|
|
void set_custom_led_color (const uint32_t c, const bool useit = true);
|
2015-03-16 14:03:41 -04:00
|
|
|
|
2014-08-22 12:45:34 -04:00
|
|
|
void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
|
|
|
|
|
2011-10-27 07:53:16 -04:00
|
|
|
Element elements() const { return _elements; }
|
2012-02-06 13:38:02 -05:00
|
|
|
void set_elements (Element);
|
2012-12-06 15:48:44 -05:00
|
|
|
void add_elements (Element);
|
2014-09-05 18:41:56 -04:00
|
|
|
|
2015-05-24 15:45:39 -04:00
|
|
|
Gtkmm2ext::ArdourIcon::Icon icon() const { return _icon; }
|
|
|
|
void set_icon (Gtkmm2ext::ArdourIcon::Icon);
|
2017-02-17 12:26:30 -05:00
|
|
|
void set_icon (rendercallback_t, void*);
|
2015-04-07 15:47:04 -04:00
|
|
|
|
2011-10-27 07:53:16 -04:00
|
|
|
void set_corner_radius (float);
|
2011-10-26 17:01:14 -04:00
|
|
|
|
2016-12-10 09:52:48 -05:00
|
|
|
void set_text (const std::string&, bool markup = false);
|
|
|
|
const std::string& get_text () { return _text; }
|
|
|
|
bool get_markup () const { return _markup; }
|
2013-07-03 12:56:30 -04:00
|
|
|
void set_angle (const double);
|
2013-07-04 21:04:40 -04:00
|
|
|
void set_alignment (const float, const float);
|
|
|
|
void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
|
2011-10-26 17:01:14 -04:00
|
|
|
|
|
|
|
void set_led_left (bool yn);
|
|
|
|
void set_distinct_led_click (bool yn);
|
|
|
|
|
2015-03-11 14:46:22 -04:00
|
|
|
void set_layout_ellipsize_width (int w);
|
2014-10-21 17:25:50 -04:00
|
|
|
void set_layout_font (const Pango::FontDescription&);
|
2014-09-05 18:41:56 -04:00
|
|
|
void set_text_ellipsize (Pango::EllipsizeMode);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2016-08-20 09:46:41 -04:00
|
|
|
/* Sets the text used for size request computation. Pass an
|
|
|
|
* empty string to return to the default behavior which uses
|
|
|
|
* the currently displayed text for measurement. */
|
|
|
|
void set_sizing_text (const std::string&);
|
|
|
|
const std::string& get_sizing_text () {return _sizing_text;}
|
|
|
|
|
2015-10-14 06:38:44 -04:00
|
|
|
sigc::signal<void, GdkEventButton*> signal_led_clicked;
|
2011-11-11 12:24:05 -05:00
|
|
|
sigc::signal<void> signal_clicked;
|
2011-10-26 17:01:14 -04:00
|
|
|
|
2011-10-29 11:54:30 -04:00
|
|
|
boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
|
2014-09-05 18:41:56 -04:00
|
|
|
void set_controllable (boost::shared_ptr<PBD::Controllable> c);
|
2011-11-24 00:36:31 -05:00
|
|
|
void watch ();
|
2011-10-29 11:54:30 -04:00
|
|
|
|
|
|
|
void set_related_action (Glib::RefPtr<Gtk::Action>);
|
|
|
|
|
2011-11-02 12:46:49 -04:00
|
|
|
bool on_button_press_event (GdkEventButton*);
|
|
|
|
bool on_button_release_event (GdkEventButton*);
|
|
|
|
|
2011-11-02 14:47:14 -04:00
|
|
|
void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
|
|
|
|
|
2016-06-09 15:35:37 -04:00
|
|
|
void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
|
|
|
|
void set_active_color (const uint32_t active_color);
|
|
|
|
void set_inactive_color (const uint32_t inactive_color);
|
2014-08-28 15:25:19 -04:00
|
|
|
|
|
|
|
void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; }
|
2014-03-06 08:05:33 -05:00
|
|
|
|
2014-09-02 13:23:18 -04:00
|
|
|
unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
|
|
|
|
unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
|
2014-09-07 12:50:34 -04:00
|
|
|
float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
|
2014-09-02 13:23:18 -04:00
|
|
|
|
2014-09-05 18:41:56 -04:00
|
|
|
protected:
|
2014-03-20 18:50:40 -04:00
|
|
|
void render (cairo_t *, cairo_rectangle_t *);
|
2011-10-27 16:10:49 -04:00
|
|
|
void on_size_request (Gtk::Requisition* req);
|
2011-10-27 07:53:16 -04:00
|
|
|
void on_size_allocate (Gtk::Allocation&);
|
2011-10-31 11:28:21 -04:00
|
|
|
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
|
2014-03-06 09:49:00 -05:00
|
|
|
void on_name_changed ();
|
2014-09-05 18:41:56 -04:00
|
|
|
void on_realize ();
|
2011-11-07 14:14:31 -05:00
|
|
|
bool on_enter_notify_event (GdkEventCrossing*);
|
|
|
|
bool on_leave_notify_event (GdkEventCrossing*);
|
2016-08-18 10:09:50 -04:00
|
|
|
bool on_grab_broken_event(GdkEventGrabBroken*);
|
2014-06-13 17:50:07 -04:00
|
|
|
bool on_focus_in_event (GdkEventFocus*);
|
|
|
|
bool on_focus_out_event (GdkEventFocus*);
|
|
|
|
bool on_key_release_event (GdkEventKey *);
|
2011-10-26 17:01:14 -04:00
|
|
|
|
2011-11-24 00:36:31 -05:00
|
|
|
void controllable_changed ();
|
|
|
|
PBD::ScopedConnection watch_connection;
|
2011-10-29 11:54:30 -04:00
|
|
|
|
2014-09-05 18:41:56 -04:00
|
|
|
protected:
|
2011-10-26 17:01:14 -04:00
|
|
|
Glib::RefPtr<Pango::Layout> _layout;
|
2011-11-02 14:47:14 -04:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
|
2011-10-27 16:10:49 -04:00
|
|
|
std::string _text;
|
2016-08-20 09:46:41 -04:00
|
|
|
std::string _sizing_text;
|
2016-12-10 09:52:48 -05:00
|
|
|
bool _markup;
|
2011-10-27 16:10:49 -04:00
|
|
|
Element _elements;
|
2015-05-24 15:45:39 -04:00
|
|
|
Gtkmm2ext::ArdourIcon::Icon _icon;
|
2017-02-17 12:26:30 -05:00
|
|
|
rendercallback_t _icon_render_cb;
|
|
|
|
void* _icon_render_cb_data;
|
2011-11-07 14:14:31 -05:00
|
|
|
Tweaks _tweaks;
|
2011-11-24 00:36:31 -05:00
|
|
|
BindingProxy binding_proxy;
|
2011-10-27 16:10:49 -04:00
|
|
|
|
2016-12-10 09:52:48 -05:00
|
|
|
void set_text_internal ();
|
2014-09-02 13:23:18 -04:00
|
|
|
void recalc_char_pixel_geometry ();
|
|
|
|
unsigned int _char_pixel_width;
|
|
|
|
unsigned int _char_pixel_height;
|
2014-09-07 12:50:34 -04:00
|
|
|
float _char_avg_pixel_width;
|
2014-09-02 13:23:18 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
int _text_width;
|
|
|
|
int _text_height;
|
|
|
|
float _diameter;
|
|
|
|
float _corner_radius;
|
2012-02-02 23:17:25 -05:00
|
|
|
int _corner_mask;
|
2011-10-26 17:01:14 -04:00
|
|
|
|
2013-07-03 12:56:30 -04:00
|
|
|
double _angle;
|
2013-07-04 21:04:40 -04:00
|
|
|
float _xalign, _yalign;
|
2013-07-03 12:56:30 -04:00
|
|
|
|
2014-08-22 12:45:34 -04:00
|
|
|
uint32_t fill_inactive_color;
|
|
|
|
uint32_t fill_active_color;
|
|
|
|
|
|
|
|
uint32_t text_active_color;
|
|
|
|
uint32_t text_inactive_color;
|
|
|
|
|
|
|
|
uint32_t led_active_color;
|
|
|
|
uint32_t led_inactive_color;
|
2015-03-16 14:03:41 -04:00
|
|
|
uint32_t led_custom_color;
|
|
|
|
bool use_custom_led_color;
|
2014-09-05 18:41:56 -04:00
|
|
|
|
2014-08-22 12:45:34 -04:00
|
|
|
cairo_pattern_t* convex_pattern;
|
|
|
|
cairo_pattern_t* concave_pattern;
|
2011-10-26 17:01:14 -04:00
|
|
|
cairo_pattern_t* led_inset_pattern;
|
2011-11-24 00:36:31 -05:00
|
|
|
cairo_rectangle_t* _led_rect;
|
|
|
|
|
|
|
|
bool _act_on_release;
|
2011-10-27 16:10:49 -04:00
|
|
|
bool _led_left;
|
|
|
|
bool _distinct_led_click;
|
2011-11-07 14:14:31 -05:00
|
|
|
bool _hovering;
|
2014-06-13 17:50:07 -04:00
|
|
|
bool _focused;
|
2016-06-09 15:35:37 -04:00
|
|
|
int _fixed_colors_set;
|
2014-08-28 15:25:19 -04:00
|
|
|
bool _fallthrough_to_parent;
|
2014-09-05 18:41:56 -04:00
|
|
|
int _layout_ellipsize_width;
|
|
|
|
Pango::EllipsizeMode _ellipsis;
|
2014-09-05 20:04:59 -04:00
|
|
|
bool _update_colors;
|
|
|
|
int _pattern_height;
|
2014-09-05 18:41:56 -04:00
|
|
|
|
2011-10-31 14:32:19 -04:00
|
|
|
void setup_led_rect ();
|
2011-10-27 16:10:49 -04:00
|
|
|
void set_colors ();
|
2011-10-26 17:01:14 -04:00
|
|
|
void color_handler ();
|
2014-09-05 18:41:56 -04:00
|
|
|
void build_patterns ();
|
|
|
|
void ensure_layout ();
|
2011-10-29 11:54:30 -04:00
|
|
|
|
|
|
|
void action_toggled ();
|
2011-11-10 13:04:34 -05:00
|
|
|
void action_sensitivity_changed ();
|
|
|
|
void action_visibility_changed ();
|
|
|
|
void action_tooltip_changed ();
|
2011-10-26 17:01:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __gtk2_ardour_ardour_button_h__ */
|