ardour
pixfader.h
Go to the documentation of this file.
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 "gtkmm2ext/cairo_widget.h"
27 #include <gtkmm/adjustment.h>
28 #include <gdkmm.h>
29 
30 #include "gtkmm2ext/visibility.h"
31 
32 namespace Gtkmm2ext {
33 
35 {
36  public:
37  PixFader (Gtk::Adjustment& adjustment, int orientation, int span, int girth);
38  virtual ~PixFader ();
39 
40  sigc::signal<void> StartGesture;
41  sigc::signal<void> StopGesture;
42  sigc::signal<void> OnExpose;
43 
44  void set_default_value (float);
45  void set_text (const std::string&, bool centered = true, bool expose = true);
46 
47  enum Tweaks {
48  NoShowUnityLine = 0x1,
49  NoButtonForward = 0x2,
50  NoVerticalScroll = 0x4,
51  };
52 
53  Tweaks tweaks() const { return _tweaks; }
54  void set_tweaks (Tweaks);
55 
56  protected:
57  void on_size_request (GtkRequisition*);
58  void on_size_allocate (Gtk::Allocation& alloc);
59 
60  void render (cairo_t *, cairo_rectangle_t*);
61  bool on_button_press_event (GdkEventButton*);
62  bool on_button_release_event (GdkEventButton*);
63  bool on_motion_notify_event (GdkEventMotion*);
64  bool on_scroll_event (GdkEventScroll* ev);
65  bool on_enter_notify_event (GdkEventCrossing* ev);
66  bool on_leave_notify_event (GdkEventCrossing* ev);
67 
68  void on_state_changed (Gtk::StateType);
69  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
70 
71  enum Orientation {
74  };
75 
76  private:
77 
78  Glib::RefPtr<Pango::Layout> _layout;
79  std::string _text;
81  Gtk::Adjustment& _adjustment;
84 
85  int _span, _girth;
86  int _min_span, _min_girth;
87  int _orien;
88  cairo_pattern_t* _pattern;
89  bool _hovering;
90  GdkWindow* _grab_window;
91  double _grab_loc;
92  double _grab_start;
93  bool _dragging;
97 
98  sigc::connection _parent_style_change;
99  Widget * _current_parent;
100  Gdk::Color get_parent_bg ();
101 
102  void create_patterns();
103  void adjustment_changed ();
104  void set_adjustment_from_event (GdkEventButton *);
105  void update_unity_position ();
106  int display_span ();
107 
108  struct FaderImage {
109  cairo_pattern_t* pattern;
110  double fr;
111  double fg;
112  double fb;
113  double br;
114  double bg;
115  double bb;
116  int width;
117  int height;
118 
119  FaderImage (cairo_pattern_t* p,
120  double afr, double afg, double afb,
121  double abr, double abg, double abb,
122  int w, int h)
123  : pattern (p)
124  , fr (afr)
125  , fg (afg)
126  , fb (afb)
127  , br (abr)
128  , bg (abg)
129  , bb (abb)
130  , width (w)
131  , height (h)
132  {}
133 
134  bool matches (double afr, double afg, double afb,
135  double abr, double abg, double abb,
136  int w, int h) {
137  return width == w &&
138  height == h &&
139  afr == fr &&
140  afg == fg &&
141  afb == fb &&
142  abr == br &&
143  abg == bg &&
144  abb == bb;
145  }
146  };
147 
148  static std::list<FaderImage*> _patterns;
149  static cairo_pattern_t* find_pattern (double afr, double afg, double afb,
150  double abr, double abg, double abb,
151  int w, int h);
152 
153 };
154 
155 
156 } /* namespace */
157 
158 #endif /* __gtkmm2ext_pixfader_h__ */
Gtk::Adjustment & _adjustment
Definition: pixfader.h:81
sigc::signal< void > StartGesture
Definition: pixfader.h:40
LIBGTKMM2EXT_API
cairo_pattern_t * pattern
Definition: pixfader.h:109
bool matches(double afr, double afg, double afb, double abr, double abg, double abb, int w, int h)
Definition: pixfader.h:134
Glib::RefPtr< Pango::Layout > _layout
Definition: pixfader.h:78
Widget * _current_parent
Definition: pixfader.h:99
double _grab_start
Definition: pixfader.h:92
static std::list< FaderImage * > _patterns
Definition: pixfader.h:148
sigc::connection _parent_style_change
Definition: pixfader.h:98
Tweaks tweaks() const
Definition: pixfader.h:53
FaderImage(cairo_pattern_t *p, double afr, double afg, double afb, double abr, double abg, double abb, int w, int h)
Definition: pixfader.h:119
GdkWindow * _grab_window
Definition: pixfader.h:90
float _default_value
Definition: pixfader.h:94
std::string _text
Definition: pixfader.h:79
cairo_pattern_t * _pattern
Definition: pixfader.h:88
sigc::signal< void > OnExpose
Definition: pixfader.h:42
sigc::signal< void > StopGesture
Definition: pixfader.h:41