2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __gtk2_ardour_ardour_button_h__
20 #define __gtk2_ardour_ardour_button_h__
25 #include <gtkmm/action.h>
27 #include "pbd/signals.h"
28 #include "gtkmm2ext/binding_proxy.h"
29 #include "gtkmm2ext/activatable.h"
30 #include "gtkmm2ext/cairo_widget.h"
32 class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
42 Inactive = 0x40, // no _action is defined AND state is not used
43 VectorIcon = 0x80, // tentative, see commit message
63 static Element default_elements;
64 static Element led_default_elements;
65 static Element just_led_default_elements;
67 ArdourButton (Element e = default_elements);
68 ArdourButton (const std::string&, Element e = default_elements);
69 virtual ~ArdourButton ();
77 Tweaks tweaks() const { return _tweaks; }
78 void set_tweaks (Tweaks);
80 void set_active_state (Gtkmm2ext::ActiveState);
81 void set_visual_state (Gtkmm2ext::VisualState);
83 void set_custom_led_color (const uint32_t c, const bool useit = true);
85 void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
87 Element elements() const { return _elements; }
88 void set_elements (Element);
89 void add_elements (Element);
91 Icon icon() const { return _icon; }
94 void set_corner_radius (float);
96 void set_text (const std::string&);
97 const std::string& get_text () {return _text;}
98 void set_angle (const double);
99 void set_alignment (const float, const float);
100 void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
102 void set_led_left (bool yn);
103 void set_distinct_led_click (bool yn);
105 void set_layout_ellipsize_width (int w);
106 void set_layout_font (const Pango::FontDescription&);
107 void set_text_ellipsize (Pango::EllipsizeMode);
109 sigc::signal<void> signal_led_clicked;
110 sigc::signal<void> signal_clicked;
112 boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
113 void set_controllable (boost::shared_ptr<PBD::Controllable> c);
116 void set_related_action (Glib::RefPtr<Gtk::Action>);
118 bool on_button_press_event (GdkEventButton*);
119 bool on_button_release_event (GdkEventButton*);
121 void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
123 void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
125 void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; }
127 unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
128 unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
129 float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
132 void render (cairo_t *, cairo_rectangle_t *);
133 void on_size_request (Gtk::Requisition* req);
134 void on_size_allocate (Gtk::Allocation&);
135 void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
136 void on_name_changed ();
138 bool on_enter_notify_event (GdkEventCrossing*);
139 bool on_leave_notify_event (GdkEventCrossing*);
140 bool on_focus_in_event (GdkEventFocus*);
141 bool on_focus_out_event (GdkEventFocus*);
142 bool on_key_release_event (GdkEventKey *);
144 void controllable_changed ();
145 PBD::ScopedConnection watch_connection;
148 Glib::RefPtr<Pango::Layout> _layout;
149 Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
154 BindingProxy binding_proxy;
156 void recalc_char_pixel_geometry ();
157 unsigned int _char_pixel_width;
158 unsigned int _char_pixel_height;
159 float _char_avg_pixel_width;
164 float _corner_radius;
168 float _xalign, _yalign;
170 uint32_t fill_inactive_color;
171 uint32_t fill_active_color;
173 uint32_t text_active_color;
174 uint32_t text_inactive_color;
176 uint32_t led_active_color;
177 uint32_t led_inactive_color;
178 uint32_t led_custom_color;
179 bool use_custom_led_color;
181 cairo_pattern_t* convex_pattern;
182 cairo_pattern_t* concave_pattern;
183 cairo_pattern_t* led_inset_pattern;
184 cairo_rectangle_t* _led_rect;
186 bool _act_on_release;
188 bool _distinct_led_click;
191 bool _fixed_colors_set;
192 bool _fallthrough_to_parent;
193 int _layout_ellipsize_width;
194 Pango::EllipsizeMode _ellipsis;
198 void setup_led_rect ();
200 void color_handler ();
201 void build_patterns ();
202 void ensure_layout ();
204 void action_toggled ();
205 void action_sensitivity_changed ();
206 void action_visibility_changed ();
207 void action_tooltip_changed ();
210 #endif /* __gtk2_ardour_ardour_button_h__ */