2 * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2013-2014 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <cairomm/cairomm.h>
23 #include "pbd/compose.h"
24 #include "pbd/convert.h"
26 #include "canvas/fill.h"
27 #include "canvas/item.h"
28 #include "canvas/types.h"
31 using namespace ArdourCanvas;
33 Fill::Fill (Item& self)
35 , _fill_color (0x000000ff)
37 , _transparent (false)
42 Fill::set_fill_color (Gtkmm2ext::Color color)
44 if (_fill_color != color) {
45 _self.begin_visual_change ();
49 Gtkmm2ext::color_to_rgba (color, r, g, b, a);
56 _self.end_visual_change ();
61 Fill::set_fill (bool fill)
64 _self.begin_visual_change ();
66 _self.end_visual_change ();
71 Fill::setup_fill_context (Cairo::RefPtr<Cairo::Context> context) const
74 context->set_source (_pattern);
76 Gtkmm2ext::set_source_rgba (context, _fill_color);
81 Fill::setup_gradient_context (Cairo::RefPtr<Cairo::Context> context, Rect const & self, Duple const & draw_origin) const
83 Cairo::RefPtr<Cairo::LinearGradient> _gradient;
85 if (_vertical_gradient) {
86 _gradient = Cairo::LinearGradient::create (draw_origin.x, self.y0, draw_origin.x, self.y1);
88 _gradient = Cairo::LinearGradient::create (self.x0, draw_origin.y, self.x1, draw_origin.y);
91 for (StopList::const_iterator s = _stops.begin(); s != _stops.end(); ++s) {
93 Gtkmm2ext::color_to_rgba (s->second, r, g, b, a);
94 _gradient->add_color_stop_rgba (s->first, r, g, b, a);
97 context->set_source (_gradient);
101 Fill::set_pattern (Cairo::RefPtr<Cairo::Pattern> p)
107 Fill::set_gradient (StopList const & stops, bool vertical)
109 _self.begin_visual_change ();
115 _vertical_gradient = vertical;
118 _self.end_visual_change ();