ardour
cell_renderer_color_selector.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Paul Davis
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
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18  $Id: cell_renderer_toggle_pixbuf.cc $
19 */
20 
21 #include <iostream>
22 #include <gtkmm.h>
23 
25 #include "gtkmm2ext/utils.h"
26 
27 using namespace std;
28 using namespace Gtk;
29 using namespace Gdk;
30 using namespace Glib;
31 using namespace Gtkmm2ext;
32 
33 
34 CellRendererColorSelector::CellRendererColorSelector()
35  : Glib::ObjectBase (typeid(CellRendererColorSelector) )
36  , Gtk::CellRenderer()
37  , _property_color (*this, "color")
38 {
39  property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
40  property_sensitive() = false;
41  property_xpad() = 2;
42  property_ypad() = 2;
43 
44  Gdk::Color c;
45 
46  c.set_red (0);
47  c.set_green (0);
48  c.set_blue (0);
49 
50  property_color() = c;
51 }
52 
54 {
55 }
56 
57 Glib::PropertyProxy<Gdk::Color>
59 {
60  return _property_color.get_proxy();
61 }
62 
63 void
64 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*/)
65 {
66  Gdk::Color c = _property_color.get_value();
67 
68  if (c.gobj() != 0) {
69 
70  cairo_t* cr = gdk_cairo_create (window->gobj());
71  double r, g, b;
72  Gdk::Color c = _property_color.get_value();
73 
74  cairo_rectangle (cr, expose_area.get_x(), expose_area.get_y(), expose_area.get_width(), expose_area.get_height());
75  cairo_clip (cr);
76 
77  r = c.get_red_p();
78  g = c.get_green_p();
79  b = c.get_blue_p();
80 
81  cairo_rectangle_t drawing_rect;
82 
83  drawing_rect.x = cell_area.get_x() + property_xpad();
84  drawing_rect.y = cell_area.get_y() + property_ypad();
85  drawing_rect.width = cell_area.get_width() - (2 * property_xpad());
86  drawing_rect.height = cell_area.get_height() - (2 * property_ypad());
87 
88  Gtkmm2ext::rounded_rectangle (cr, drawing_rect.x, drawing_rect.y, drawing_rect.width, drawing_rect.height, 5);
89  cairo_set_source_rgb (cr, r, g, b);
90  cairo_fill (cr);
91 
92  cairo_destroy (cr);
93  }
94 }
95 
Glib::PropertyProxy< Gdk::Color > property_color()
Definition: ardour_ui.h:130
Definition: Beats.hpp:239
virtual void 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)
LIBGTKMM2EXT_API void rounded_rectangle(Cairo::RefPtr< Cairo::Context > context, double x, double y, double w, double h, double r=10)
Definition: utils.cc:520