Ardour  9.0-pre0-386-g96ef4d20f2
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 <gdkmm.h>
27 #include <gtkmm/adjustment.h>
28 
29 #include "gtkmm2ext/cairo_widget.h"
30 #include "gtkmm2ext/colors.h"
31 
32 #include "widgets/fader_widget.h"
33 #include "widgets/visibility.h"
34 
35 namespace ArdourWidgets {
36 
37 class LIBWIDGETS_API ArdourFader : virtual public FaderWidget
38 {
39 public:
40  ArdourFader (Gtk::Adjustment& adjustment, int orientation, int span, int girth);
41  virtual ~ArdourFader ();
42  static void flush_pattern_cache();
43 
44  void set_default_value (float);
45  void set_text (const std::string&, bool centered = true, bool expose = true);
46 
49  void unset_bg ();
50  void unset_fg ();
51 
52 protected:
55 
56  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
59 
61  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
62 
63 private:
64  Glib::RefPtr<Pango::Layout> _layout;
65  std::string _text;
68 
69  int _span, _girth;
70  int _min_span, _min_girth;
71  cairo_pattern_t* _pattern;
72 
75 
76  sigc::connection _parent_style_change;
77  Widget * _current_parent;
83 
84  uint32_t outline_color;
85 
89  int display_span ();
92 
93  struct FaderImage {
94  cairo_pattern_t* pattern;
95  double fr;
96  double fg;
97  double fb;
98  double br;
99  double bg;
100  double bb;
101  int width;
102  int height;
103 
104  FaderImage (cairo_pattern_t* p,
105  double afr, double afg, double afb,
106  double abr, double abg, double abb,
107  int w, int h)
108  : pattern (p)
109  , fr (afr)
110  , fg (afg)
111  , fb (afb)
112  , br (abr)
113  , bg (abg)
114  , bb (abb)
115  , width (w)
116  , height (h)
117  {}
118 
119  bool matches (double afr, double afg, double afb,
120  double abr, double abg, double abb,
121  int w, int h) {
122  return width == w &&
123  height == h &&
124  afr == fr &&
125  afg == fg &&
126  afb == fb &&
127  abr == br &&
128  abg == bg &&
129  abb == bb;
130  }
131  };
132 
133  static std::list<FaderImage*> _patterns;
134  static cairo_pattern_t* find_pattern (double afr, double afg, double afb,
135  double abr, double abg, double abb,
136  int w, int h);
137 
138 };
139 
140 } /* namespace */
141 
142 #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:79
void set_fg(Gtkmm2ext::Color)
bool on_touch_update_event(GdkEventTouch *)
Gtkmm2ext::Color explicit_fg
Definition: ardour_fader.h:81
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:71
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:133
void set_bg(Gtkmm2ext::Color)
void on_size_request(GtkRequisition *)
This is a default handler for the signal signal_size_request().
sigc::connection _parent_style_change
Definition: ardour_fader.h:76
Glib::RefPtr< Pango::Layout > _layout
Definition: ardour_fader.h:64
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:119
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:104
#define LIBWIDGETS_API
gint height
Definition: xcursors.h:1
gint width
Definition: xcursors.h:1