gradient-vector.cpp revision d2e42b9425ccd4c2d4c20c2217455da177035e48
/*
* Gradient vector selection widget
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* MenTaLguY <mental@rydia.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2001-2002 Lauris Kaplinski
* Copyright (C) 2001 Ximian, Inc.
* Copyright (C) 2004 Monash University
* Copyright (C) 2004 David Turner
* Copyright (C) 2006 MenTaLguY
* Copyright (C) 2010 Jon A. Cruz
*
* Released under GNU GPL, read the file 'COPYING' for more information
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glibmm.h>
#include "gradient-vector.h"
#include "ui/widget/color-preview.h"
#include "verbs.h"
#include "macros.h"
#include <set>
#include "widgets/gradient-image.h"
#include "inkscape.h"
#include "document-private.h"
#include "gradient-chemistry.h"
#include "io/resource.h"
#include "ui/dialog-events.h"
#include "preferences.h"
#include "svg/css-ostringstream.h"
#include "sp-stop.h"
#include "selection-chemistry.h"
#include "style.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "desktop.h"
#include "layer-manager.h"
#include "document-undo.h"
using Inkscape::DocumentUndo;
enum {
};
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
// TODO FIXME kill these globals!!!
static gint x = -1000, y = -1000, w = 0, h = 0; // impossible original values to make sure they are read from prefs
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
G_TYPE_NONE, 1,
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
{
#if GTK_CHECK_VERSION(3,0,0)
#endif
}
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
}
}
#if GTK_CHECK_VERSION(3,0,0)
}
#else
}
#endif
}
{
if (doc) {
} else {
}
return gvs;
}
void sp_gradient_vector_selector_set_gradient(SPGradientVectorSelector *gvs, SPDocument *doc, SPGradient *gr)
{
// g_message("sp_gradient_vector_selector_set_gradient(%p, %p, %p) [%s] %d %d", gvs, doc, gr,
// (gr ? gr->getId():"N/A"),
// (gr ? gr->isSwatch() : -1),
// (gr ? gr->isSolid() : -1));
/* Disconnect signals */
}
}
// Connect signals
if (doc) {
gvs->defs_release_connection = doc->getDefs()->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_gvs_defs_release), gvs));
gvs->defs_modified_connection = doc->getDefs()->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_gvs_defs_modified), gvs));
}
if (gr) {
gvs->gradient_release_connection = gr->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_gvs_gradient_release), gvs));
}
// Harder case - keep document, rebuild list and stuff
// fixme: (Lauris)
}
/* The case of setting NULL -> NULL is not very interesting */
}
{
}
{
}
{
if (!id) {
}
if (strlen(id) > 14 && (!strncmp (id, "linearGradient", 14) || !strncmp (id, "radialGradient", 14)))
}
/*
* Ellipse text if longer than maxlen, "50% start text + ... + ~50% end text"
* Text should be > length 8 or just return the original text
*/
{
}
return src;
}
{
/* Clear old list, if there is any */
/* Pick up all gradients with vectors */
}
}
}
/* Get usage count of all the gradients */
} else if (!gl) {
} else {
while (gl) {
SPGradient *gr;
}
}
}
/*
* Return a "HHSSLL" version of the first stop color so we can sort by it
*/
{
float hsl[3];
}
static GSList *get_all_doc_items(GSList *list, SPObject *from, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude)
{
if (SP_IS_ITEM(child)) {
}
}
}
return list;
}
/*
* Return a SPItem's gradient
*/
{
if (item_paint->isPaintserver()) {
}
}
return NULL;
}
/*
* Map each gradient to its usage count for both fill and stroke styles
*/
{
if (!doc)
return;
GSList *all_list = get_all_doc_items(NULL, doc->getRoot(), onlyvisible, onlysensitive, ingroups, NULL);
continue;
if (gr) {
}
if (gr) {
}
}
}
{
/* Disconnect gradient */
}
/* Rebuild GUI */
}
{
/* Disconnect gradient as well */
}
/* Rebuild GUI */
}
static void sp_gvs_defs_modified(SPObject */*defs*/, guint /*flags*/, SPGradientVectorSelector *gvs)
{
/* fixme: We probably have to check some flags here (Lauris) */
}
void SPGradientVectorSelector::setSwatched()
{
swatched = true;
sp_gvs_rebuild_gui_full(this);
}
/*##################################################################
### Vector Editing Widget
##################################################################*/
#include "widgets/sp-color-notebook.h"
#include "widgets/widget-sizes.h"
#include "xml/node-event-vector.h"
#include "svg/svg-color.h"
#define PAD 4
static gint sp_gradient_vector_dialog_delete(GtkWidget *widget, GdkEvent *event, GtkWidget *dialog);
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
static void grad_edit_dia_stop_added_or_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, gpointer data)
{
}
//FIXME!!! We must also listen to attr changes on all children (i.e. stops) too,
//otherwise the dialog does not reflect undoing color or offset change. This is a major
//hassle, unless we have a "one of the descendants changed in some way" signal.
{
grad_edit_dia_stop_added_or_removed, /* child_added */
grad_edit_dia_stop_added_or_removed, /* child_removed */
NULL, /* attr_changed*/
NULL, /* content_changed */
NULL /* order_changed */
};
{
int i = 0;
/* count stops */
if (SP_IS_STOP(ochild)) {
i++;
}
}
if (i < 1) {
}
if (i < 2) {
}
}
{
int i = 0;
if (SP_IS_STOP(ochild)) {
break;
}
i++;
}
}
}
{
if (!SP_IS_GRADIENT(gradient)) {
return;
}
/* Clear old list, if there is any */
if (!combo_box) {
return;
}
if (!store) {
return;
}
/* Populate the combobox store */
if (SP_IS_STOP(ochild)) {
}
}
}
if (!sl) {
} else {
Inkscape::UI::Widget::ColorPreview *cpv = Gtk::manage(new Inkscape::UI::Widget::ColorPreview(stop->get_rgba32()));
}
}
}
/* Set history */
} else {
}
}
// user selected existing stop from list
{
if (!stop) {
return;
}
SPColorSelector *csel = static_cast<SPColorSelector*>(g_object_get_data(G_OBJECT(tbl), "cselector"));
// set its color, from the stored array
bool isEndStop = false;
} else {
isEndStop = true;
gtk_adjustment_set_lower (adj, 0);
}
} else {
isEndStop = true;
}
//fixme: does this work on all possible input gradients?
if (!isEndStop) {
} else {
}
}
{
if (combo_box) {
}
}
return stop;
}
{
if (!blocked) {
if (stop) {
_("Change gradient stop offset"));
}
}
}
{
return SP_RGBA32_U_COMPOSE(r, g, b, a);
}
{
if (!stop) {
return;
}
}
}
} else {
}
gchar c[64];
sp_svg_write_color(c, sizeof(c), cnew);
_("Add gradient stop"));
}
{
if (!stop) {
return;
}
if (next) {
}
if (prev) {
}
}
_("Delete gradient stop"));
}
}
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
gtk_widget_show(w);
/* ComboBox of stops with 3 columns,
* The color preview, the label and a pointer to the SPStop
*/
/* Add and Remove buttons */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
// TRANSLATORS: "Stop" means: a "phase" of a gradient
gtk_widget_show(b);
gtk_widget_set_tooltip_text(b, _("Add another control stop to gradient"));
b = gtk_button_new_with_label(_("Delete stop"));
gtk_widget_show(b);
gtk_widget_set_tooltip_text(b, _("Delete current control stop from gradient"));
/* Offset Slider and stuff */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
/* Label */
gtk_widget_show(l);
/* Adjustment */
if (!stop) {
return NULL;
}
/* Slider */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
/* Spinbutton */
} else {
}
/* Signals */
// g_signal_connect(G_OBJECT(slider), "changed", G_CALLBACK(offsliderChanged), vb);
// TRANSLATORS: "Stop" means: a "phase" of a gradient
f = gtk_frame_new(_("Stop Color"));
gtk_widget_show(f);
if (select_stop) {
}
return vb;
}
{
if (x == -1000 || y == -1000) {
}
if (w ==0 || h == 0) {
}
if (x<0) {
x=0;
}
if (y<0) {
y=0;
}
if (x != 0 || y != 0) {
} else {
}
if (w && h) {
}
INKSCAPE.signal_activate_desktop.connect(sigc::bind(sigc::ptr_fun(&sp_transientize_callback), &wd));
sigc::bind(sigc::ptr_fun(&sp_gradient_vector_dialog_delete), (GtkWidget *) NULL, (GdkEvent *) NULL, (GtkWidget *) NULL)
));
/* Connect signals */
} else {
// FIXME: temp fix for 0.38
// Simply load_gradient into the editor does not work for multi-stop gradients,
// as the stop list and other widgets are in a wrong state and crash readily.
// Instead we just delete the window (by sending the delete signal)
// and call sp_gradient_vector_editor_new again, so it creates the window anew.
}
return dlg;
}
{
release_connection = static_cast<sigc::connection *>(g_object_get_data(G_OBJECT(widget), "gradient_release_connection"));
modified_connection = static_cast<sigc::connection *>(g_object_get_data(G_OBJECT(widget), "gradient_modified_connection"));
if (old) {
}
if (gradient) {
if (!release_connection) {
}
if (!modified_connection) {
}
*release_connection = gradient->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_gradient_vector_gradient_release), widget));
*modified_connection = gradient->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_gradient_vector_gradient_modified), widget));
} else {
if (release_connection) {
delete release_connection;
}
if (modified_connection) {
delete modified_connection;
}
}
}
if (gradient) {
gradient->ensureVector();
if (!stop) {
return;
}
// get the color selector
/* Fill preview */
// Once the user edits a gradient, it stops being auto-collectable
}
} else { // no gradient, disable everything
}
}
// \FIXME this
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
//sp_signal_disconnect_by_data(INKSCAPE, dlg);
}
static gboolean sp_gradient_vector_dialog_delete(GtkWidget */*widget*/, GdkEvent */*event*/, GtkWidget */*dialog*/)
{
if (x<0) {
x=0;
}
if (y<0) {
y=0;
}
return FALSE; // which means, go ahead and destroy it
}
/* Widget destroy handler */
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
sigc::connection *release_connection = static_cast<sigc::connection *>(g_object_get_data(G_OBJECT(object), "gradient_release_connection"));
sigc::connection *modified_connection = static_cast<sigc::connection *>(g_object_get_data(G_OBJECT(object), "gradient_modified_connection"));
if (gradient) {
}
}
}
{
}
static void sp_gradient_vector_gradient_modified(SPObject *object, guint /*flags*/, GtkWidget *widget)
{
if (!blocked) {
}
}
{
if (blocked) {
return;
}
if (!gradient) {
return;
}
/* Our master gradient has changed */
}
ngr->ensureVector();
if (!stop) {
return;
}
stop->currentColor = false;
}
{
if (blocked) {
return;
}
if (!gradient) {
return;
}
/* Our master gradient has changed */
}
ngr->ensureVector();
/* Set start parameters */
/* We rely on normalized vector, i.e. stops HAVE to exist */
if (!stop) {
return;
}
float alpha = 0;
// g_snprintf(c, 256, "stop-color:#%06x;stop-opacity:%g;", rgb >> 8, static_cast<gdouble>(alpha));
//stop->getRepr()->setAttribute("style", c);
_("Change gradient stop color"));
// Set the color in the selected stop after change
if (combo_box) {
Inkscape::UI::Widget::ColorPreview *cp = Gtk::manage(new Inkscape::UI::Widget::ColorPreview(stop->get_rgba32()));
}
}
}
/*
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 :