add a new simple cell renderer to be used to allow color display/editing in treeviews
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 6 Dec 2011 21:43:30 +0000 (21:43 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 6 Dec 2011 21:43:30 +0000 (21:43 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10913 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/gtkmm2ext/cell_renderer_color_selector.cc [new file with mode: 0644]
libs/gtkmm2ext/gtkmm2ext/cell_renderer_color_selector.h [new file with mode: 0644]
libs/gtkmm2ext/wscript

diff --git a/libs/gtkmm2ext/cell_renderer_color_selector.cc b/libs/gtkmm2ext/cell_renderer_color_selector.cc
new file mode 100644 (file)
index 0000000..6ed7611
--- /dev/null
@@ -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 (file)
index 0000000..16e2fec
--- /dev/null
@@ -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__ */
index 3c65508eb8d905cf305f03657fbfef556b8ed3fd..ef2c623dcad5615cfd5499d655829820d6f36586 100644 (file)
@@ -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',