From f42da2a813083a17eb54d776692970b61ff934f6 Mon Sep 17 00:00:00 2001 From: joncruz Date: Fri, 24 Mar 2006 04:12:22 +0000 Subject: [PATCH] Bringing in new color class --- ChangeLog | 8 +++ src/dialogs/Makefile_insert | 2 + src/dialogs/eek-color-def.cpp | 96 +++++++++++++++++++++++++++++++++++ src/dialogs/eek-color-def.h | 73 ++++++++++++++++++++++++++ src/dialogs/swatches.cpp | 32 +++++------- src/dialogs/swatches.h | 10 ++-- 6 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 src/dialogs/eek-color-def.cpp create mode 100644 src/dialogs/eek-color-def.h diff --git a/ChangeLog b/ChangeLog index f65651c8c..8def88483 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-03-10 Jon A. Cruz + + * src/dialogs/eek-color-def.cpp, src/dialogs/eek-color-def.h, + src/dialogs/Makefile_insert, src/dialogs/swatches.h, + src/dialogs/swatches.cpp: + + Bringing in new color class. + 2006-03-23 Michael Wybrow * packaging/macosx/Resources/bin/inkscape: Fix a packaging diff --git a/src/dialogs/Makefile_insert b/src/dialogs/Makefile_insert index b3084c06a..4100ec853 100644 --- a/src/dialogs/Makefile_insert +++ b/src/dialogs/Makefile_insert @@ -18,6 +18,8 @@ dialogs_libspdialogs_a_SOURCES = \ dialogs/debugdialog.h \ dialogs/dialog-events.cpp \ dialogs/dialog-events.h \ + dialogs/eek-color-def.h \ + dialogs/eek-color-def.cpp \ dialogs/eek-preview.h \ dialogs/eek-preview.cpp \ dialogs/export.cpp \ diff --git a/src/dialogs/eek-color-def.cpp b/src/dialogs/eek-color-def.cpp new file mode 100644 index 000000000..8d24f82f0 --- /dev/null +++ b/src/dialogs/eek-color-def.cpp @@ -0,0 +1,96 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Eek Color Definition. + * + * The Initial Developer of the Original Code is + * Jon A. Cruz. + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include + +#if !defined(_) +#define _(s) gettext(s) +#endif // !defined(_) + +#include "eek-color-def.h" + +namespace eek +{ + +ColorDef::ColorDef() : + r(0), + g(0), + b(0), + descr(_("none")), + none(true) +{ +} + +ColorDef::ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description ) : + r(r), + g(g), + b(b), + descr(description), + none(false) +{ +} + +ColorDef::~ColorDef() +{ +} + +ColorDef::ColorDef( ColorDef const &other ) +{ + if ( this != &other ) { + *this = other; + } +} + +ColorDef& ColorDef::operator=( ColorDef const &other ) +{ + if ( this != & other ) + { + r = other.r; + g = other.g; + b = other.b; + descr = other.descr; + none = other.none; + } + return *this; +} + + + + +} // namespace eek diff --git a/src/dialogs/eek-color-def.h b/src/dialogs/eek-color-def.h new file mode 100644 index 000000000..13e2a50fe --- /dev/null +++ b/src/dialogs/eek-color-def.h @@ -0,0 +1,73 @@ +#ifndef SEEN_EEK_COLOR_DEF_H +#define SEEN_EEK_COLOR_DEF_H +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Eek Color Definition. + * + * The Initial Developer of the Original Code is + * Jon A. Cruz. + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include + +namespace eek +{ + +class ColorDef +{ +public: + ColorDef(); + ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description ); + virtual ~ColorDef(); + + ColorDef( ColorDef const &other ); + virtual ColorDef& operator=( ColorDef const &other ); + + + unsigned int r; + unsigned int g; + unsigned int b; + std::string descr; + bool none; + +protected: + +private: +}; + + +} // namespace eek + + +#endif // SEEN_EEK_COLOR_DEF_H diff --git a/src/dialogs/swatches.cpp b/src/dialogs/swatches.cpp index 17418186a..d9aad2bdc 100644 --- a/src/dialogs/swatches.cpp +++ b/src/dialogs/swatches.cpp @@ -40,10 +40,7 @@ SwatchesPanel* SwatchesPanel::instance = 0; ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ) : - _r(r), - _g(g), - _b(b), - _name(name) + def( r, g, b, name ) { } @@ -62,10 +59,7 @@ ColorItem::ColorItem(ColorItem const &other) : ColorItem &ColorItem::operator=(ColorItem const &other) { if ( this != &other ) { - _r = other._r; - _g = other._g; - _b = other._b; - _name = other._name; + def = other.def; } return *this; } @@ -92,7 +86,7 @@ static void dragGetColorData( GtkWidget *widget, ColorItem* item = reinterpret_cast(user_data); if ( info == 1 ) { - gchar* tmp = g_strdup_printf("#%02x%02x%02x", item->_r, item->_g, item->_b); + gchar* tmp = g_strdup_printf("#%02x%02x%02x", item->def.r, item->def.g, item->def.b); gtk_selection_data_set( data, typeText, @@ -103,9 +97,9 @@ static void dragGetColorData( GtkWidget *widget, tmp = 0; } else { guint16 tmp[4]; - tmp[0] = (item->_r << 8) | item->_r; - tmp[1] = (item->_g << 8) | item->_g; - tmp[2] = (item->_b << 8) | item->_b; + tmp[0] = (item->def.r << 8) | item->def.r; + tmp[1] = (item->def.g << 8) | item->def.g; + tmp[2] = (item->def.b << 8) | item->def.b; tmp[3] = 0xffff; gtk_selection_data_set( data, typeXColor, @@ -121,9 +115,9 @@ static void dragBegin( GtkWidget *widget, GdkDragContext* dc, gpointer data ) if ( item ) { Glib::RefPtr thumb = Gdk::Pixbuf::create( Gdk::COLORSPACE_RGB, false, 8, 32, 24 ); - guint32 fillWith = (0xff000000 & (item->_r << 24)) - | (0x00ff0000 & (item->_g << 16)) - | (0x0000ff00 & (item->_b << 8)); + guint32 fillWith = (0xff000000 & (item->def.r << 24)) + | (0x00ff0000 & (item->def.g << 16)) + | (0x0000ff00 & (item->def.b << 8)); thumb->fill( fillWith ); gtk_drag_set_icon_pixbuf( dc, thumb->gobj(), 0, 0 ); } @@ -160,7 +154,7 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, Gtk::Built { Gtk::Widget* widget = 0; if ( style == PREVIEW_STYLE_BLURB ) { - Gtk::Label *lbl = new Gtk::Label(_name); + Gtk::Label *lbl = new Gtk::Label(def.descr); lbl->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); widget = lbl; } else { @@ -173,7 +167,7 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, Gtk::Built EekPreview * preview = EEK_PREVIEW(eekWidget); Gtk::Widget* newBlot = Glib::wrap(eekWidget); - eek_preview_set_color( preview, (_r << 8)|_r, (_g << 8)|_g, (_b << 8)|_b); + eek_preview_set_color( preview, (def.r << 8) | def.r, (def.g << 8) | def.g, (def.b << 8) | def.b); eek_preview_set_details( preview, (::PreviewStyle)style, (::ViewType)view, (::GtkIconSize)size ); @@ -194,7 +188,7 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, Gtk::Built Gtk::Widget* newBlot = btn; */ - tips.set_tip((*newBlot), _name); + tips.set_tip((*newBlot), def.descr); /* newBlot->signal_clicked().connect( sigc::mem_fun(*this, &ColorItem::buttonClicked) ); @@ -243,7 +237,7 @@ void ColorItem::buttonClicked(bool secondary) SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { char const * attrName = secondary ? "stroke" : "fill"; - guint32 rgba = (_r << 24) | (_g << 16) | (_b << 8) | 0xff; + guint32 rgba = (def.r << 24) | (def.g << 16) | (def.b << 8) | 0xff; gchar c[64]; sp_svg_write_color(c, 64, rgba); diff --git a/src/dialogs/swatches.h b/src/dialogs/swatches.h index 37a04cfba..1fba23eba 100644 --- a/src/dialogs/swatches.h +++ b/src/dialogs/swatches.h @@ -17,6 +17,9 @@ #include "ui/widget/panel.h" #include "ui/previewholder.h" +#include "dialogs/eek-color-def.h" + +using eek::ColorDef; namespace Inkscape { namespace UI { @@ -39,11 +42,8 @@ public: ViewType view, Gtk::BuiltinIconSize size); void buttonClicked(bool secondary = false); - unsigned int _r; - unsigned int _g; - unsigned int _b; - Glib::ustring _name; - + + ColorDef def; private: Gtk::Tooltips tips; }; -- 2.39.5