if CANVAS_DEBUG is defined, then the env variable CANVAS_HARLEQUIN_DEBUGGING will...
[ardour.git] / libs / canvas / canvas / xfade_curve.h
1 /*
2     Copyright (C) 2013 Paul Davis
3     Copyright (C) 2014 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
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __CANVAS_XFADECURVE_H__
21 #define __CANVAS_XFADECURVE_H__
22
23 #include "canvas/visibility.h"
24 #include "canvas/item.h"
25 #include "canvas/curve.h"
26
27 namespace ArdourCanvas {
28
29 class LIBCANVAS_API XFadeCurve : public Item, public InterpolatedCurve
30 {
31 public:
32         enum XFadePosition {
33                 Start,
34                 End,
35         };
36
37         XFadeCurve (Canvas *);
38         XFadeCurve (Canvas *, XFadePosition);
39         XFadeCurve (Item*);
40         XFadeCurve (Item*, XFadePosition);
41
42         void set_fade_position (XFadePosition xfp) { _xfadeposition = xfp; }
43         
44         void compute_bounding_box () const;
45         void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
46
47         void set_points_per_segment (uint32_t n);
48         void set_inout (Points const & in, Points const & out);
49
50         void set_outline_color (Color c) {
51                 begin_visual_change ();
52                 _outline_color = c;
53                 end_visual_change ();
54         };
55
56         void set_fill_color (Color c) {
57                 begin_visual_change ();
58                 _fill_color = c;
59                 end_visual_change ();
60         }
61
62 private:
63         struct CanvasCurve {
64                 CanvasCurve() : n_samples(0) { }
65                 Points points;
66                 Points samples;
67                 Points::size_type n_samples;
68         };
69
70         Cairo::Path * get_path(Rect const &, Cairo::RefPtr<Cairo::Context>, CanvasCurve const &) const;
71         void close_path(Rect const &, Cairo::RefPtr<Cairo::Context>, CanvasCurve const &p, bool) const;
72
73         uint32_t points_per_segment;
74
75         CanvasCurve _in;
76         CanvasCurve _out;
77
78         XFadePosition _xfadeposition;
79         Color _outline_color;
80         Color _fill_color;
81
82         void interpolate ();
83 };
84
85 }
86
87 #endif