Ardour  9.0-pre0-1467-gc8540a5ad6
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 <ytkmm/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 = 0x001,
43  Body = 0x002,
44  Text = 0x004,
45  Indicator = 0x008,
46  ColorBox = 0x018, // also sets Indicator
47  Menu = 0x020,
48  MetaMenu = 0x040,
49  Inactive = 0x080, // no _action is defined AND state is not used
50  VectorIcon = 0x100,
51  IconRenderCallback = 0x200,
52  };
53 
54  typedef void (* rendercallback_t) (cairo_t*, int, int, uint32_t, void*);
55 
59 
60  ArdourButton (Element e = default_elements, bool toggle = false);
61  ArdourButton (const std::string&, Element e = default_elements, bool toggle = false);
62  virtual ~ArdourButton ();
63 
64  enum Tweaks {
65  Square = 0x001,
66  TrackHeader = 0x002,
67  OccasionalText = 0x004,
68  OccasionalLED = 0x008,
69  ForceBoxy = 0x010,
70  ForceFlat = 0x020,
71  ExpandtoSquare = 0x040,
72  TransportIcon = 0x080,
73  NoConcave = 0x100,
74  EnforceMinHeight = 0x200,
75  };
76 
78  static void set_default_tweaks (Tweaks t) { default_tweaks = t; }
79 
80  Tweaks tweaks() const { return _tweaks; }
82 
85 
86  void set_custom_led_color (const uint32_t c, const bool useit = true);
87 
88  void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
89 
90  Element elements() const { return _elements; }
94 
95  ArdourIcon::Icon icon() const { return _icon; }
97  void set_icon (rendercallback_t, void*);
98 
99  enum CornerMask {
100  NONE = 0x0,
101  TOP_LEFT = 0x1,
102  TOP_RIGHT = 0x2,
103  BOTTOM_LEFT = 0x4,
104  BOTTOM_RIGHT = 0x8,
105  TOP = 0x3,
106  BOTTOM = 0xC,
107  LEFT = 0x5,
108  RIGHT = 0xA
109  };
110 
111  void set_corner_radius (float);
112  void set_corner_mask (int);
113 
114  void set_text (const std::string&, bool markup = false);
115  const std::string& get_text () const { return _text; }
116  bool get_markup () const { return _markup; }
117  void set_angle (const double);
118  void set_alignment (const float, const float);
119  void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
120 
121  void set_led_left (bool yn);
122  void set_distinct_led_click (bool yn);
123 
125  void set_layout_font (const Pango::FontDescription&);
126  void set_text_ellipsize (Pango::EllipsizeMode);
127  void set_width_padding (float);
128 
129  /* Sets the text used for size request computation. Pass an
130  * empty string to return to the default behavior which uses
131  * the currently displayed text for measurement. */
132  void set_sizing_text (std::string const&);
133  void add_sizing_text (std::string const&);
134  void set_sizing_texts (std::vector<std::string> const&);
135 
137  sigc::signal<void, GdkEventButton*> signal_led_clicked;
138  sigc::signal<void> signal_clicked;
139 
140  std::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
141  void set_controllable (std::shared_ptr<PBD::Controllable> c);
142  void watch ();
143 
144  void set_related_action (Glib::RefPtr<Gtk::Action>);
145 
150 
151  void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
152 
153  void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
154  void set_active_color (const uint32_t active_color);
155  void set_inactive_color (const uint32_t inactive_color);
157 
158  void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; }
159 
160  unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
161  unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
162  float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
163 
164  protected:
165  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
168  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
170  void on_realize ();
178 
181 
182  protected:
183  Glib::RefPtr<Pango::Layout> _layout;
184  Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
185  std::string _text;
186  std::vector<std::string> _sizing_texts;
187  bool _markup;
190  rendercallback_t _icon_render_cb;
194 
197 
198  unsigned int _char_pixel_width;
199  unsigned int _char_pixel_height;
203 
206  float _diameter;
209 
210  double _angle;
211  float _xalign, _yalign;
212 
215 
218 
223 
224  uint32_t outline_color;
225 
226  std::optional<int> _squaresize;
227 
228  cairo_pattern_t* convex_pattern;
229  cairo_pattern_t* concave_pattern;
230  cairo_pattern_t* led_inset_pattern;
231  cairo_rectangle_t* _led_rect;
232 
235  bool _led_left;
237  bool _hovering;
238  bool _touching;
239  bool _focused;
243  Pango::EllipsizeMode _ellipsis;
246 
247  void setup_led_rect ();
248  void set_colors ();
249  void color_handler ();
250  void build_patterns ();
251  void ensure_layout ();
252 
253  void action_toggled ();
257 };
258 
259 } /* end namespace */
260 
261 #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:88
static Element led_default_elements
Definition: ardour_button.h:57
void add_sizing_text(std::string const &)
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:56
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 is_led_click(GdkEventButton *)
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
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:78
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:95
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:58
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().
@ NONE
Definition: time.h:31
#define LIBWIDGETS_API