[Summary] Should have been committed with previous: made background fade optional...
[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         void set_show_background_fade (bool show) { show_background_fade = show; }
44     
45         void compute_bounding_box () const;
46         void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
47
48         void set_points_per_segment (uint32_t n);
49         void set_inout (Points const & in, Points const & out);
50
51         void set_outline_color (Color c) {
52                 begin_visual_change ();
53                 _outline_color = c;
54                 end_visual_change ();
55         };
56
57         void set_fill_color (Color c) {
58                 begin_visual_change ();
59                 _fill_color = c;
60                 end_visual_change ();
61         }
62
63 private:
64         struct CanvasCurve {
65                 CanvasCurve() : n_samples(0) { }
66                 Points points;
67                 Points samples;
68                 Points::size_type n_samples;
69         };
70
71         Cairo::Path * get_path(Rect const &, Cairo::RefPtr<Cairo::Context>, CanvasCurve const &) const;
72         void close_path(Rect const &, Cairo::RefPtr<Cairo::Context>, CanvasCurve const &p, bool) const;
73
74         uint32_t points_per_segment;
75
76         CanvasCurve _in;
77         CanvasCurve _out;
78
79         XFadePosition _xfadeposition;
80         Color _outline_color;
81         Color _fill_color;
82
83     bool show_background_fade;
84     
85         void interpolate ();
86 };
87
88 }
89
90 #endif