diff options
| author | Ted Gould <ted@gould.cx> | 2007-08-10 17:38:51 +0000 |
|---|---|---|
| committer | gouldtj <gouldtj@users.sourceforge.net> | 2007-08-10 17:38:51 +0000 |
| commit | b29eafffd0b92cc7b67e5cd877aad5e98b0f0231 (patch) | |
| tree | 167c348e5e11ebf3d8afec37593f023180675039 /src/extension/paramcolor.cpp | |
| parent | fix 1767940 (diff) | |
| download | inkscape-b29eafffd0b92cc7b67e5cd877aad5e98b0f0231.tar.gz inkscape-b29eafffd0b92cc7b67e5cd877aad5e98b0f0231.zip | |
r16217@tres: ted | 2007-08-10 10:36:27 -0700
ImageMagick effects patch from Chris Brown. Google Summer of Code
project.
(bzr r3450)
Diffstat (limited to 'src/extension/paramcolor.cpp')
| -rw-r--r-- | src/extension/paramcolor.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/extension/paramcolor.cpp b/src/extension/paramcolor.cpp new file mode 100644 index 000000000..83dba1b2b --- /dev/null +++ b/src/extension/paramcolor.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould <ted@gould.cx> + * Johan Engelen <johan@shouraizou.nl> + * Christopher Brown <audiere@gmail.com> + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <iostream> +#include <sstream> + +#include <gtkmm/adjustment.h> +#include <gtkmm/box.h> +#include <gtkmm/spinbutton.h> + +#include <xml/node.h> + +#include "extension.h" +#include "paramcolor.h" + +#include "color.h" +#include "widgets/sp-color-selector.h" +#include "widgets/sp-color-notebook.h" + + +namespace Inkscape { +namespace Extension { + +void sp_color_param_changed(SPColorSelector *csel, GObject *cp); + + +/** \brief Free the allocated data. */ +ParamColor::~ParamColor(void) +{ + g_free(_value); +} + +SPColor* +ParamColor::set (SPColor* in, SPDocument * doc, Inkscape::XML::Node * node) +{ + _value = in; + + gchar * prefname = this->pref_name(); + prefs_set_string_attribute(PREF_DIR, prefname, this->string()->c_str()); + g_free(prefname); + + return _value; +} + +/** \brief Initialize the object, to do that, copy the data. */ +ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, ext), _value(NULL) +{ + const char * defaulthex = NULL; + if (sp_repr_children(xml) != NULL) + defaulthex = sp_repr_children(xml)->content(); + + gchar * pref_name = this->pref_name(); + const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name); + g_free(pref_name); + + if (paramval != NULL) + defaulthex = paramval; + + const char* hexMark = strchr(defaulthex, '#'); + if (hexMark != NULL) + defaulthex++;// = hexMark; + + if (strlen(defaulthex) == 6) { + int r = 0, g = 0, b = 0; + std::stringstream ss; + ss << strndup(defaulthex, 2); + ss >> std::hex >> r; + ss << strndup(defaulthex + 2, 2); + ss >> std::hex >> g; + ss << defaulthex + 4; + ss >> std::hex >> b; + g_free(ss); + + SPColor defaultColor; + sp_color_set_rgb_float(&defaultColor, r / 255.0, g / 255.0, b / 255.0); + _value = &defaultColor; + } + + return; +} + +/** \brief Return the value as a string */ +Glib::ustring * +ParamColor::string (void) +{ + float rgb[3]; + sp_color_get_rgb_floatv(_value, rgb); + char hex[8]; + snprintf(hex, 8, "#%02X%02X%02X", (int)(rgb[0] * 255), (int)(rgb[1] * 255), (int)(rgb[2] * 255)); + + Glib::ustring* ret = new Glib::ustring(hex); + + printf("ParamColor::string = '%s'\n", hex); + + return ret; +} + +Gtk::Widget * +ParamColor::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) +{ + _changeSignal = new sigc::signal<void>(*changeSignal); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK, SP_COLORSPACE_TYPE_RGB); + + ColorSelector* colorSelector = spColorSelector->base; + if (_value == NULL) { + _value = new SPColor(); + sp_color_set_rgb_float(_value, 1.0, 0.0, 0.0); + } + colorSelector->setColor(*_value); + + hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0); + g_signal_connect(G_OBJECT(spColorSelector), "dragged", G_CALLBACK(sp_color_param_changed), (void*)this); + g_signal_connect(G_OBJECT(spColorSelector), "released", G_CALLBACK(sp_color_param_changed), (void*)this); + g_signal_connect(G_OBJECT(spColorSelector), "changed", G_CALLBACK(sp_color_param_changed), (void*)this); + + gtk_widget_show(GTK_WIDGET(spColorSelector)); + hbox->show(); + + return dynamic_cast<Gtk::Widget *>(hbox); +} + +void +sp_color_param_changed(SPColorSelector *csel, GObject *obj) +{ + SPColor color; + float alpha; + csel->base->getColorAlpha(color, &alpha); + guint32 rgba = sp_color_get_rgba32_falpha(&color, alpha); + + + ParamColor* ptr = (ParamColor* )obj; + ptr->set(&color, NULL, NULL); + + ptr->_changeSignal->emit(); +} + +}; /* namespace Extension */ +}; /* namespace Inkscape */ |
