fix merge errors with master
[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 #include "gtkmm2ext/visibility.h"
31
32 namespace Gtkmm2ext {
33
34 class LIBGTKMM2EXT_API PixFader : public Gtk::DrawingArea
35 {
36   public:
37         PixFader (Gtk::Adjustment& adjustment, int orientation, int span, int girth);
38         virtual ~PixFader ();
39
40         void set_default_value (float);
41         void set_text (const std::string&);
42
43   protected:
44         Glib::RefPtr<Pango::Layout> _layout;
45         std::string                 _text;
46         int   _text_width;
47         int   _text_height;
48         double text_r;
49         double text_g;
50         double text_b;
51
52         Gtk::Adjustment& adjustment;
53
54         void on_size_request (GtkRequisition*);
55         void on_size_allocate (Gtk::Allocation& alloc);
56
57         bool on_expose_event (GdkEventExpose*);
58         bool on_button_press_event (GdkEventButton*);
59         bool on_button_release_event (GdkEventButton*);
60         bool on_motion_notify_event (GdkEventMotion*);
61         bool on_scroll_event (GdkEventScroll* ev);
62         bool on_enter_notify_event (GdkEventCrossing* ev);
63         bool on_leave_notify_event (GdkEventCrossing* ev);
64         void on_state_changed (Gtk::StateType);
65         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
66
67         enum Orientation {
68                 VERT,
69                 HORIZ,
70         };
71
72   private:
73         int span, girth;
74         int _orien;
75         cairo_pattern_t* pattern;
76
77         struct FaderImage {
78             cairo_pattern_t* pattern;
79             double fr;
80             double fg;
81             double fb;
82             double br;
83             double bg;
84             double bb;
85             int width;
86             int height;
87
88             FaderImage (cairo_pattern_t* p, 
89                         double afr, double afg, double afb, 
90                         double abr, double abg, double abb,
91                         int w, int h) 
92                     : pattern (p)
93                     , fr (afr)
94                     , fg (afg)
95                     , fb (afb)
96                     , br (abr)
97                     , bg (abg)
98                     , bb (abb)
99                     , width (w)
100                     , height (h)
101             {}
102
103             bool matches (double afr, double afg, double afb, 
104                           double abr, double abg, double abb,
105                           int w, int h) {
106                     return width == w && 
107                             height == h &&
108                             afr == fr &&
109                             afg == fg && 
110                             afb == fb &&
111                             abr == br &&
112                             abg == bg && 
113                             abb == bb;
114             }
115         };
116
117         static std::list<FaderImage*> _patterns;
118         static cairo_pattern_t* find_pattern (double afr, double afg, double afb, 
119                                               double abr, double abg, double abb, 
120                                               int w, int h);
121
122         bool _hovering;
123
124         GdkWindow* grab_window;
125         double grab_loc;
126         double grab_start;
127         int last_drawn;
128         bool dragging;
129         float default_value;
130         int unity_loc;
131
132         void adjustment_changed ();
133         int display_span ();
134         void set_adjustment_from_event (GdkEventButton *);
135         void update_unity_position ();
136         void create_patterns();
137 };
138
139
140 } /* namespace */
141
142  #endif /* __gtkmm2ext_pixfader_h__ */