summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/cell_renderer_color_selector.cc
blob: f8093cca1d0df2269f86faeaba1d961e185c6b05 (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
91
92
93
94
95
/*
    Copyright (C) 2011 Paul Davis

    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.

    $Id: cell_renderer_toggle_pixbuf.cc $
*/

#include <iostream>
#include <gtkmm.h>

#include "gtkmm2ext/cell_renderer_color_selector.h"
#include "gtkmm2ext/utils.h"

using namespace std;
using namespace Gtk;
using namespace Gdk;
using namespace Glib;
using namespace Gtkmm2ext;


CellRendererColorSelector::CellRendererColorSelector()
	: Glib::ObjectBase (typeid(CellRendererColorSelector) )
	, Gtk::CellRenderer()
	, _property_color (*this, "color")
{
	property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
	property_sensitive() = false;
	property_xpad() = 2;
	property_ypad() = 2;

	Gdk::Color c;

	c.set_red (0);
	c.set_green (0);
	c.set_blue (0);

	property_color() = c;
}

CellRendererColorSelector::~CellRendererColorSelector ()
{
}

Glib::PropertyProxy<Gdk::Color>
CellRendererColorSelector::property_color()
{
	return _property_color.get_proxy();
}

void
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*/)
{
	Gdk::Color c = _property_color.get_value();

	if (c.gobj() != 0) {

		cairo_t* cr = gdk_cairo_create (window->gobj());
		double r, g, b;
		Gdk::Color c = _property_color.get_value();

		cairo_rectangle (cr, expose_area.get_x(), expose_area.get_y(), expose_area.get_width(), expose_area.get_height());
		cairo_clip (cr);

		r = c.get_red_p();
		g = c.get_green_p();
		b = c.get_blue_p();

		cairo_rectangle_t drawing_rect;

		drawing_rect.x = cell_area.get_x() + property_xpad();
		drawing_rect.y = cell_area.get_y() + property_ypad();
		drawing_rect.width = cell_area.get_width() - (2 * property_xpad());
		drawing_rect.height = cell_area.get_height() - (2 * property_ypad());

		Gtkmm2ext::rounded_rectangle (cr, drawing_rect.x, drawing_rect.y, drawing_rect.width, drawing_rect.height, 5);
		cairo_set_source_rgb (cr, r, g, b);
		cairo_fill (cr);

		cairo_destroy (cr);
	}
}