gradient-vector.cpp revision 65ad200c98b082f9ec02ce216f0a8fc146ac1bab
/*
* 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
#ifdef HAVE_STRING_H
#endif
#include "macros.h"
#include "../widgets/gradient-image.h"
#include "../inkscape.h"
#include "../document-private.h"
#include "../gradient-chemistry.h"
#include "gradient-vector.h"
#include "../dialogs/dialog-events.h"
#include "../preferences.h"
#include "svg/css-ostringstream.h"
#include "sp-stop.h"
using Inkscape::DocumentUndo;
enum {
};
static GtkVBoxClass *parent_class;
// 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 (!type) {
sizeof(SPGradientVectorSelectorClass),
NULL, /* base_init */
NULL, /* base_finalize */
reinterpret_cast<GClassInitFunc>(sp_gradient_vector_selector_class_init),
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(SPGradientVectorSelector),
0, /* n_preallocs */
reinterpret_cast<GInstanceInitFunc>(sp_gradient_vector_selector_init),
0, /* value_table */
};
"SPGradientVectorSelector",
&info,
static_cast< GTypeFlags >(0) );
}
return type;
}
{
G_TYPE_NONE, 1,
}
{
}
{
}
}
}
}
{
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 menus and stuff
// fixme: (Lauris)
}
/* The case of setting NULL -> NULL is not very interesting */
}
{
}
{
}
{
/* Clear old menu, if there is any */
}
/* Create new menu widget */
GtkWidget *m = gtk_menu_new();
gtk_widget_show(m);
/* Pick up all gradients with vectors */
}
}
}
GtkWidget *i;
i = gtk_menu_item_new_with_label(_("No document selected"));
gtk_widget_show(i);
gtk_menu_shell_append(GTK_MENU_SHELL(m), i);
} else if (!gl) {
GtkWidget *i;
i = gtk_menu_item_new_with_label(_("No gradients in document"));
gtk_widget_show(i);
gtk_menu_shell_append(GTK_MENU_SHELL(m), i);
GtkWidget *i;
i = gtk_menu_item_new_with_label(_("No gradient selected"));
gtk_widget_show(i);
gtk_menu_shell_append(GTK_MENU_SHELL(m), i);
} else {
while (gl) {
SPGradient *gr;
GtkWidget *i, *w;
/* We have to know: */
/* Gradient destroy */
/* Gradient name change */
i = gtk_menu_item_new();
gtk_widget_show(i);
w = sp_gradient_image_new(gr);
gtk_widget_show(w);
gtk_widget_show(l);
w = hb;
}
gtk_container_add(GTK_CONTAINER(i), w);
gtk_menu_shell_append(GTK_MENU_SHELL(m), i);
}
idx += 1;
}
}
/* Set history */
}
{
/* Hmmm... bad things may happen here, if actual gradient is something new */
/* Namely - menuitems etc. will be fucked up */
/* Hmmm - probably we can just re-set it as menuitem data (Lauris) */
//g_print("SPGradientVectorSelector: gradient %s activated\n", gr->getId());
//g_message("Setting to gradient %p swatch:%d solid:%d", gr, gr->isSwatch(), gr->isSolid());
//g_print("SPGradientVectorSelector: become %s after normalization\n", norm->getId());
/* But be careful that we do not have gradient saved anywhere else */
}
/* fixme: Really we would want to use _set_vector */
/* Detach old */
}
/* Attach new */
if (norm) {
gvs->gradient_release_connection = norm->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_gvs_gradient_release), gvs));
}
/* We do extra undo push here */
/* If handler has already done it, it is just NOP */
// FIXME: looks like this is never a valid undo step, consider removing this
/* TODO: annotate */ "gradient-vector.cpp:350");
}
}
{
/* 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 "ui/widget/color-preview.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);
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 menu, if there is any */
}
/* Create new menu widget */
GtkWidget *m = gtk_menu_new();
gtk_widget_show(m);
if (SP_IS_STOP(ochild)) {
}
}
}
if (!sl) {
gtk_widget_show(i);
gtk_menu_shell_append(GTK_MENU_SHELL(m), i);
} else {
GtkWidget *i = gtk_menu_item_new();
gtk_widget_show(i);
gtk_widget_show(l);
gtk_menu_shell_append(GTK_MENU_SHELL(m), i);
}
}
}
/* Set history */
} else {
}
}
// user selected existing stop from list
{
if (!stop) {
return;
}
// 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 (!blocked) {
if ( g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop") ) {
SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
_("Change gradient stop offset"));
}
}
}
{
return SP_RGBA32_U_COMPOSE(r, g, b, a);
}
{
SPStop *stop = static_cast<SPStop *>(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
return;
}
}
}
} else {
}
gchar c[64];
sp_svg_write_color(c, sizeof(c), cnew);
_("Add gradient stop"));
}
{
if (!g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop")) return;
SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
if (next) {
}
if (prev) {
}
}
_("Delete gradient stop"));
}
}
{
gtk_widget_show(w);
/* Stop list */
/* Create new menu widget */
/* Add and Remove buttons */
// 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 */
/* Label */
gtk_widget_show(l);
/* Adjustment */
/* Slider */
/* 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) {
}
g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(sp_transientize_callback), &wd);
g_signal_connect(G_OBJECT(INKSCAPE), "shut_down", G_CALLBACK(sp_gradient_vector_dialog_delete), dlg);
/* 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 = (sigc::connection *)g_object_get_data(G_OBJECT(widget), "gradient_release_connection");
modified_connection = (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();
SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
// get the color selector
/* Fill preview */
// Once the user edits a gradient, it stops being auto-collectable
}
} else { // no gradient, disable everything
}
}
{
}
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 */
{
sigc::connection *release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(object), "gradient_release_connection");
sigc::connection *modified_connection = (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();
SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
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 */
SPStop *stop = SP_STOP(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "stop"));
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"));
Inkscape::UI::Widget::ColorPreview *cpv = static_cast<Inkscape::UI::Widget::ColorPreview *>(g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(mnu)))), "preview"));
}
/*
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 :