summaryrefslogtreecommitdiff
path: root/libs/canvas/canvas/xfade_curve.h
blob: 60c1c45e2342f94822f2b49a54411e61a7a5f50d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
    Copyright (C) 2013 Paul Davis
    Copyright (C) 2014 Robin Gareus <robin@gareus.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __CANVAS_XFADECURVE_H__
#define __CANVAS_XFADECURVE_H__

#include "canvas/visibility.h"
#include "canvas/item.h"
#include "canvas/curve.h"

namespace ArdourCanvas {

class LIBCANVAS_API XFadeCurve : public Item, public InterpolatedCurve
{
public:
	enum XFadePosition {
		Start,
		End,
	};

	XFadeCurve (Canvas *);
	XFadeCurve (Canvas *, XFadePosition);
	XFadeCurve (Item*);
	XFadeCurve (Item*, XFadePosition);

	void set_fade_position (XFadePosition xfp) { _xfadeposition = xfp; }
	void set_show_background_fade (bool show) { show_background_fade = show; }
    
	void compute_bounding_box () const;
	void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;

	void set_points_per_segment (uint32_t n);
	void set_inout (Points const & in, Points const & out);

	void set_outline_color (Color c) {
		begin_visual_change ();
		_outline_color = c;
		end_visual_change ();
	};

	void set_fill_color (Color c) {
		begin_visual_change ();
		_fill_color = c;
		end_visual_change ();
	}

private:
	struct CanvasCurve {
		CanvasCurve() : n_samples(0) { }
		Points points;
		Points samples;
		Points::size_type n_samples;
	};

	Cairo::Path * get_path(Rect const &, Cairo::RefPtr<Cairo::Context>, CanvasCurve const &) const;
	void close_path(Rect const &, Cairo::RefPtr<Cairo::Context>, CanvasCurve const &p, bool) const;

	uint32_t points_per_segment;

	CanvasCurve _in;
	CanvasCurve _out;

	XFadePosition _xfadeposition;
	Color _outline_color;
	Color _fill_color;

	bool show_background_fade;
    
	void interpolate ();
};

}

#endif