tweak to plugin parameter sliders in mixer strips
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / pixfader.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_pixfader_h__
21 #define __gtkmm2ext_pixfader_h__
22
23 #include <cmath>
24 #include <stdint.h>
25
26 #include <gtkmm/drawingarea.h>
27 #include <gtkmm/adjustment.h>
28 #include <gdkmm.h>
29
30 namespace Gtkmm2ext {
31
32 class PixFader : public Gtk::DrawingArea
33 {
34   public:
35         PixFader (Glib::RefPtr<Gdk::Pixbuf>, Glib::RefPtr<Gdk::Pixbuf>, Gtk::Adjustment& adjustment, int orientation, int);
36         virtual ~PixFader ();
37
38         void set_fader_length (int);
39         void set_border_colors (uint32_t rgba_left, uint32_t rgba_right);
40
41         void set_default_value (float);
42
43         void set_text (const std::string&);
44
45   protected:
46         Glib::RefPtr<Pango::Layout> _layout;
47         std::string                 _text;
48         int   _text_width;
49         int   _text_height;
50         double text_r;
51         double text_g;
52         double text_b;
53
54         Gtk::Adjustment& adjustment;
55
56         void on_size_request (GtkRequisition*);
57         void on_size_allocate (Gtk::Allocation& alloc);
58
59         bool on_expose_event (GdkEventExpose*);
60         bool on_button_press_event (GdkEventButton*);
61         bool on_button_release_event (GdkEventButton*);
62         bool on_motion_notify_event (GdkEventMotion*);
63         bool on_scroll_event (GdkEventScroll* ev);
64         bool on_enter_notify_event (GdkEventCrossing* ev);
65         bool on_leave_notify_event (GdkEventCrossing* ev);
66
67         enum Orientation {
68                 VERT=1,
69                 HORIZ=2,
70         };
71
72   private:
73
74         enum State {
75                 NORMAL,
76                 DESENSITISED,
77                 STATES
78         };
79         
80         Cairo::RefPtr<Cairo::Context> belt_context[STATES];
81         Cairo::RefPtr<Cairo::ImageSurface> belt_surface[STATES];
82         Glib::RefPtr<Gdk::Pixbuf> pixbuf[STATES];
83
84         int span, girth;
85         int _orien;
86         float left_r;
87         float left_g;
88         float left_b;
89         float right_r;
90         float right_g;
91         float right_b;
92
93         GdkRectangle view;
94
95         void create_patterns();
96         cairo_pattern_t* pattern;
97         cairo_pattern_t* shine_pattern;
98
99         bool _hovering;
100
101         GdkWindow* grab_window;
102         double grab_loc;
103         double grab_start;
104         int last_drawn;
105         bool dragging;
106         float default_value;
107         int unity_loc;
108
109         void adjustment_changed ();
110         int display_span ();
111         void set_adjustment_from_event (GdkEventButton *);
112         void update_unity_position ();
113 };
114
115
116 } /* namespace */
117
118  #endif /* __gtkmm2ext_pixfader_h__ */