Ardour  9.0-pre0-582-g084a23a80d
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 = 0x01,
65  TrackHeader = 0x02,
66  OccasionalText = 0x04,
67  OccasionalLED = 0x08,
68  ForceBoxy = 0x10,
69  ForceFlat = 0x20,
70  ExpandtoSquare = 0x40,
71  };
72 
74  static void set_default_tweaks (Tweaks t) { default_tweaks = t; }
75 
76  Tweaks tweaks() const { return _tweaks; }
78 
81 
82  void set_custom_led_color (const uint32_t c, const bool useit = true);
83 
84  void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
85 
86  Element elements() const { return _elements; }
89 
90  ArdourIcon::Icon icon() const { return _icon; }
92  void set_icon (rendercallback_t, void*);
93 
94  void set_corner_radius (float);
95 
96  void set_text (const std::string&, bool markup = false);
97  const std::string& get_text () const { return _text; }
98  bool get_markup () const { return _markup; }
99  void set_angle (const double);
100  void set_alignment (const float, const float);
101  void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
102 
103  void set_led_left (bool yn);
104  void set_distinct_led_click (bool yn);
105 
107  void set_layout_font (const Pango::FontDescription&);
108  void set_text_ellipsize (Pango::EllipsizeMode);
109  void set_width_padding (float);
110 
111  /* Sets the text used for size request computation. Pass an
112  * empty string to return to the default behavior which uses
113  * the currently displayed text for measurement. */
114  void set_sizing_text (std::string const&);
115  void set_sizing_texts (std::vector<std::string> const&);
116 
117  sigc::signal<void, GdkEventButton*> signal_led_clicked;
118  sigc::signal<void> signal_clicked;
119 
120  std::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
121  void set_controllable (std::shared_ptr<PBD::Controllable> c);
122  void watch ();
123 
124  void set_related_action (Glib::RefPtr<Gtk::Action>);
125 
130 
131  void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
132 
133  void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
134  void set_active_color (const uint32_t active_color);
135  void set_inactive_color (const uint32_t inactive_color);
137 
138  void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; }
139 
140  unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
141  unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
142  float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
143 
144  protected:
145  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
148  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
150  void on_realize ();
158 
161 
162  protected:
163  Glib::RefPtr<Pango::Layout> _layout;
164  Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
165  std::string _text;
166  std::vector<std::string> _sizing_texts;
167  bool _markup;
170  rendercallback_t _icon_render_cb;
174 
177 
178  unsigned int _char_pixel_width;
179  unsigned int _char_pixel_height;
183 
186  float _diameter;
189 
190  double _angle;
191  float _xalign, _yalign;
192 
195 
198 
203 
204  uint32_t outline_color;
205 
206  std::optional<int> _squaresize;
207 
208  cairo_pattern_t* convex_pattern;
209  cairo_pattern_t* concave_pattern;
210  cairo_pattern_t* led_inset_pattern;
211  cairo_rectangle_t* _led_rect;
212 
215  bool _led_left;
217  bool _hovering;
218  bool _focused;
222  Pango::EllipsizeMode _ellipsis;
225 
226  void setup_led_rect ();
227  void set_colors ();
228  void color_handler ();
229  void build_patterns ();
230  void ensure_layout ();
231 
232  void action_toggled ();
236 };
237 
238 } /* end namespace */
239 
240 #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)
bool on_touch_begin_event(GdkEventTouch *)
void set_act_on_release(bool onRelease)
Definition: ardour_button.h:84
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
std::optional< int > _squaresize
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:97
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:74
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
bool on_touch_end_event(GdkEventTouch *)
ArdourIcon::Icon icon() const
Definition: ardour_button.h:90
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