cache shaded meter-background regardless of color
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / scroomer.h
1 /*
2     Copyright (C) 2008 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_scroomer_h__ 
21 #define __gtkmm2ext_scroomer_h__
22
23 #include <gtkmm/drawingarea.h>
24 #include <gtkmm/adjustment.h>
25 #include <gdkmm.h>
26
27 namespace Gtkmm2ext {
28
29 class Scroomer : public Gtk::DrawingArea
30 {
31 public:
32         enum Component {
33                 TopBase = 0,
34                 Handle1 = 1,
35                 Slider = 2,
36                 Handle2 = 3,
37                 BottomBase = 4,
38                 Total = 5,
39                 None = 6
40         };
41
42         Scroomer(Gtk::Adjustment& adjustment);
43         ~Scroomer();
44
45         bool on_motion_notify_event (GdkEventMotion*);
46         bool on_button_press_event (GdkEventButton*);
47         bool on_button_release_event (GdkEventButton*);
48         bool on_scroll_event (GdkEventScroll*);
49         virtual void on_size_allocate (Gtk::Allocation&);
50
51         void set_comp_rect(GdkRectangle&, Component) const;
52
53         Component point_in(double point) const;
54
55         void set_min_page_size(double page_size);
56         int get_handle_size() { return handle_size; }
57         
58         inline int position_of(Component comp) { return position[comp]; }
59
60         sigc::signal0<void> DragStarting;
61         sigc::signal0<void> DragFinishing;
62
63         sigc::signal0<void> DoubleClicked;
64
65 protected:
66         Gtk::Adjustment& adj;
67
68 private:
69         struct UpdateRect {
70                 GdkRectangle rect;
71                 Component first_comp;
72         };
73
74         void update();
75         void adjustment_changed ();
76
77         int position[6];
78         int old_pos[6];
79         int handle_size;
80         double min_page_size;
81         GdkWindow* grab_window;
82         Component grab_comp;
83         double grab_y;
84         double unzoomed_val;
85         double unzoomed_page;
86         bool pinch;
87 };
88
89 } // namespace
90
91 #endif /* __gtkmm2ext_scroomer_h__ */