magic knob
[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 #include "gtkmm2ext/persistent_tooltip.h"
32
33 class KnobPersistentTooltip : public Gtkmm2ext::PersistentTooltip
34 {
35 public:
36         KnobPersistentTooltip (Gtk::Widget* w);
37
38         void start_drag ();
39         void stop_drag ();
40         bool dragging () const;
41
42 private:
43         bool _dragging;
44 };
45
46
47 class ArdourKnob : public CairoWidget , public Gtkmm2ext::Activatable
48 {
49 public:
50
51         enum Element {
52                 Arc = 0x1,
53                 Bevel = 0x2,
54                 unused2 = 0x4,
55                 unused3 = 0x8,
56                 unused4 = 0x10,
57                 unused5 = 0x20,
58         };
59
60         ArdourKnob (Element e = default_elements, bool arc_to_zero = false);
61         virtual ~ArdourKnob ();
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         static Element default_elements;
70
71         void set_tooltip_prefix (std::string pfx) { _tooltip_prefix = pfx; }
72
73         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
74         void set_controllable (boost::shared_ptr<PBD::Controllable> c);
75
76         bool on_button_press_event (GdkEventButton*);
77         bool on_button_release_event (GdkEventButton*);
78         bool on_scroll_event (GdkEventScroll* ev);
79         bool on_motion_notify_event (GdkEventMotion *ev) ;
80
81         void color_handler ();
82
83   protected:
84         void render (cairo_t *, cairo_rectangle_t *);
85         void on_size_request (Gtk::Requisition* req);
86         void on_size_allocate (Gtk::Allocation&);
87         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
88         void on_name_changed ();
89         bool on_enter_notify_event (GdkEventCrossing*);
90         bool on_leave_notify_event (GdkEventCrossing*);
91         bool on_focus_in_event (GdkEventFocus*);
92         bool on_focus_out_event (GdkEventFocus*);
93
94         void controllable_changed ();
95         PBD::ScopedConnection watch_connection;
96
97
98   private:
99         Element                     _elements;
100
101         BindingProxy                binding_proxy;
102
103         bool _hovering;
104         float _grabbed_x;
105         float _grabbed_y;
106
107         float _val; // current value [0..1]
108         float _zero; // default value, arc
109         float _dead_zone_delta;
110         bool _arc_to_zero; // if false, arc starts left-edge
111
112         void action_sensitivity_changed ();
113         void action_visibility_changed ();
114         void action_tooltip_changed ();
115
116         std::string _tooltip_prefix;
117         KnobPersistentTooltip _tooltip;
118 };
119
120 #endif /* __gtk2_ardour_ardour_knob_h__ */