Consistent use of abort() /* NOTREACHED */
[ardour.git] / libs / gtkmm2ext / cell_renderer_color_selector.cc
1 /*
2  * Copyright (C) 2011-2015 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include <iostream>
20 #include <gtkmm.h>
21
22 #include "gtkmm2ext/cell_renderer_color_selector.h"
23 #include "gtkmm2ext/utils.h"
24
25 using namespace std;
26 using namespace Gtk;
27 using namespace Gdk;
28 using namespace Glib;
29 using namespace Gtkmm2ext;
30
31
32 CellRendererColorSelector::CellRendererColorSelector()
33         : Glib::ObjectBase (typeid(CellRendererColorSelector) )
34         , Gtk::CellRenderer()
35         , _property_color (*this, "color")
36 {
37         property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
38         property_sensitive() = false;
39         property_xpad() = 2;
40         property_ypad() = 2;
41
42         Gdk::Color c;
43
44         c.set_red (0);
45         c.set_green (0);
46         c.set_blue (0);
47
48         property_color() = c;
49 }
50
51 CellRendererColorSelector::~CellRendererColorSelector ()
52 {
53 }
54
55 Glib::PropertyProxy<Gdk::Color>
56 CellRendererColorSelector::property_color()
57 {
58         return _property_color.get_proxy();
59 }
60
61 void
62 CellRendererColorSelector::render_vfunc (const Glib::RefPtr<Gdk::Drawable>& window, Gtk::Widget& /*widget*/, const Gdk::Rectangle& /*background_area*/, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& expose_area, Gtk::CellRendererState /*flags*/)
63 {
64         Gdk::Color c = _property_color.get_value();
65
66         if (c.gobj() != 0) {
67
68                 cairo_t* cr = gdk_cairo_create (window->gobj());
69                 double r, g, b;
70                 Gdk::Color c = _property_color.get_value();
71
72                 cairo_rectangle (cr, expose_area.get_x(), expose_area.get_y(), expose_area.get_width(), expose_area.get_height());
73                 cairo_clip (cr);
74
75                 r = c.get_red_p();
76                 g = c.get_green_p();
77                 b = c.get_blue_p();
78
79                 cairo_rectangle_t drawing_rect;
80
81                 drawing_rect.x = cell_area.get_x() + property_xpad();
82                 drawing_rect.y = cell_area.get_y() + property_ypad();
83                 drawing_rect.width = cell_area.get_width() - (2 * property_xpad());
84                 drawing_rect.height = cell_area.get_height() - (2 * property_ypad());
85
86                 Gtkmm2ext::rounded_rectangle (cr, drawing_rect.x, drawing_rect.y, drawing_rect.width, drawing_rect.height, 5);
87                 cairo_set_source_rgb (cr, r, g, b);
88                 cairo_fill (cr);
89
90                 cairo_destroy (cr);
91         }
92 }
93