Merge branch 'master' into windows
[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/binding_proxy.h"
31 #include "gtkmm2ext/prolooks-helpers.h"
32
33 namespace Gtk {
34         class Adjustment;
35         class SpinButton;
36 }
37
38 namespace Gtkmm2ext {
39
40 class MotionFeedback : public Gtk::VBox
41 {
42  public:
43         enum Type {
44                 Rotary,
45                 CenterSpring,
46                 Endless
47         };
48
49         MotionFeedback (Glib::RefPtr<Gdk::Pixbuf>, 
50                         Type type,
51                         boost::shared_ptr<PBD::Controllable>,
52                         double default_value,
53                         double step_increment,
54                         double page_increment,
55                         const char *widget_name = NULL,
56                         bool with_numeric_display = true,
57                         int sub_image_width = 40,
58                         int sub_image_height = 40);
59         virtual ~MotionFeedback ();
60
61         Gtk::Widget& eventwin () { return pixwin; }
62
63         boost::shared_ptr<PBD::Controllable> controllable() const;
64         virtual void set_controllable (boost::shared_ptr<PBD::Controllable> c);
65
66         static void set_lamp_color (const std::string&);
67         
68         static Glib::RefPtr<Gdk::Pixbuf> render_pixbuf (int size);
69
70         void set_print_func(void (*pf)(char buf[32], const boost::shared_ptr<PBD::Controllable>&, void *),
71                             void *arg) {
72                 print_func = pf;
73                 print_arg = arg;
74         };
75
76  protected:
77         boost::shared_ptr<PBD::Controllable> _controllable;
78         Gtk::Label* value;
79         double default_value;
80         double step_inc;
81         double page_inc;
82
83         void pixwin_size_request (GtkRequisition *);
84
85         bool pixwin_button_press_event (GdkEventButton *);
86         bool pixwin_button_release_event (GdkEventButton *);
87         bool pixwin_motion_notify_event (GdkEventMotion *);
88         bool pixwin_key_press_event (GdkEventKey *);
89         bool pixwin_enter_notify_event (GdkEventCrossing *);
90         bool pixwin_leave_notify_event (GdkEventCrossing *);
91         bool pixwin_focus_in_event (GdkEventFocus*);
92         bool pixwin_focus_out_event (GdkEventFocus *);
93         bool pixwin_expose_event (GdkEventExpose*);
94         bool pixwin_scroll_event (GdkEventScroll*);
95
96         /* map a display value (0.0 .. 1.0) to a control
97            value (controllable->lower() .. controllable()->upper)
98         */
99         virtual double to_control_value (double) = 0;
100
101         /* map a control value (controllable->lower() .. controllable()->upper)
102            to a display value (0.0 .. 1.0)
103         */
104         virtual double to_display_value (double) = 0;
105         
106         virtual double adjust (double nominal_delta) = 0;
107
108   private:
109         Type type;
110         Gtk::EventBox      pixwin;
111         Gtk::EventBox*     value_packer;
112         Glib::RefPtr<Gdk::Pixbuf> pixbuf;
113         BindingProxy       binding_proxy;
114         static Gdk::Color* base_color;
115
116         void (*print_func) (char buf[32], const boost::shared_ptr<PBD::Controllable>&, void *);
117         void *print_arg;
118         static void default_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>&, void *);
119
120         bool   grab_is_fine;
121         double grabbed_y;
122         double grabbed_x;
123         int subwidth;
124         int subheight;
125         void controllable_value_changed ();
126         PBD::ScopedConnection controller_connection;
127
128         static void core_draw (cairo_t*, int, double, double, double, double, const GdkColor* bright, const GdkColor* dark);
129 };
130
131 } /* namespace */
132         
133 #endif // __gtkmm2ext_motion_feedback_h__