paint-selector.cpp revision f79230a9de342146783bf0ec0be886eea5d72e37
/**
* @file
* SPPaintSelector: Generic paint selector widget.
*/
/*
* Authors:
* Lauris Kaplinski
* bulia byak <buliabyak@users.sf.net>
* John Cliff <simarilius@yahoo.com>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) Lauris Kaplinski 2002
* Copyright (C) 2010 Authors
*/
#define noSP_PS_VERBOSE
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <cstring>
#include <string>
#include "widgets/swatch-selector.h"
#include "sp-pattern.h"
#include "widgets/widget-sizes.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "sp-mesh.h"
#include "sp-stop.h"
/* fixme: Move it from dialogs to here */
#include "gradient-selector.h"
#include <inkscape.h>
#include <document-private.h>
#include <desktop-style.h>
#include <style.h>
#include "svg/svg-color.h"
#include "svg/css-ostringstream.h"
#include "path-prefix.h"
#include "helper/stock-items.h"
#include "ui/icon-names.h"
#include "ui/widget/color-notebook.h"
#include "paint-selector.h"
#ifdef SP_PS_VERBOSE
#include "svg/svg-icc-color.h"
#endif // SP_PS_VERBOSE
enum {
};
static GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, gchar const *px, SPPaintSelector::Mode mode, gchar const *tip);
#ifdef SP_PS_VERBOSE
static gchar const* modeStrings[] = {
"MODE_EMPTY",
"MODE_MULTIPLE",
"MODE_NONE",
"MODE_SOLID_COLOR",
"MODE_GRADIENT_LINEAR",
"MODE_GRADIENT_RADIAL",
"MODE_PATTERN",
"MODE_SWATCH",
"MODE_UNSET",
".",
".",
".",
};
#endif
{
#ifdef WITH_MESH
#endif
return isGrad;
}
{
SPGradientSelector *grad = 0;
SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
if (swatchsel) {
}
} else {
grad = reinterpret_cast<SPGradientSelector*>(g_object_get_data(G_OBJECT(psel->selector), "gradient-selector"));
}
return grad;
}
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
static void
{
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
}
#define XPAD 4
#define YPAD 1
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#endif
psel->mode = static_cast<SPPaintSelector::Mode>(-1); // huh? do you mean 0xff? -- I think this means "not in the enum"
/* Paint style button box */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
/* Buttons */
#ifdef WITH_MESH
#endif
/* Fillrule */
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
GtkWidget *w;
// TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
gtk_widget_set_tooltip_text(psel->evenodd, _("Any path self-intersections or subpaths create holes in the fill (fill-rule: evenodd)"));
g_object_set_data(G_OBJECT(psel->evenodd), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_EVENODD));
g_signal_connect(G_OBJECT(psel->evenodd), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
// TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
gtk_widget_set_tooltip_text(psel->nonzero, _("Fill is solid unless a subpath is counterdirectional (fill-rule: nonzero)"));
g_object_set_data(G_OBJECT(psel->nonzero), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_NONZERO));
g_signal_connect(G_OBJECT(psel->nonzero), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
}
/* Frame */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
//gtk_container_set_border_width(GTK_CONTAINER(psel->frame), 0);
/* Last used color */
psel->updating_color = false;
psel->selected_color->signal_grabbed.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorGrabbed));
psel->selected_color->signal_dragged.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorDragged));
psel->selected_color->signal_released.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorReleased));
psel->selected_color->signal_changed.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorChanged));
}
{
// clean up our long-living pattern menu
if (psel->selected_color) {
delete psel->selected_color;
}
}
{
GtkWidget *b, *w;
b = gtk_toggle_button_new();
gtk_widget_show(b);
gtk_widget_show(w);
gtk_container_add(GTK_CONTAINER(b), w);
return b;
}
static void
{
psel->setMode(static_cast<SPPaintSelector::Mode>(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(tb), "mode"))));
}
}
static void
{
SPPaintSelector::FillRule fr = static_cast<SPPaintSelector::FillRule>(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(tb), "mode")));
}
}
static void
{
if (psel->fillrulebox) {
if (is_fill) {
} else {
}
}
}
{
// This silliness is here because I don't know how to pass a parameter to the
// GtkObject "constructor" (sp_paint_selector_init). Remove it when paint_selector
// becomes a normal class.
return psel;
}
{
#ifdef SP_PS_VERBOSE
g_print("Mode change %d -> %d %s -> %s\n", this->mode, mode, modeStrings[this->mode], modeStrings[mode]);
#endif
switch (mode) {
case MODE_EMPTY:
break;
case MODE_MULTIPLE:
break;
case MODE_NONE:
break;
case MODE_SOLID_COLOR:
sp_paint_selector_set_mode_color(this, mode);
break;
case MODE_GRADIENT_LINEAR:
case MODE_GRADIENT_RADIAL:
#ifdef WITH_MESH
case MODE_GRADIENT_MESH:
#endif
break;
case MODE_PATTERN:
break;
case MODE_SWATCH:
break;
case MODE_UNSET:
break;
default:
break;
}
}
}
{
if (fillrulebox) {
// TODO this flips widgets but does not use a member to store state. Revisit
}
}
{
/*
guint32 rgba = 0;
if ( sp_color_get_colorspace_type(color) == SP_COLORSPACE_TYPE_CMYK )
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set CMYKA\n");
#endif
sp_paint_selector_set_mode(psel, MODE_COLOR_CMYK);
}
else
*/
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set RGBA\n");
#endif
}
updating_color = true;
updating_color = false;
//rgba = color.toRGBA32( alpha );
}
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set SWATCH\n");
#endif
SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(selector), "swatch-selector"));
if (swatchsel) {
}
}
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set GRADIENT LINEAR\n");
#endif
}
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set GRADIENT RADIAL\n");
#endif
}
#ifdef WITH_MESH
{
#ifdef SP_PS_VERBOSE
g_print("PaintSelector set GRADIENT MESH\n");
#endif
}
#endif
{
}
void SPPaintSelector::getGradientProperties( SPGradientUnits &units, SPGradientSpread &spread) const
{
}
/**
* \post (alpha == NULL) || (*alpha in [0.0, 1.0]).
*/
{
&& ( alpha <= 1.0 ) );
}
{
SPGradient* vect = 0;
if (isPaintModeGradient(mode)) {
}
return vect;
}
{
gr->updateRepr();
}
static void
{
}
}
static void
{
}
static void
{
}
static void
{
}
static void
{
}
/* Color paint */
void SPPaintSelector::onSelectedColorGrabbed() {
}
void SPPaintSelector::onSelectedColorDragged() {
if (updating_color) {
return;
}
}
void SPPaintSelector::onSelectedColorReleased() {
}
void SPPaintSelector::onSelectedColorChanged() {
if (updating_color) {
return;
}
}
{
if (gsel) {
}
}
/* Already have color selector */
// Do nothing
} else {
/* Create new color selector */
/* Create vbox */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
/* Color selector */
color_selector->show();
/* Pack everything to frame */
}
#ifdef SP_PS_VERBOSE
g_print("Color req\n");
#endif
}
/* Gradient */
static void sp_paint_selector_gradient_grabbed(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
{
}
static void sp_paint_selector_gradient_dragged(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
{
}
static void sp_paint_selector_gradient_released(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
{
}
static void sp_paint_selector_gradient_changed(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
{
}
{
/* fixme: We do not need function-wide gsel at all */
}
#ifdef WITH_MESH
else {
}
#endif
if ((psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR) || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL)) {
/* Already have gradient selector */
} else {
/* Create new gradient selector */
g_signal_connect(G_OBJECT(gsel), "released", G_CALLBACK(sp_paint_selector_gradient_released), psel);
/* Pack everything to frame */
}
/* Actually we have to set option menu history here */
//sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_LINEAR);
}
#ifdef WITH_MESH
else {
}
#endif
#ifdef SP_PS_VERBOSE
g_print("Gradient req\n");
#endif
}
static void
{
#ifdef WITH_MESH
#endif
}
{
// drop our reference to the pattern menu widget
}
{
}
/**
* Returns a list of patterns in the defs of the given source document as a GSList object
* Returns NULL if there are no patterns in the document.
*/
static GSList *
{
return NULL;
}
}
return pl;
}
/**
* Adds menu items for pattern list - derived from marker code, left hb etc in to make addition of previews easier at some point.
*/
static void
{
// label for combobox
} else {
}
stockid = true;
}
COMBO_COL_LABEL, label, COMBO_COL_STOCK, stockid, COMBO_COL_PATTERN, patid, COMBO_COL_SEP, FALSE, -1);
}
}
/**
* Pick up all patterns from source, except those that are in
* current_doc (if non-NULL), and add items to the pattern menu.
*/
static void sp_pattern_list_from_doc(GtkWidget *combo, SPDocument * /*current_doc*/, SPDocument *source, SPDocument * /*pattern_doc*/)
{
continue;
}
// Add to the list of patterns we really do wish to show
}
g_slist_free (pl);
}
static void
{
// find and load patterns.svg
if (patterns_doc == NULL) {
}
}
// suck in from current doc
// add separator
{
}
// suck in from patterns.svg
if (patterns_doc) {
doc->ensureUpToDate();
}
}
static GtkWidget*
{
if (!doc) {
COMBO_COL_LABEL, _("No document selected"), COMBO_COL_STOCK, false, COMBO_COL_PATTERN, "", COMBO_COL_SEP, false, -1);
} else {
}
// Select the first item that is not a seperator
if (sep) {
}
}
return combo;
}
/*update pattern list*/
{
if (update) {
return;
}
/* Clear existing menu if any */
/* Set history */
// Find this pattern and set it active in the combo_box
if (!valid) {
return;
}
}
if (valid) {
}
}
}
{
}
/* Already have pattern menu */
} else {
/* Create vbox */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
/**
* Create a combo_box and store with 4 columns,
* The label, a pointer to the pattern, is stockid or not, is a separator or not.
*/
GtkListStore *store = gtk_list_store_new (COMBO_N_COLS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_BOOLEAN);
gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combo), SPPaintSelector::isSeparator, NULL, NULL);
}
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
gtk_label_set_markup(GTK_LABEL(l), _("Use the <b>Node tool</b> to adjust position, scale, and rotation of the pattern on canvas. Use <b>Object > Pattern > Objects to Pattern</b> to create a new pattern from selection."));
gtk_label_set_line_wrap(GTK_LABEL(l), true);
}
}
#ifdef SP_PS_VERBOSE
g_print("Pattern req\n");
#endif
}
return sep;
}
{
/* no pattern menu if we were just selected */
return NULL;
}
/* Get the selected pattern */
return NULL;
}
gtk_tree_model_get (store, &iter, COMBO_COL_LABEL, &label, COMBO_COL_STOCK, &stockid, COMBO_COL_PATTERN, &patid, -1);
return NULL;
}
if (stockid) {
}
else {
}
if (pat_obj) {
}
} else {
}
pat = 0;
}
return pat;
}
{
}
// swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
} else {
// Create new gradient selector
// Pack everything to frame
}
#ifdef SP_PS_VERBOSE
g_print("Swatch req\n");
#endif
}
// TODO this seems very bad to be taking in a desktop pointer to muck with. Logic probably belongs elsewhere
void SPPaintSelector::setFlatColor( SPDesktop *desktop, gchar const *color_property, gchar const *opacity_property )
{
#ifdef SP_PS_VERBOSE
g_message("sp_paint_selector_set_flat_color() to '%s' from 0x%08x::%s",
rgba,
#endif // SP_PS_VERBOSE
}
{
mode = MODE_UNSET;
} else if ( target.isPaintserver() ) {
SPPaintServer const *server = (kind == FILL) ? style.getFillPaintServer() : style.getStrokePaintServer();
#ifdef SP_PS_VERBOSE
g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n"));
#endif // SP_PS_VERBOSE
mode = MODE_SWATCH;
} else if (SP_IS_LINEARGRADIENT(server)) {
} else if (SP_IS_RADIALGRADIENT(server)) {
#ifdef WITH_MESH
} else if (SP_IS_MESH(server)) {
#endif
} else if (SP_IS_PATTERN(server)) {
mode = MODE_PATTERN;
} else {
}
// TODO this is no longer a valid assertion:
} else {
}
return mode;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :