Ardour  8.12
ardour_button.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef _WIDGETS_ARDOUR_BUTTON_H_
21 #define _WIDGETS_ARDOUR_BUTTON_H_
22 
23 #include <list>
24 #include <stdint.h>
25 
26 #include <gtkmm/action.h>
27 
28 #include "pbd/signals.h"
29 #include "gtkmm2ext/activatable.h"
30 #include "gtkmm2ext/cairo_widget.h"
31 
32 #include "widgets/ardour_icon.h"
33 #include "widgets/binding_proxy.h"
34 #include "widgets/visibility.h"
35 
36 namespace ArdourWidgets {
37 
39 {
40  public:
41  enum Element {
42  Edge = 0x1,
43  Body = 0x2,
44  Text = 0x4,
45  Indicator = 0x8,
46  ColorBox = 0x18, //also sets Indicator
47  Menu = 0x20,
48  Inactive = 0x40, // no _action is defined AND state is not used
49  VectorIcon = 0x80,
50  IconRenderCallback = 0x100,
51  };
52 
53  typedef void (* rendercallback_t) (cairo_t*, int, int, uint32_t, void*);
54 
58 
59  ArdourButton (Element e = default_elements, bool toggle = false);
60  ArdourButton (const std::string&, Element e = default_elements, bool toggle = false);
61  virtual ~ArdourButton ();
62 
63  enum Tweaks {
64  Square = 0x1,
65  TrackHeader = 0x2,
66  OccasionalText = 0x4,
67  OccasionalLED = 0x8,
68  ForceBoxy = 0x10,
69  ForceFlat = 0x20,
70  };
71 
73  static void set_default_tweaks (Tweaks t) { default_tweaks = t; }
74 
75  Tweaks tweaks() const { return _tweaks; }
77 
80 
81  void set_custom_led_color (const uint32_t c, const bool useit = true);
82 
83  void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
84 
85  Element elements() const { return _elements; }
88 
89  ArdourIcon::Icon icon() const { return _icon; }
91  void set_icon (rendercallback_t, void*);
92 
93  void set_corner_radius (float);
94 
95  void set_text (const std::string&, bool markup = false);
96  const std::string& get_text () const { return _text; }
97  bool get_markup () const { return _markup; }
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 
106  void set_layout_font (const Pango::FontDescription&);
107  void set_text_ellipsize (Pango::EllipsizeMode);
108  void set_width_padding (float);
109 
110  /* Sets the text used for size request computation. Pass an
111  * empty string to return to the default behavior which uses
112  * the currently displayed text for measurement. */
113  void set_sizing_text (std::string const&);
114  void set_sizing_texts (std::vector<std::string> const&);
115 
116  sigc::signal<void, GdkEventButton*> signal_led_clicked;
117  sigc::signal<void> signal_clicked;
118 
119  std::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
120  void set_controllable (std::shared_ptr<PBD::Controllable> c);
121  void watch ();
122 
123  void set_related_action (Glib::RefPtr<Gtk::Action>);
124 
127 
128  void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
129 
130  void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
131  void set_active_color (const uint32_t active_color);
132  void set_inactive_color (const uint32_t inactive_color);
134 
135  void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; }
136 
137  unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
138  unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
139  float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
140 
141  protected:
142  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
145  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
147  void on_realize ();
155 
158 
159  protected:
160  Glib::RefPtr<Pango::Layout> _layout;
161  Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
162  std::string _text;
163  std::vector<std::string> _sizing_texts;
164  bool _markup;
167  rendercallback_t _icon_render_cb;
171 
174 
175  unsigned int _char_pixel_width;
176  unsigned int _char_pixel_height;
180 
183  float _diameter;
186 
187  double _angle;
188  float _xalign, _yalign;
189 
192 
195 
200 
201  uint32_t outline_color;
202 
203 
204  cairo_pattern_t* convex_pattern;
205  cairo_pattern_t* concave_pattern;
206  cairo_pattern_t* led_inset_pattern;
207  cairo_rectangle_t* _led_rect;
208 
211  bool _led_left;
213  bool _hovering;
214  bool _focused;
218  Pango::EllipsizeMode _ellipsis;
221 
222  void setup_led_rect ();
223  void set_colors ();
224  void color_handler ();
225  void build_patterns ();
226  void ensure_layout ();
227 
228  void action_toggled ();
232 };
233 
234 } /* end namespace */
235 
236 #endif
void set_icon(rendercallback_t, void *)
rendercallback_t _icon_render_cb
void on_realize()
This is a default handler for the signal signal_realize().
bool on_grab_broken_event(GdkEventGrabBroken *)
void set_sizing_text(std::string const &)
void set_image(const Glib::RefPtr< Gdk::Pixbuf > &)
void set_active_state(Gtkmm2ext::ActiveState)
void set_angle(const double)
void set_act_on_release(bool onRelease)
Definition: ardour_button.h:83
static Element led_default_elements
Definition: ardour_button.h:56
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
cairo_pattern_t * concave_pattern
Glib::RefPtr< Pango::Layout > _layout
void set_inactive_color(const uint32_t inactive_color)
Glib::RefPtr< Gdk::Pixbuf > _pixbuf
PBD::ScopedConnection watch_connection
unsigned int char_pixel_width()
sigc::signal< void, GdkEventButton * > signal_led_clicked
bool on_focus_in_event(GdkEventFocus *)
This is a default handler for the signal signal_focus_in_event().
bool on_key_press_event(GdkEventKey *)
This is a default handler for the signal signal_key_press_event().
cairo_pattern_t * led_inset_pattern
bool on_focus_out_event(GdkEventFocus *)
This is a default handler for the signal signal_focus_out_event().
void on_size_allocate(Gtk::Allocation &)
This is a default handler for the signal signal_size_allocate().
static Element default_elements
Definition: ardour_button.h:55
ArdourButton(const std::string &, Element e=default_elements, bool toggle=false)
void set_fallthrough_to_parent(bool fall)
Pango::EllipsizeMode _ellipsis
void set_controllable(std::shared_ptr< PBD::Controllable > c)
unsigned int char_pixel_height()
bool on_enter_notify_event(GdkEventCrossing *)
This is a default handler for the signal signal_enter_notify_event().
void set_layout_font(const Pango::FontDescription &)
void get_alignment(float &xa, float &ya)
void set_layout_ellipsize_width(int w)
ArdourButton(Element e=default_elements, bool toggle=false)
void set_text(const std::string &, bool markup=false)
std::vector< std::string > _sizing_texts
bool on_key_release_event(GdkEventKey *)
This is a default handler for the signal signal_key_release_event().
void set_custom_led_color(const uint32_t c, const bool useit=true)
const std::string & get_text() const
Definition: ardour_button.h:96
void set_related_action(Glib::RefPtr< Gtk::Action >)
bool on_button_release_event(GdkEventButton *)
This is a default handler for the signal signal_button_release_event().
void set_active_color(const uint32_t active_color)
void set_alignment(const float, const float)
sigc::signal< void > signal_clicked
static void set_default_tweaks(Tweaks t)
Definition: ardour_button.h:73
void render(Cairo::RefPtr< Cairo::Context > const &, cairo_rectangle_t *)
void set_fixed_colors(const uint32_t active_color, const uint32_t inactive_color)
cairo_pattern_t * convex_pattern
void set_icon(ArdourIcon::Icon)
void set_text_ellipsize(Pango::EllipsizeMode)
cairo_rectangle_t * _led_rect
ArdourIcon::Icon icon() const
Definition: ardour_button.h:89
void set_distinct_led_click(bool yn)
std::shared_ptr< PBD::Controllable > get_controllable()
void set_sizing_texts(std::vector< std::string > const &)
static Element just_led_default_elements
Definition: ardour_button.h:57
bool on_leave_notify_event(GdkEventCrossing *)
This is a default handler for the signal signal_leave_notify_event().
void set_visual_state(Gtkmm2ext::VisualState)
bool on_button_press_event(GdkEventButton *)
This is a default handler for the signal signal_button_press_event().
void on_size_request(Gtk::Requisition *req)
This is a default handler for the signal signal_size_request().
#define LIBWIDGETS_API