ardour
ardour_button.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Paul Davis
3 
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.
8 
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.
13 
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.
17 */
18 
19 #ifndef __gtk2_ardour_ardour_button_h__
20 #define __gtk2_ardour_ardour_button_h__
21 
22 #include <list>
23 #include <stdint.h>
24 
25 #include <gtkmm/action.h>
26 
27 #include "pbd/signals.h"
29 #include "gtkmm2ext/activatable.h"
30 #include "gtkmm2ext/cairo_widget.h"
31 
33 {
34  public:
35  enum Element {
36  Edge = 0x1,
37  Body = 0x2,
38  Text = 0x4,
39  Indicator = 0x8,
40  unused = 0x10,
41  Menu = 0x20,
42  Inactive = 0x40, // no _action is defined AND state is not used
43  VectorIcon = 0x80, // tentative, see commit message
44  };
45 
46  enum Icon {
61  };
62 
66 
67  ArdourButton (Element e = default_elements);
68  ArdourButton (const std::string&, Element e = default_elements);
69  virtual ~ArdourButton ();
70 
71  enum Tweaks {
72  Square = 0x1,
73  TrackHeader = 0x2,
74  unused3 = 0x4,
75  };
76 
77  Tweaks tweaks() const { return _tweaks; }
78  void set_tweaks (Tweaks);
79 
80  void set_active_state (Gtkmm2ext::ActiveState);
81  void set_visual_state (Gtkmm2ext::VisualState);
82 
83  void set_custom_led_color (const uint32_t c, const bool useit = true);
84 
85  void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
86 
87  Element elements() const { return _elements; }
88  void set_elements (Element);
89  void add_elements (Element);
90 
91  Icon icon() const { return _icon; }
92  void set_icon (Icon);
93 
94  void set_corner_radius (float);
95 
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;};
101 
102  void set_led_left (bool yn);
103  void set_distinct_led_click (bool yn);
104 
105  void set_layout_ellipsize_width (int w);
106  void set_layout_font (const Pango::FontDescription&);
107  void set_text_ellipsize (Pango::EllipsizeMode);
108 
109  sigc::signal<void> signal_led_clicked;
110  sigc::signal<void> signal_clicked;
111 
114  void watch ();
115 
116  void set_related_action (Glib::RefPtr<Gtk::Action>);
117 
118  bool on_button_press_event (GdkEventButton*);
119  bool on_button_release_event (GdkEventButton*);
120 
121  void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
122 
123  void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
124 
126 
130 
131  protected:
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 ();
137  void on_realize ();
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 *);
143 
144  void controllable_changed ();
146 
147  protected:
148  Glib::RefPtr<Pango::Layout> _layout;
149  Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
150  std::string _text;
155 
157  unsigned int _char_pixel_width;
158  unsigned int _char_pixel_height;
160 
163  float _diameter;
166 
167  double _angle;
168  float _xalign, _yalign;
169 
172 
175 
180 
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;
185 
187  bool _led_left;
189  bool _hovering;
190  bool _focused;
194  Pango::EllipsizeMode _ellipsis;
197 
198  void setup_led_rect ();
199  void set_colors ();
200  void color_handler ();
201  void build_patterns ();
202  void ensure_layout ();
203 
204  void action_toggled ();
207  void action_tooltip_changed ();
208 };
209 
210 #endif /* __gtk2_ardour_ardour_button_h__ */
bool _act_on_release
void action_sensitivity_changed()
void recalc_char_pixel_geometry()
BindingProxy binding_proxy
uint32_t led_custom_color
sigc::signal< void > signal_led_clicked
bool use_custom_led_color
boost::shared_ptr< PBD::Controllable > get_controllable() const
Definition: binding_proxy.h:48
int _layout_ellipsize_width
sigc::signal< void > signal_clicked
PBD::ScopedConnection watch_connection
void action_toggled()
bool on_key_release_event(GdkEventKey *)
float _char_avg_pixel_width
void set_distinct_led_click(bool yn)
void set_act_on_release(bool onRelease)
Definition: ardour_button.h:85
void add_elements(Element)
void set_related_action(Glib::RefPtr< Gtk::Action >)
const std::string & get_text()
Definition: ardour_button.h:97
void on_size_allocate(Gtk::Allocation &)
bool on_focus_in_event(GdkEventFocus *)
uint32_t text_active_color
void get_alignment(float &xa, float &ya)
cairo_pattern_t * concave_pattern
void set_image(const Glib::RefPtr< Gdk::Pixbuf > &)
Element elements() const
Definition: ardour_button.h:87
boost::shared_ptr< PBD::Controllable > get_controllable()
void set_tweaks(Tweaks)
void action_tooltip_changed()
void set_elements(Element)
unsigned int _char_pixel_width
float char_avg_pixel_width()
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
void set_custom_led_color(const uint32_t c, const bool useit=true)
Glib::RefPtr< Pango::Layout > _layout
cairo_pattern_t * convex_pattern
ArdourButton(Element e=default_elements)
unsigned int _char_pixel_height
bool on_leave_notify_event(GdkEventCrossing *)
std::string _text
void set_icon(Icon)
Pango::EllipsizeMode _ellipsis
void on_size_request(Gtk::Requisition *req)
Element _elements
void build_patterns()
uint32_t led_inactive_color
uint32_t text_inactive_color
void set_fixed_colors(const uint32_t active_color, const uint32_t inactive_color)
void set_controllable(boost::shared_ptr< PBD::Controllable > c)
void controllable_changed()
void set_visual_state(Gtkmm2ext::VisualState)
bool _distinct_led_click
bool on_enter_notify_event(GdkEventCrossing *)
static Element just_led_default_elements
Definition: ardour_button.h:65
void set_active_state(Gtkmm2ext::ActiveState)
void set_layout_ellipsize_width(int w)
uint32_t fill_inactive_color
void set_layout_font(const Pango::FontDescription &)
uint32_t led_active_color
Icon icon() const
Definition: ardour_button.h:91
void set_fallthrough_to_parent(bool fall)
void setup_led_rect()
unsigned int char_pixel_width()
uint32_t fill_active_color
void set_angle(const double)
bool _fixed_colors_set
bool _fallthrough_to_parent
void on_name_changed()
void set_text_ellipsize(Pango::EllipsizeMode)
void action_visibility_changed()
void color_handler()
Glib::RefPtr< Gdk::Pixbuf > _pixbuf
void set_text(const std::string &)
bool on_focus_out_event(GdkEventFocus *)
bool on_button_press_event(GdkEventButton *)
bool on_button_release_event(GdkEventButton *)
virtual ~ArdourButton()
float _corner_radius
void set_alignment(const float, const float)
Tweaks tweaks() const
Definition: ardour_button.h:77
static Element default_elements
Definition: ardour_button.h:63
void render(cairo_t *, cairo_rectangle_t *)
static Element led_default_elements
Definition: ardour_button.h:64
void ensure_layout()
cairo_rectangle_t * _led_rect
unsigned int char_pixel_height()
void set_led_left(bool yn)
void set_corner_radius(float)
cairo_pattern_t * led_inset_pattern