introduce flat button option,which right now is on all the time. GUI nit-pickers...
[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
20 #ifndef __gtk2_ardour_ardour_button_h__
21 #define __gtk2_ardour_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/binding_proxy.h"
30 #include "gtkmm2ext/activatable.h"
31 #include "gtkmm2ext/cairo_widget.h"
32
33 class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
34 {
35   public:
36         enum Element {
37                 Edge = 0x1,
38                 Body = 0x2,
39                 Text = 0x4,
40                 Indicator = 0x8,
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 = 0x4,
57         };
58
59         Tweaks tweaks() const { return _tweaks; }
60         void set_tweaks (Tweaks);
61
62         void set_active_state (Gtkmm2ext::ActiveState);
63         void set_visual_state (Gtkmm2ext::VisualState);
64
65         Element elements() const { return _elements; }
66         void set_elements (Element);
67         
68         void set_corner_radius (float);
69         void set_rounded_corner_mask (int);
70         void set_diameter (float);
71
72         void set_text (const std::string&);
73         void set_markup (const std::string&);
74
75         void set_led_left (bool yn);
76         void set_distinct_led_click (bool yn);
77
78         Glib::RefPtr<Pango::Layout> layout() const { return _layout; }
79
80         sigc::signal<void> signal_led_clicked;
81         sigc::signal<void> signal_clicked;
82
83         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
84         void set_controllable (boost::shared_ptr<PBD::Controllable> c);
85         void watch ();
86
87         void set_related_action (Glib::RefPtr<Gtk::Action>);
88
89         bool on_button_press_event (GdkEventButton*);
90         bool on_button_release_event (GdkEventButton*);
91
92         void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
93
94   protected:
95         void render (cairo_t *);
96         void on_size_request (Gtk::Requisition* req);
97         void on_size_allocate (Gtk::Allocation&);
98         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
99         bool on_enter_notify_event (GdkEventCrossing*);
100         bool on_leave_notify_event (GdkEventCrossing*);
101
102         void controllable_changed ();
103         PBD::ScopedConnection watch_connection;
104
105   private:
106         Glib::RefPtr<Pango::Layout> _layout;
107         Glib::RefPtr<Gdk::Pixbuf>   _pixbuf;
108         std::string                 _text;
109         Element                     _elements;
110         Tweaks                      _tweaks;
111         BindingProxy                binding_proxy;
112
113         int   _text_width;
114         int   _text_height;
115         float _diameter;
116         float _corner_radius;
117         int   _corner_mask;
118
119         cairo_pattern_t* edge_pattern;
120         cairo_pattern_t* active_pattern;
121         cairo_pattern_t* inactive_pattern;
122         cairo_pattern_t* led_inset_pattern;
123         cairo_pattern_t* reflection_pattern;
124
125         cairo_rectangle_t* _led_rect;
126
127         double text_r;
128         double text_g;
129         double text_b;
130         double text_a;
131
132         double led_r;
133         double led_g;
134         double led_b;
135         double led_a;
136
137         double active_r;
138         double active_g;
139         double active_b;
140         double active_a;
141
142         bool _act_on_release;
143         bool _led_left;
144         bool _fixed_diameter;
145         bool _distinct_led_click;
146         bool _hovering;
147
148         static bool _flat_buttons;
149
150         void setup_led_rect ();
151         void set_colors ();
152         void color_handler ();
153
154         void action_toggled ();
155
156         void action_sensitivity_changed ();
157         void action_visibility_changed ();
158         void action_tooltip_changed ();
159 };
160
161 #endif /* __gtk2_ardour_ardour_button_h__ */