tweaks for the monitor section. refactoring of some buttons, using new ArdourKnob...
[ardour.git] / gtk2_ardour / ardour_knob.h
1 /*
2     Copyright (C) 2014 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_knob_h__
20 #define __gtk2_ardour_ardour_knob_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 ArdourKnob : public CairoWidget , public Gtkmm2ext::Activatable
33 {
34 public:
35
36         enum Element {
37                 Arc = 0x1,
38                 Bevel = 0x2,
39                 unused2 = 0x4,
40                 unused3 = 0x8,
41                 unused4 = 0x10,
42                 unused5 = 0x20,
43         };
44
45         ArdourKnob (Element e = default_elements);
46         virtual ~ArdourKnob ();
47
48         void set_active_state (Gtkmm2ext::ActiveState);
49         void set_visual_state (Gtkmm2ext::VisualState);
50
51         Element elements() const { return _elements; }
52         void set_elements (Element);
53         void add_elements (Element);
54         static Element default_elements;
55
56         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
57         void set_controllable (boost::shared_ptr<PBD::Controllable> c);
58
59         bool on_button_press_event (GdkEventButton*);
60         bool on_button_release_event (GdkEventButton*);
61         bool on_scroll_event (GdkEventScroll* ev);
62         bool on_motion_notify_event (GdkEventMotion *ev) ;
63
64         void color_handler ();
65
66   protected:
67         void render (cairo_t *, cairo_rectangle_t *);
68         void on_size_request (Gtk::Requisition* req);
69         void on_size_allocate (Gtk::Allocation&);
70         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
71         void on_name_changed ();
72         bool on_enter_notify_event (GdkEventCrossing*);
73         bool on_leave_notify_event (GdkEventCrossing*);
74         bool on_focus_in_event (GdkEventFocus*);
75         bool on_focus_out_event (GdkEventFocus*);
76
77         void controllable_changed ();
78         PBD::ScopedConnection watch_connection;
79
80
81   private:
82         Element                     _elements;
83
84         BindingProxy                binding_proxy;
85
86         bool _hovering;
87         bool _grabbed;
88         float _grabbed_y;
89
90         float _val;  //percent of knob travel
91
92         void action_sensitivity_changed ();
93         void action_visibility_changed ();
94         void action_tooltip_changed ();
95 };
96
97 #endif /* __gtk2_ardour_ardour_knob_h__ */