Ardour  9.0-pre0-1048-gdef69dd383
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  void update_min_size (int span, int girth);
52 
53 protected:
56 
57  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
60 
62  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
63 
64 private:
65  Glib::RefPtr<Pango::Layout> _layout;
66  std::string _text;
69 
70  int _span, _girth;
71  int _min_span, _min_girth;
72  cairo_pattern_t* _pattern;
73 
76 
77  sigc::connection _parent_style_change;
78  Widget * _current_parent;
84 
85  uint32_t outline_color;
86 
90  int display_span ();
93 
94  struct FaderImage {
95  cairo_pattern_t* pattern;
96  double fr;
97  double fg;
98  double fb;
99  double br;
100  double bg;
101  double bb;
102  int width;
103  int height;
104 
105  FaderImage (cairo_pattern_t* p,
106  double afr, double afg, double afb,
107  double abr, double abg, double abb,
108  int w, int h)
109  : pattern (p)
110  , fr (afr)
111  , fg (afg)
112  , fb (afb)
113  , br (abr)
114  , bg (abg)
115  , bb (abb)
116  , width (w)
117  , height (h)
118  {}
119 
120  bool matches (double afr, double afg, double afb,
121  double abr, double abg, double abb,
122  int w, int h) {
123  return width == w &&
124  height == h &&
125  afr == fr &&
126  afg == fg &&
127  afb == fb &&
128  abr == br &&
129  abg == bg &&
130  abb == bb;
131  }
132  };
133 
134  static std::list<FaderImage*> _patterns;
135  static cairo_pattern_t* find_pattern (double afr, double afg, double afb,
136  double abr, double abg, double abb,
137  int w, int h);
138 
139 };
140 
141 } /* namespace */
142 
143 #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:80
void set_fg(Gtkmm2ext::Color)
bool on_touch_update_event(GdkEventTouch *)
Gtkmm2ext::Color explicit_fg
Definition: ardour_fader.h:82
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:72
void on_state_changed(Gtk::StateType)
This is a default handler for the signal signal_state_changed().
static std::list< FaderImage * > _patterns
Definition: ardour_fader.h:134
void set_bg(Gtkmm2ext::Color)
void on_size_request(GtkRequisition *)
This is a default handler for the signal signal_size_request().
void update_min_size(int span, int girth)
sigc::connection _parent_style_change
Definition: ardour_fader.h:77
Glib::RefPtr< Pango::Layout > _layout
Definition: ardour_fader.h:65
bool on_motion_notify_event(GdkEventMotion *)
This is a default handler for the signal signal_motion_notify_event().
void on_size_allocate(Gtk::Allocation &alloc)
This is a default handler for the signal signal_size_allocate().
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:120
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:105
#define LIBWIDGETS_API
gint height
Definition: xcursors.h:1
gint width
Definition: xcursors.h:1