remove pixel based Button LED diameter setting
[ardour.git] / gtk2_ardour / ardour_button.h
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"
28 #include "gtkmm2ext/binding_proxy.h"
29 #include "gtkmm2ext/activatable.h"
30 #include "gtkmm2ext/cairo_widget.h"
31
32 class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
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                 RecButton = 0x80, // tentative, see commit message
44                 RecTapeMode = 0x100, // tentative
45                 CloseCross = 0x200, // tentative
46         };
47
48         static Element default_elements;
49         static Element led_default_elements;
50         static Element just_led_default_elements;
51
52         ArdourButton (Element e = default_elements);
53         ArdourButton (const std::string&, Element e = default_elements);
54         virtual ~ArdourButton ();
55
56         enum Tweaks {
57                 Square = 0x1,
58                 unused2 = 0x2,
59                 unused3 = 0x4,
60         };
61
62         Tweaks tweaks() const { return _tweaks; }
63         void set_tweaks (Tweaks);
64
65         void set_active_state (Gtkmm2ext::ActiveState);
66         void set_visual_state (Gtkmm2ext::VisualState);
67
68         void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
69
70         Element elements() const { return _elements; }
71         void set_elements (Element);
72         void add_elements (Element);
73
74         void set_corner_radius (float);
75
76         void set_text (const std::string&);
77         const std::string& get_text () {return _text;}
78         void set_angle (const double);
79         void set_alignment (const float, const float);
80         void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
81
82         void set_led_left (bool yn);
83         void set_distinct_led_click (bool yn);
84
85         void set_layout_ellisize_width (int w);
86         void set_text_ellipsize (Pango::EllipsizeMode);
87
88         sigc::signal<void> signal_led_clicked;
89         sigc::signal<void> signal_clicked;
90
91         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
92         void set_controllable (boost::shared_ptr<PBD::Controllable> c);
93         void watch ();
94
95         void set_related_action (Glib::RefPtr<Gtk::Action>);
96
97         bool on_button_press_event (GdkEventButton*);
98         bool on_button_release_event (GdkEventButton*);
99
100         void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
101
102         void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color);
103
104         void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; }
105
106         unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
107         unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
108
109         protected:
110         void render (cairo_t *, cairo_rectangle_t *);
111         void on_size_request (Gtk::Requisition* req);
112         void on_size_allocate (Gtk::Allocation&);
113         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
114         void on_name_changed ();
115         void on_realize ();
116         bool on_enter_notify_event (GdkEventCrossing*);
117         bool on_leave_notify_event (GdkEventCrossing*);
118         bool on_focus_in_event (GdkEventFocus*);
119         bool on_focus_out_event (GdkEventFocus*);
120         bool on_key_release_event (GdkEventKey *);
121
122         void controllable_changed ();
123         PBD::ScopedConnection watch_connection;
124
125         protected:
126         Glib::RefPtr<Pango::Layout> _layout;
127         Glib::RefPtr<Gdk::Pixbuf>   _pixbuf;
128         std::string                 _text;
129         Element                     _elements;
130         Tweaks                      _tweaks;
131         BindingProxy                binding_proxy;
132
133         void recalc_char_pixel_geometry ();
134         unsigned int _char_pixel_width;
135         unsigned int _char_pixel_height;
136
137         int   _text_width;
138         int   _text_height;
139         float _diameter;
140         float _corner_radius;
141         int   _corner_mask;
142
143         double _angle;
144         float _xalign, _yalign;
145
146         uint32_t fill_inactive_color;
147         uint32_t fill_active_color;
148
149         uint32_t text_active_color;
150         uint32_t text_inactive_color;
151
152         uint32_t led_active_color;
153         uint32_t led_inactive_color;
154
155         cairo_pattern_t* convex_pattern;
156         cairo_pattern_t* concave_pattern;
157         cairo_pattern_t* led_inset_pattern;
158         cairo_rectangle_t* _led_rect;
159
160         bool _act_on_release;
161         bool _led_left;
162         bool _distinct_led_click;
163         bool _hovering;
164         bool _focused;
165         bool _fixed_colors_set;
166         bool _fallthrough_to_parent;
167         int _layout_ellipsize_width;
168         Pango::EllipsizeMode _ellipsis;
169         bool _update_colors;
170         int _pattern_height;
171
172         void setup_led_rect ();
173         void set_colors ();
174         void color_handler ();
175         void build_patterns ();
176         void ensure_layout ();
177
178         void action_toggled ();
179         void action_sensitivity_changed ();
180         void action_visibility_changed ();
181         void action_tooltip_changed ();
182 };
183
184 #endif /* __gtk2_ardour_ardour_button_h__ */