and now without debug printf()
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / fader.h
1 /*
2   Copyright (C) 2006 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 __gtkmm2ext_fader_h__
21 #define __gtkmm2ext_fader_h__
22
23 #include <cmath>
24 #include <stdint.h>
25
26 #include <gtkmm/adjustment.h>
27 #include <gdkmm.h>
28 #include <gtkmm2ext/binding_proxy.h>
29 #include "gtkmm2ext/cairo_widget.h"
30
31 #include <boost/shared_ptr.hpp>
32
33 #include "gtkmm2ext/visibility.h"
34
35 namespace Gtkmm2ext {
36
37 class LIBGTKMM2EXT_API Fader : public CairoWidget
38 {
39   public:
40         Fader (Gtk::Adjustment& adjustment,
41                const Glib::RefPtr<Gdk::Pixbuf>& face_pixbuf,
42                const Glib::RefPtr<Gdk::Pixbuf>& active_face_pixbuf,
43                const Glib::RefPtr<Gdk::Pixbuf>& underlay_pixbuf,
44                const Glib::RefPtr<Gdk::Pixbuf>& handle_pixbuf,
45                const Glib::RefPtr<Gdk::Pixbuf>& active_handle_pixbuf,
46                int min_pos_x,
47                int min_pos_y,
48                int max_pos_x,
49                int max_pos_y,
50                bool read_only);
51
52         virtual ~Fader ();
53
54         void set_controllable (boost::shared_ptr<PBD::Controllable> c) { binding_proxy.set_controllable (c); }
55         void set_default_value (float);
56         void set_touch_cursor (const Glib::RefPtr<Gdk::Pixbuf>& touch_cursor);
57         void get_image_scales (double &x_scale, double &y_scale);
58
59   protected:
60         void get_handle_position (double& x, double& y);
61
62         void on_size_request (GtkRequisition*);
63         void on_size_allocate (Gtk::Allocation& alloc);
64
65         void render (cairo_t* cr, cairo_rectangle_t*);
66         bool on_button_press_event (GdkEventButton*);
67         bool on_button_release_event (GdkEventButton*);
68         bool on_motion_notify_event (GdkEventMotion*);
69         bool on_scroll_event (GdkEventScroll* ev);
70         bool on_enter_notify_event (GdkEventCrossing* ev);
71         bool on_leave_notify_event (GdkEventCrossing* ev);
72
73   protected:
74         Gtk::Adjustment& adjustment;
75         BindingProxy binding_proxy;
76
77   private:
78
79         const Glib::RefPtr<Gdk::Pixbuf> _face_pixbuf;
80         const Glib::RefPtr<Gdk::Pixbuf> _active_face_pixbuf;
81         const Glib::RefPtr<Gdk::Pixbuf> _underlay_pixbuf;
82         const Glib::RefPtr<Gdk::Pixbuf> _handle_pixbuf;
83         const Glib::RefPtr<Gdk::Pixbuf> _active_handle_pixbuf;
84         int _min_pos_x;
85         int _min_pos_y;
86         int _max_pos_x;
87         int _max_pos_y;
88
89         bool _hovering;
90
91         GdkWindow* _grab_window;
92         Gdk::Cursor *_touch_cursor;
93
94         double _grab_start_mouse_x;
95         double _grab_start_mouse_y;
96         double _grab_start_handle_x;
97         double _grab_start_handle_y;
98         double _last_drawn_x;
99         double _last_drawn_y;
100         bool _dragging;
101         float _default_value;
102         bool _read_only;
103
104         void adjustment_changed ();
105         void update_unity_position ();
106 };
107
108
109 } /* namespace */
110
111 #endif /* __gtkmm2ext_fader_h__ */