provide control over precisely what aspects of an ArdourButton are rendered, and...
[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 <stdint.h>
24
25 #include <gtkmm/activatable.h>
26
27 #include "cairo_widget.h"
28
29 class ArdourButton : public CairoWidget, Gtk::Activatable
30 {
31   public:
32         enum Element {
33                 Edge = 0x1,
34                 Body = 0x2,
35                 Text = 0x4,
36                 Indicator = 0x8,
37                 Image = 0x16
38         };
39         
40         static Element default_elements;
41         static Element led_default_elements;
42
43         ArdourButton (Element e = default_elements);
44         virtual ~ArdourButton ();
45
46         void set_elements (Element);
47         Element elements() const { return _elements; }
48
49         void set_corner_radius (float);
50         void set_diameter (float);
51
52         void set_text (const std::string&);
53         void set_markup (const std::string&);
54
55         void set_led_left (bool yn);
56         void set_distinct_led_click (bool yn);
57
58         sigc::signal<void> signal_led_clicked;
59
60   protected:
61         void render (cairo_t *);
62         void on_size_request (Gtk::Requisition* req);
63         void on_size_allocate (Gtk::Allocation&);
64         bool on_button_press_event (GdkEventButton*);
65         bool on_button_release_event (GdkEventButton*);
66
67   private:
68         Element _elements;
69         Glib::RefPtr<Pango::Layout> _layout;
70         std::string _text;
71         int     _text_width;
72         int     _text_height;
73         bool    _led_left;
74         float   _diameter;
75         bool    _fixed_diameter;
76         bool    _distinct_led_click;
77         float   _corner_radius;
78
79         cairo_pattern_t* edge_pattern;
80         cairo_pattern_t* fill_pattern;
81         cairo_pattern_t* led_inset_pattern;
82         cairo_pattern_t* reflection_pattern;
83
84         double text_r;
85         double text_g;
86         double text_b;
87         double text_a;
88
89         double led_r;
90         double led_g;
91         double led_b;
92         double led_a;
93
94         void set_colors ();
95         void color_handler ();
96         void state_handler ();
97 };
98
99 #endif /* __gtk2_ardour_ardour_button_h__ */