revert 29b1e706ddaeaec5a330cf6643816ec43024b545 and then redo separation of ArdourBut...
[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                 FlatFace = 0x10,
41         };
42
43         static Element default_elements;
44         static Element led_default_elements;
45         static Element just_led_default_elements;
46
47         static void set_flat_buttons (bool yn);
48         static bool flat_buttons() { return _flat_buttons; }
49
50         ArdourButton (Element e = default_elements);
51         ArdourButton (const std::string&, Element e = default_elements);
52         virtual ~ArdourButton ();
53
54         enum Tweaks {
55                 ShowClick = 0x1,
56                 NoModel = 0x2,
57                 ImplicitUsesSolidColor = 0x4,
58         };
59
60         Tweaks tweaks() const { return _tweaks; }
61         void set_tweaks (Tweaks);
62
63         void set_active_state (Gtkmm2ext::ActiveState);
64         void set_visual_state (Gtkmm2ext::VisualState);
65
66         Element elements() const { return _elements; }
67         void set_elements (Element);
68         void add_elements (Element);
69         
70         void set_corner_radius (float);
71         void set_rounded_corner_mask (int);
72         void set_diameter (float);
73
74         void set_text (const std::string&);
75         void set_markup (const std::string&);
76         void set_angle (const double);
77         void set_alignment (const float, const float);
78         void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
79
80         void set_led_left (bool yn);
81         void set_distinct_led_click (bool yn);
82
83         Glib::RefPtr<Pango::Layout> layout() const { return _layout; }
84
85         sigc::signal<void> signal_led_clicked;
86         sigc::signal<void> signal_clicked;
87
88         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
89         void set_controllable (boost::shared_ptr<PBD::Controllable> c);
90         void watch ();
91
92         void set_related_action (Glib::RefPtr<Gtk::Action>);
93
94         bool on_button_press_event (GdkEventButton*);
95         bool on_button_release_event (GdkEventButton*);
96
97         void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
98
99   protected:
100         void render (cairo_t *);
101         void on_size_request (Gtk::Requisition* req);
102         void on_size_allocate (Gtk::Allocation&);
103         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
104         bool on_enter_notify_event (GdkEventCrossing*);
105         bool on_leave_notify_event (GdkEventCrossing*);
106
107         void controllable_changed ();
108         PBD::ScopedConnection watch_connection;
109
110   private:
111         Glib::RefPtr<Pango::Layout> _layout;
112         Glib::RefPtr<Gdk::Pixbuf>   _pixbuf;
113         std::string                 _text;
114         Element                     _elements;
115         Tweaks                      _tweaks;
116         BindingProxy                binding_proxy;
117
118         int   _text_width;
119         int   _text_height;
120         float _diameter;
121         float _corner_radius;
122         int   _corner_mask;
123
124         double _angle;
125         float _xalign, _yalign;
126
127         uint32_t bg_color;
128         uint32_t border_color;
129         uint32_t fill_start_inactive_color;
130         uint32_t fill_end_inactive_color;
131         uint32_t fill_start_active_color;
132         uint32_t fill_end_active_color;
133         uint32_t text_active_color;
134         uint32_t text_inactive_color;
135         uint32_t led_active_color;
136         uint32_t led_inactive_color;
137     
138         cairo_pattern_t* fill_pattern;
139         cairo_pattern_t* fill_pattern_active;
140         cairo_pattern_t* shine_pattern;
141         cairo_pattern_t* led_inset_pattern;
142         cairo_pattern_t* reflection_pattern;
143     
144         cairo_rectangle_t* _led_rect;
145
146         double text_r;
147         double text_g;
148         double text_b;
149         double text_a;
150
151         double led_r;
152         double led_g;
153         double led_b;
154         double led_a;
155
156         double active_r;
157         double active_g;
158         double active_b;
159         double active_a;
160
161         bool _act_on_release;
162         bool _led_left;
163         bool _fixed_diameter;
164         bool _distinct_led_click;
165         bool _hovering;
166     
167         static bool _flat_buttons;
168
169         void setup_led_rect ();
170         void set_colors ();
171         void color_handler ();
172         void build_patterns ();
173
174         void action_toggled ();
175
176         void action_sensitivity_changed ();
177         void action_visibility_changed ();
178         void action_tooltip_changed ();
179 };
180
181 #endif /* __gtk2_ardour_ardour_button_h__ */