summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-12-06 21:43:30 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-12-06 21:43:30 +0000
commit5e3a3b56de6135499dc3f6993bc924f28e7190ed (patch)
tree9716e1fc66e9d66c05522c74be369c38f9ffe900
parent78db8a94453272a964c51218b858ed53a1769d47 (diff)
add a new simple cell renderer to be used to allow color display/editing in treeviews
git-svn-id: svn://localhost/ardour2/branches/3.0@10913 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--libs/gtkmm2ext/cell_renderer_color_selector.cc90
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/cell_renderer_color_selector.h52
-rw-r--r--libs/gtkmm2ext/wscript1
3 files changed, 143 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/cell_renderer_color_selector.cc b/libs/gtkmm2ext/cell_renderer_color_selector.cc
new file mode 100644
index 0000000000..6ed761132a
--- /dev/null
+++ b/libs/gtkmm2ext/cell_renderer_color_selector.cc
@@ -0,0 +1,90 @@
+/*
+ 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*/)
+{
+ 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);
+}
+
diff --git a/libs/gtkmm2ext/gtkmm2ext/cell_renderer_color_selector.h b/libs/gtkmm2ext/gtkmm2ext/cell_renderer_color_selector.h
new file mode 100644
index 0000000000..16e2feca6a
--- /dev/null
+++ b/libs/gtkmm2ext/gtkmm2ext/cell_renderer_color_selector.h
@@ -0,0 +1,52 @@
+/*
+ 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.
+
+*/
+
+#ifndef __gtkmm2ext_cell_renderer_color_selector_h__
+#define __gtkmm2ext_cell_renderer_color_selector_h__
+
+#include <gtkmm/drawingarea.h>
+#include <gtkmm/widget.h>
+#include <gtkmm/cellrenderer.h>
+#include <gdkmm.h>
+
+using namespace Gtk;
+
+namespace Gtk {
+ class ColorSelectionDialog;
+}
+
+namespace Gtkmm2ext {
+
+class CellRendererColorSelector : public Gtk::CellRenderer
+{
+ public:
+ CellRendererColorSelector();
+ virtual ~CellRendererColorSelector();
+
+ 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);
+
+ Glib::PropertyProxy<Gdk::Color> property_color();
+
+ private:
+ Glib::Property<Gdk::Color> _property_color;
+};
+
+} // namespace
+
+#endif /* __gtkmm2ext_cell_renderer_pixbuf_toggle_h__ */
diff --git a/libs/gtkmm2ext/wscript b/libs/gtkmm2ext/wscript
index 3c65508eb8..ef2c623dca 100644
--- a/libs/gtkmm2ext/wscript
+++ b/libs/gtkmm2ext/wscript
@@ -28,6 +28,7 @@ gtkmm2ext_sources = [
'bindable_button.cc',
'bindings.cc',
'cairocell.cc',
+ 'cell_renderer_color_selector.cc',
'cell_renderer_pixbuf_multi.cc',
'cell_renderer_pixbuf_toggle.cc',
'choice.cc',