fix OSX compilation
[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 "ardour/automatable.h"
29
30 #include "gtkmm2ext/binding_proxy.h"
31 #include "gtkmm2ext/activatable.h"
32 #include "gtkmm2ext/cairo_widget.h"
33 #include "gtkmm2ext/persistent_tooltip.h"
34
35 class KnobPersistentTooltip : public Gtkmm2ext::PersistentTooltip
36 {
37 public:
38         KnobPersistentTooltip (Gtk::Widget* w);
39
40         void start_drag ();
41         void stop_drag ();
42         bool dragging () const;
43
44 private:
45         bool _dragging;
46 };
47
48
49 class ArdourKnob : public CairoWidget , public Gtkmm2ext::Activatable
50 {
51 public:
52
53         enum Element {
54                 Arc = 0x1,
55                 Bevel = 0x2,
56                 unused2 = 0x4,
57                 unused3 = 0x8,
58                 unused4 = 0x10,
59                 unused5 = 0x20,
60         };
61
62         enum Flags {
63                 NoFlags = 0,
64                 Detent = 0x1,
65                 ArcToZero = 0x2,
66         };
67
68         ArdourKnob (Element e = default_elements, Flags flags = NoFlags);
69         virtual ~ArdourKnob ();
70
71         void set_active_state (Gtkmm2ext::ActiveState);
72         void set_visual_state (Gtkmm2ext::VisualState);
73
74         Element elements() const { return _elements; }
75         void set_elements (Element);
76         void add_elements (Element);
77         static Element default_elements;
78
79         void set_tooltip_prefix (std::string pfx) { _tooltip_prefix = pfx; controllable_changed (true); }
80
81         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
82         void set_controllable (boost::shared_ptr<PBD::Controllable> c);
83
84         bool on_button_press_event (GdkEventButton*);
85         bool on_button_release_event (GdkEventButton*);
86         bool on_scroll_event (GdkEventScroll* ev);
87         bool on_motion_notify_event (GdkEventMotion *ev) ;
88
89         void set_printer (boost::shared_ptr<ARDOUR::Automatable> p) { _printer = p; controllable_changed (true); }
90
91         void color_handler ();
92
93   protected:
94         void render (cairo_t *, cairo_rectangle_t *);
95         void on_size_request (Gtk::Requisition* req);
96         void on_size_allocate (Gtk::Allocation&);
97         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
98         void on_name_changed ();
99         bool on_enter_notify_event (GdkEventCrossing*);
100         bool on_leave_notify_event (GdkEventCrossing*);
101         bool on_focus_in_event (GdkEventFocus*);
102         bool on_focus_out_event (GdkEventFocus*);
103
104         void controllable_changed (bool force_update = false);
105         PBD::ScopedConnection watch_connection;
106
107
108   private:
109         Element _elements;
110         BindingProxy binding_proxy;
111         boost::shared_ptr<ARDOUR::Automatable> _printer;
112
113         bool _hovering;
114         float _grabbed_x;
115         float _grabbed_y;
116
117         float _val; // current value [0..1]
118         float _normal; // default value, arc
119         float _dead_zone_delta;
120
121         Flags _flags;
122
123         void action_sensitivity_changed ();
124         void action_visibility_changed ();
125         void action_tooltip_changed ();
126
127         std::string _tooltip_prefix;
128         KnobPersistentTooltip _tooltip;
129 };
130
131 #endif /* __gtk2_ardour_ardour_knob_h__ */