spiral-toolbar.cpp revision 0de73848362e95b081e5fa85f910d6481094b2b9
1494N/A/**
1683N/A * @file
1494N/A * Spiral aux toolbar
1494N/A */
1494N/A/* Authors:
1494N/A * MenTaLguY <mental@rydia.net>
1494N/A * Lauris Kaplinski <lauris@kaplinski.com>
1494N/A * bulia byak <buliabyak@users.sf.net>
1494N/A * Frank Felfe <innerspace@iname.com>
1494N/A * John Cliff <simarilius@yahoo.com>
1494N/A * David Turner <novalis@gnu.org>
1494N/A * Josh Andler <scislac@scislac.com>
1494N/A * Jon A. Cruz <jon@joncruz.org>
1494N/A * Maximilian Albert <maximilian.albert@gmail.com>
1494N/A * Tavmjong Bah <tavmjong@free.fr>
1494N/A * Abhishek Sharma
1494N/A * Kris De Gussem <Kris.DeGussem@gmail.com>
1494N/A *
1494N/A * Copyright (C) 2004 David Turner
1494N/A * Copyright (C) 2003 MenTaLguY
1494N/A * Copyright (C) 1999-2011 authors
1494N/A * Copyright (C) 2001-2002 Ximian, Inc.
1494N/A *
1494N/A * Released under GNU GPL, read the file 'COPYING' for more information
1494N/A */
1494N/A
1494N/A#ifdef HAVE_CONFIG_H
1494N/A# include "config.h"
1494N/A#endif
1494N/A
1494N/A#include <glibmm/i18n.h>
1494N/A
1494N/A#include "spiral-toolbar.h"
1494N/A
1494N/A#include "desktop.h"
1494N/A#include "document-undo.h"
1494N/A#include "widgets/ege-adjustment-action.h"
1494N/A#include "widgets/ege-output-action.h"
1494N/A#include "widgets/ink-action.h"
1494N/A#include "preferences.h"
1494N/A#include "selection.h"
1494N/A#include "sp-spiral.h"
1494N/A#include "toolbox.h"
1494N/A#include "ui/icon-names.h"
1494N/A#include "ui/uxmanager.h"
1494N/A#include "verbs.h"
1494N/A#include "widgets/spinbutton-events.h"
1494N/A#include "xml/node-event-vector.h"
1494N/A#include "xml/node.h"
1494N/A#include "xml/repr.h"
1494N/A
1494N/Ausing Inkscape::UI::UXManager;
1494N/Ausing Inkscape::DocumentUndo;
1494N/Ausing Inkscape::UI::ToolboxFactory;
1494N/Ausing Inkscape::UI::PrefPusher;
1494N/A
1494N/A//########################
1494N/A//## Spiral ##
1494N/A//########################
1494N/A
1494N/Astatic void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustring const &value_name)
1494N/A{
1494N/A SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
1494N/A
1494N/A if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
1494N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1494N/A prefs->setDouble("/tools/shapes/spiral/" + value_name,
1494N/A gtk_adjustment_get_value(adj));
1494N/A }
1494N/A
1494N/A // quit if run by the attr_changed listener
1494N/A if (g_object_get_data( tbl, "freeze" )) {
1494N/A return;
1494N/A }
1494N/A
1494N/A // in turn, prevent listener from responding
1494N/A g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
1494N/A
1494N/A gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL);
1494N/A
1494N/A bool modmade = false;
1494N/A SelContainer itemlist=desktop->getSelection()->itemList();
1494N/A for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
1494N/A SPItem *item = SP_ITEM(*i);
1494N/A if (SP_IS_SPIRAL(item)) {
1494N/A Inkscape::XML::Node *repr = item->getRepr();
1494N/A sp_repr_set_svg_double( repr, namespaced_name,
1494N/A gtk_adjustment_get_value(adj) );
1494N/A item->updateRepr();
1494N/A modmade = true;
1494N/A }
1494N/A }
1494N/A
1494N/A g_free(namespaced_name);
1494N/A
1494N/A if (modmade) {
1494N/A DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_SPIRAL,
1494N/A _("Change spiral"));
1494N/A }
1494N/A
1494N/A g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
1494N/A}
1494N/A
1494N/Astatic void sp_spl_tb_revolution_value_changed(GtkAdjustment *adj, GObject *tbl)
1494N/A{
1494N/A sp_spl_tb_value_changed(adj, tbl, "revolution");
1494N/A}
1494N/A
1494N/Astatic void sp_spl_tb_expansion_value_changed(GtkAdjustment *adj, GObject *tbl)
1494N/A{
1494N/A sp_spl_tb_value_changed(adj, tbl, "expansion");
1494N/A}
1494N/A
1494N/Astatic void sp_spl_tb_t0_value_changed(GtkAdjustment *adj, GObject *tbl)
1494N/A{
1494N/A sp_spl_tb_value_changed(adj, tbl, "t0");
1494N/A}
1494N/A
1494N/Astatic void sp_spl_tb_defaults(GtkWidget * /*widget*/, GObject *obj)
1494N/A{
1494N/A GtkWidget *tbl = GTK_WIDGET(obj);
1494N/A
1494N/A GtkAdjustment *adj;
1494N/A
1494N/A // fixme: make settable
1494N/A gdouble rev = 3;
1494N/A gdouble exp = 1.0;
1494N/A gdouble t0 = 0.0;
1494N/A
1494N/A adj = GTK_ADJUSTMENT(g_object_get_data(obj, "revolution"));
1494N/A gtk_adjustment_set_value(adj, rev);
1494N/A gtk_adjustment_value_changed(adj);
1494N/A
1494N/A adj = GTK_ADJUSTMENT(g_object_get_data(obj, "expansion"));
1494N/A gtk_adjustment_set_value(adj, exp);
1494N/A gtk_adjustment_value_changed(adj);
1494N/A
1494N/A adj = GTK_ADJUSTMENT(g_object_get_data(obj, "t0"));
1494N/A gtk_adjustment_set_value(adj, t0);
1494N/A gtk_adjustment_value_changed(adj);
1494N/A
1494N/A spinbutton_defocus(tbl);
1494N/A}
1494N/A
1494N/A
1494N/Astatic void spiral_tb_event_attr_changed(Inkscape::XML::Node *repr,
1494N/A gchar const * /*name*/,
1494N/A gchar const * /*old_value*/,
1494N/A gchar const * /*new_value*/,
1494N/A bool /*is_interactive*/,
1494N/A gpointer data)
1494N/A{
1494N/A GtkWidget *tbl = GTK_WIDGET(data);
1494N/A
1494N/A // quit if run by the _changed callbacks
1494N/A if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
1494N/A return;
1494N/A }
1494N/A
1494N/A // in turn, prevent callbacks from responding
1494N/A g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(TRUE));
1494N/A
1494N/A GtkAdjustment *adj;
1494N/A adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "revolution"));
1494N/A double revolution = 3.0;
1494N/A sp_repr_get_double(repr, "sodipodi:revolution", &revolution);
1494N/A gtk_adjustment_set_value(adj, revolution);
1494N/A
1494N/A adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "expansion"));
1494N/A double expansion = 1.0;
1494N/A sp_repr_get_double(repr, "sodipodi:expansion", &expansion);
1494N/A gtk_adjustment_set_value(adj, expansion);
1494N/A
1494N/A adj = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(tbl), "t0"));
1494N/A double t0 = 0.0;
1494N/A sp_repr_get_double(repr, "sodipodi:t0", &t0);
1494N/A gtk_adjustment_set_value(adj, t0);
1494N/A
1494N/A g_object_set_data(G_OBJECT(tbl), "freeze", GINT_TO_POINTER(FALSE));
1494N/A}
1494N/A
1494N/A
1494N/Astatic Inkscape::XML::NodeEventVector spiral_tb_repr_events = {
1494N/A NULL, /* child_added */
1494N/A NULL, /* child_removed */
1494N/A spiral_tb_event_attr_changed,
1494N/A NULL, /* content_changed */
1494N/A NULL /* order_changed */
1494N/A};
1494N/A
1494N/Astatic void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl)
1494N/A{
1494N/A int n_selected = 0;
1494N/A Inkscape::XML::Node *repr = NULL;
1494N/A
1494N/A purge_repr_listener( tbl, tbl );
1494N/A
1494N/A SelContainer itemlist=selection->itemList();
1494N/A for(SelContainer::const_iterator i=itemlist.begin();i!=itemlist.end();i++){
1494N/A SPItem *item = SP_ITEM(*i);
1494N/A if (SP_IS_SPIRAL(item)) {
1494N/A n_selected++;
1494N/A repr = item->getRepr();
1494N/A }
1494N/A }
1494N/A
1494N/A EgeOutputAction* act = EGE_OUTPUT_ACTION( g_object_get_data( tbl, "mode_action" ) );
1494N/A
1494N/A if (n_selected == 0) {
1494N/A g_object_set( G_OBJECT(act), "label", _("<b>New:</b>"), NULL );
1494N/A } else if (n_selected == 1) {
1494N/A g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
1494N/A
1494N/A if (repr) {
1494N/A g_object_set_data( tbl, "repr", repr );
1494N/A Inkscape::GC::anchor(repr);
1494N/A sp_repr_add_listener(repr, &spiral_tb_repr_events, tbl);
1494N/A sp_repr_synthesize_events(repr, &spiral_tb_repr_events, tbl);
1494N/A }
1494N/A } else {
1494N/A // FIXME: implement averaging of all parameters for multiple selected
1494N/A //gtk_label_set_markup(GTK_LABEL(l), _("<b>Average:</b>"));
1494N/A g_object_set( G_OBJECT(act), "label", _("<b>Change:</b>"), NULL );
1494N/A }
1494N/A}
1494N/A
1494N/A
1494N/Avoid sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
1494N/A{
1494N/A EgeAdjustmentAction* eact = 0;
1494N/A Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
1494N/A
1494N/A {
1494N/A EgeOutputAction* act = ege_output_action_new( "SpiralStateAction", _("<b>New:</b>"), "", 0 );
1494N/A ege_output_action_set_use_markup( act, TRUE );
1494N/A gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
1494N/A g_object_set_data( holder, "mode_action", act );
1494N/A }
1494N/A
1494N/A /* Revolution */
1494N/A {
1494N/A gchar const* labels[] = {_("just a curve"), 0, _("one full revolution"), 0, 0, 0, 0, 0, 0};
1494N/A gdouble values[] = {0.01, 0.5, 1, 2, 3, 5, 10, 20, 50, 100};
1494N/A eact = create_adjustment_action( "SpiralRevolutionAction",
1494N/A _("Number of turns"), _("Turns:"), _("Number of revolutions"),
1494N/A "/tools/shapes/spiral/revolution", 3.0,
1494N/A GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-spiral",
1494N/A 0.01, 1024.0, 0.1, 1.0,
1494N/A labels, values, G_N_ELEMENTS(labels),
1494N/A sp_spl_tb_revolution_value_changed, NULL /*unit tracker*/, 1, 2);
1494N/A gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1494N/A }
1494N/A
1494N/A /* Expansion */
1494N/A {
1494N/A gchar const* labels[] = {_("circle"), _("edge is much denser"), _("edge is denser"), _("even"), _("center is denser"), _("center is much denser"), 0};
1494N/A gdouble values[] = {0, 0.1, 0.5, 1, 1.5, 5, 20};
1494N/A eact = create_adjustment_action( "SpiralExpansionAction",
1494N/A _("Divergence"), _("Divergence:"), _("How much denser/sparser are outer revolutions; 1 = uniform"),
1494N/A "/tools/shapes/spiral/expansion", 1.0,
1494N/A GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
1494N/A 0.0, 1000.0, 0.01, 1.0,
1494N/A labels, values, G_N_ELEMENTS(labels),
1494N/A sp_spl_tb_expansion_value_changed);
1494N/A gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1494N/A }
1494N/A
1494N/A /* T0 */
1494N/A {
1494N/A gchar const* labels[] = {_("starts from center"), _("starts mid-way"), _("starts near edge")};
1494N/A gdouble values[] = {0, 0.5, 0.9};
1494N/A eact = create_adjustment_action( "SpiralT0Action",
1494N/A _("Inner radius"), _("Inner radius:"), _("Radius of the innermost revolution (relative to the spiral size)"),
1494N/A "/tools/shapes/spiral/t0", 0.0,
1494N/A GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
1494N/A 0.0, 0.999, 0.01, 1.0,
1494N/A labels, values, G_N_ELEMENTS(labels),
1494N/A sp_spl_tb_t0_value_changed);
1494N/A gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
1494N/A }
1494N/A
1494N/A /* Reset */
1494N/A {
1494N/A InkAction* inky = ink_action_new( "SpiralResetAction",
1494N/A _("Defaults"),
1494N/A _("Reset shape parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
1494N/A INKSCAPE_ICON("edit-clear"),
1494N/A secondarySize );
1494N/A g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_spl_tb_defaults), holder );
1494N/A gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
1494N/A }
1494N/A
1494N/A
1494N/A sigc::connection *connection = new sigc::connection(
1494N/A desktop->getSelection()->connectChanged(sigc::bind(sigc::ptr_fun(sp_spiral_toolbox_selection_changed), holder))
1494N/A );
1494N/A g_signal_connect( holder, "destroy", G_CALLBACK(delete_connection), connection );
1494N/A g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
1494N/A}
1494N/A
1494N/A
1494N/A/*
1494N/A Local Variables:
1494N/A mode:c++
1494N/A c-file-style:"stroustrup"
1494N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1494N/A indent-tabs-mode:nil
1494N/A fill-column:99
1494N/A End:
1494N/A*/
1494N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
1494N/A