Ardour  9.0-pre0-822-g12e3bc5c20
ardour_fader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef _WIDGETS_ARDOUR_FADER_H_
21 #define _WIDGETS_ARDOUR_FADER_H_
22 
23 #include <cmath>
24 #include <stdint.h>
25 
26 #include <ytkmm/adjustment.h>
27 
28 #include "gtkmm2ext/cairo_widget.h"
29 #include "gtkmm2ext/colors.h"
30 
31 #include "widgets/fader_widget.h"
32 #include "widgets/visibility.h"
33 
34 namespace ArdourWidgets {
35 
36 class LIBWIDGETS_API ArdourFader : virtual public FaderWidget
37 {
38 public:
39  ArdourFader (Gtk::Adjustment& adjustment, int orientation, int span, int girth);
40  virtual ~ArdourFader ();
41  static void flush_pattern_cache();
42 
43  void set_default_value (float);
44  void set_text (const std::string&, bool centered = true, bool expose = true);
45 
48  void unset_bg ();
49  void unset_fg ();
50 
51 protected:
52  void on_size_request (GtkRequisition*);
53  void on_size_allocate (Gtk::Allocation& alloc);
54 
55  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
56  bool on_motion_notify_event (GdkEventMotion*);
57  bool on_touch_update_event (GdkEventTouch*);
58 
59  void on_state_changed (Gtk::StateType);
60  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
61 
62 private:
63  Glib::RefPtr<Pango::Layout> _layout;
64  std::string _text;
67 
68  int _span, _girth;
69  int _min_span, _min_girth;
70  cairo_pattern_t* _pattern;
71 
74 
75  sigc::connection _parent_style_change;
76  Widget * _current_parent;
82 
83  uint32_t outline_color;
84 
86  void set_adjustment_from_event (GdkEventButton *);
88  int display_span ();
89  Gdk::Color bg_color (Gtk::StateType);
90  Gdk::Color fg_color (Gtk::StateType);
91 
92  struct FaderImage {
93  cairo_pattern_t* pattern;
94  double fr;
95  double fg;
96  double fb;
97  double br;
98  double bg;
99  double bb;
100  int width;
101  int height;
102 
103  FaderImage (cairo_pattern_t* p,
104  double afr, double afg, double afb,
105  double abr, double abg, double abb,
106  int w, int h)
107  : pattern (p)
108  , fr (afr)
109  , fg (afg)
110  , fb (afb)
111  , br (abr)
112  , bg (abg)
113  , bb (abb)
114  , width (w)
115  , height (h)
116  {}
117 
118  bool matches (double afr, double afg, double afb,
119  double abr, double abg, double abb,
120  int w, int h) {
121  return width == w &&
122  height == h &&
123  afr == fr &&
124  afg == fg &&
125  afb == fb &&
126  abr == br &&
127  abg == bg &&
128  abb == bb;
129  }
130  };
131 
132  static std::list<FaderImage*> _patterns;
133  static cairo_pattern_t* find_pattern (double afr, double afg, double afb,
134  double abr, double abg, double abb,
135  int w, int h);
136 
137 };
138 
139 } /* namespace */
140 
141 #endif /* __gtkmm2ext_pixfader_h__ */
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
Gdk::Color bg_color(Gtk::StateType)
Gdk::Color fg_color(Gtk::StateType)
static void flush_pattern_cache()
void set_text(const std::string &, bool centered=true, bool expose=true)
void set_adjustment_from_event(GdkEventButton *)
Gtkmm2ext::Color explicit_bg
Definition: ardour_fader.h:78
void set_fg(Gtkmm2ext::Color)
bool on_touch_update_event(GdkEventTouch *)
Gtkmm2ext::Color explicit_fg
Definition: ardour_fader.h:80
static cairo_pattern_t * find_pattern(double afr, double afg, double afb, double abr, double abg, double abb, int w, int h)
void render(Cairo::RefPtr< Cairo::Context > const &, cairo_rectangle_t *)
cairo_pattern_t * _pattern
Definition: ardour_fader.h:70
void on_state_changed(Gtk::StateType)
static std::list< FaderImage * > _patterns
Definition: ardour_fader.h:132
void set_bg(Gtkmm2ext::Color)
void on_size_request(GtkRequisition *)
sigc::connection _parent_style_change
Definition: ardour_fader.h:75
Glib::RefPtr< Pango::Layout > _layout
Definition: ardour_fader.h:63
bool on_motion_notify_event(GdkEventMotion *)
void on_size_allocate(Gtk::Allocation &alloc)
ArdourFader(Gtk::Adjustment &adjustment, int orientation, int span, int girth)
bool expose(GdkEventExpose *ev, Gtk::Widget *w, const enum Icon icon)
uint32_t Color
Definition: colors.h:33
bool matches(double afr, double afg, double afb, double abr, double abg, double abb, int w, int h)
Definition: ardour_fader.h:118
FaderImage(cairo_pattern_t *p, double afr, double afg, double afb, double abr, double abg, double abb, int w, int h)
Definition: ardour_fader.h:103
#define LIBWIDGETS_API