9e051b04b8738fc5bfc76f0f39458323e7b69556
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / motionfeedback.h
1 /*
2     Copyright (C) 1998-99 Paul Barton-Davis 
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the GNU General Public License as published by
5     the Free Software Foundation; either version 2 of the License, or
6     (at your option) any later version.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17     $Id: motionfeedback.h,v 1.1.1.1 2001/11/24 00:44:46 pbd Exp $
18 */
19
20 #ifndef __gtkmm2ext_motion_feedback_h__
21 #define __gtkmm2ext_motion_feedback_h__
22
23 #include "pbd/signals.h"
24
25 #include <gdkmm/pixbuf.h>
26 #include <gtkmm/box.h>
27 #include <gtkmm/label.h>
28 #include <gtkmm/eventbox.h>
29
30 #include "gtkmm2ext/visibility.h"
31 #include "gtkmm2ext/binding_proxy.h"
32 #include "gtkmm2ext/prolooks-helpers.h"
33
34 namespace Gtk {
35         class Adjustment;
36         class SpinButton;
37 }
38
39 namespace Gtkmm2ext {
40
41 class LIBGTKMM2EXT_API MotionFeedback : public Gtk::VBox
42 {
43  public:
44         enum Type {
45                 Rotary,
46                 CenterSpring,
47                 Endless
48         };
49
50         MotionFeedback (Glib::RefPtr<Gdk::Pixbuf>, 
51                         Type type,
52                         boost::shared_ptr<PBD::Controllable>,
53                         double default_value,
54                         double step_increment,
55                         double page_increment,
56                         const char *widget_name = NULL,
57                         bool with_numeric_display = true,
58                         int sub_image_width = 40,
59                         int sub_image_height = 40);
60         virtual ~MotionFeedback ();
61
62         Gtk::Widget& eventwin () { return pixwin; }
63
64         boost::shared_ptr<PBD::Controllable> controllable() const;
65         virtual void set_controllable (boost::shared_ptr<PBD::Controllable> c);
66
67         static void set_lamp_color (const std::string&);
68         
69         static Glib::RefPtr<Gdk::Pixbuf> render_pixbuf (int size);
70
71         void set_print_func(void (*pf)(char buf[32], const boost::shared_ptr<PBD::Controllable>&, void *),
72                             void *arg) {
73                 print_func = pf;
74                 print_arg = arg;
75         };
76
77  protected:
78         boost::shared_ptr<PBD::Controllable> _controllable;
79         Gtk::Label* value;
80         double default_value;
81         double step_inc;
82         double page_inc;
83
84         void pixwin_size_request (GtkRequisition *);
85
86         bool pixwin_button_press_event (GdkEventButton *);
87         bool pixwin_button_release_event (GdkEventButton *);
88         bool pixwin_motion_notify_event (GdkEventMotion *);
89         bool pixwin_key_press_event (GdkEventKey *);
90         bool pixwin_enter_notify_event (GdkEventCrossing *);
91         bool pixwin_leave_notify_event (GdkEventCrossing *);
92         bool pixwin_focus_in_event (GdkEventFocus*);
93         bool pixwin_focus_out_event (GdkEventFocus *);
94         bool pixwin_expose_event (GdkEventExpose*);
95         bool pixwin_scroll_event (GdkEventScroll*);
96
97         /* map a display value (0.0 .. 1.0) to a control
98            value (controllable->lower() .. controllable()->upper)
99         */
100         virtual double to_control_value (double) = 0;
101
102         /* map a control value (controllable->lower() .. controllable()->upper)
103            to a display value (0.0 .. 1.0)
104         */
105         virtual double to_display_value (double) = 0;
106         
107         virtual double adjust (double nominal_delta) = 0;
108
109   private:
110         Type type;
111         Gtk::EventBox      pixwin;
112         Gtk::EventBox*     value_packer;
113         Glib::RefPtr<Gdk::Pixbuf> pixbuf;
114         BindingProxy       binding_proxy;
115         static Gdk::Color* base_color;
116
117         void (*print_func) (char buf[32], const boost::shared_ptr<PBD::Controllable>&, void *);
118         void *print_arg;
119         static void default_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>&, void *);
120
121         bool   grab_is_fine;
122         double grabbed_y;
123         double grabbed_x;
124         int subwidth;
125         int subheight;
126         void controllable_value_changed ();
127         PBD::ScopedConnection controller_connection;
128
129         static void core_draw (cairo_t*, int, double, double, double, double, const GdkColor* bright, const GdkColor* dark);
130 };
131
132 } /* namespace */
133         
134 #endif // __gtkmm2ext_motion_feedback_h__