diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2012-05-23 12:00:49 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2012-05-23 12:00:49 +0000 |
| commit | 0ea9b448ee16fe941d46395c2877f4d2e815b9ed (patch) | |
| tree | a49cb57d691df46475d1e9fe197aeade8b0fa10c /src/widgets | |
| parent | Correct improper flipping of sRGB transform from RGB to BGR with cairo change... (diff) | |
| download | inkscape-0ea9b448ee16fe941d46395c2877f4d2e815b9ed.tar.gz inkscape-0ea9b448ee16fe941d46395c2877f4d2e815b9ed.zip | |
Add Mesh tool (experimental, requires Cario >= 1.11.4, disabled by default).
(bzr r11406)
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/widgets/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/widgets/gradient-toolbar.h | 2 | ||||
| -rw-r--r-- | src/widgets/mesh-toolbar.cpp | 373 | ||||
| -rw-r--r-- | src/widgets/mesh-toolbar.h | 22 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 23 |
6 files changed, 421 insertions, 3 deletions
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 8ae6441c3..38180bd69 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -9,6 +9,7 @@ set(widgets_SRC erasor-toolbar.cpp lpe-toolbar.cpp measure-toolbar.cpp + mesh-toolbar.cpp node-toolbar.cpp paintbucket-toolbar.cpp pencil-toolbar.cpp @@ -65,6 +66,7 @@ set(widgets_SRC erasor-toolbar.h lpe-toolbar.h measure-toolbar.h + mesh-toolbar.h node-toolbar.h paintbucket-toolbar.h pencil-toolbar.h diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert index 439b5c3d4..7d6b413bd 100644 --- a/src/widgets/Makefile_insert +++ b/src/widgets/Makefile_insert @@ -42,6 +42,8 @@ ink_common_sources += \ widgets/lpe-toolbar.h \ widgets/measure-toolbar.cpp \ widgets/measure-toolbar.h \ + widgets/mesh-toolbar.cpp \ + widgets/mesh-toolbar.h \ widgets/node-toolbar.cpp \ widgets/node-toolbar.h \ widgets/paint-selector.cpp \ diff --git a/src/widgets/gradient-toolbar.h b/src/widgets/gradient-toolbar.h index 938f45dc6..980a41a83 100644 --- a/src/widgets/gradient-toolbar.h +++ b/src/widgets/gradient-toolbar.h @@ -17,4 +17,4 @@ struct SPDesktop; void sp_gradient_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder); -#endif /* !SEEN_SELECT_TOOLBAR_H */ +#endif /* !SEEN_GRADIENT_TOOLBAR_H */ diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp new file mode 100644 index 000000000..7c37d757c --- /dev/null +++ b/src/widgets/mesh-toolbar.cpp @@ -0,0 +1,373 @@ +/* + * Gradient aux toolbar + * + * Authors: + * bulia byak <bulia@dr.com> + * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> + * Abhishek Sharma + * Tavmjong Bah <tavjong@free.fr> + * + * Copyright (C) 2012 Tavmjong Bah + * Copyright (C) 2007 Johan Engelen + * Copyright (C) 2005 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +// REVIEW THESE AT END OF REWRITE +#include "toolbox.h" +#include "mesh-toolbar.h" + +#include "ui/widget/color-preview.h" +#include "verbs.h" + +#include "macros.h" +#include "widgets/button.h" +#include "widgets/widget-sizes.h" +#include "widgets/spw-utilities.h" +#include "widgets/spinbutton-events.h" +#include "widgets/gradient-vector.h" +#include "widgets/gradient-image.h" +#include "style.h" + +#include "preferences.h" +#include "document-private.h" +#include "document-undo.h" +#include "desktop.h" +#include "desktop-handles.h" +#include <glibmm/i18n.h> + +#include "gradient-context.h" +#include "gradient-drag.h" +#include "sp-mesh-gradient.h" +#include "gradient-chemistry.h" +#include "gradient-selector.h" +#include "selection.h" +#include "ui/icon-names.h" + +#include "../ege-adjustment-action.h" +#include "../ege-output-action.h" +#include "../ege-select-one-action.h" +#include "../ink-action.h" +#include "../ink-comboboxentry-action.h" + +#include "sp-stop.h" +#include "svg/css-ostringstream.h" +#include "svg/svg-color.h" +#include "desktop-style.h" +#include "gradient-context.h" + +#include "toolbox.h" + +using Inkscape::DocumentUndo; +using Inkscape::UI::ToolboxFactory; +using Inkscape::UI::PrefPusher; + +static gboolean blocked = FALSE; + +//######################## +//## Mesh ## +//######################## + +/* + * Core function, setup all the widgets whenever something changes on the desktop + */ +static void ms_tb_selection_changed(Inkscape::Selection * /*selection*/, gpointer data) +{ + // DOES NOTHING AT MOMENT + + // std::cout << "ms_tb_selection_changed" << std::endl; + + // if (blocked) + // return; + + // GtkWidget *widget = GTK_WIDGET(data); + + // SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(G_OBJECT(widget), "desktop")); + // if (!desktop) { + // return; + // } + + // Inkscape::Selection *selection = sp_desktop_selection(desktop); // take from desktop, not from args + // if (selection) { + // SPEventContext *ev = sp_desktop_event_context(desktop); + // GrDrag *drag = NULL; + // if (ev) { + // drag = ev->get_drag(); + // // Hide/show handles? + // } + + // } +} + + +static void ms_tb_selection_modified(Inkscape::Selection *selection, guint /*flags*/, gpointer data) +{ + ms_tb_selection_changed(selection, data); +} + +static void ms_drag_selection_changed(gpointer /*dragger*/, gpointer data) +{ + ms_tb_selection_changed(NULL, data); + +} + +static void ms_defs_release(SPObject * defs, GtkWidget *widget) +{ + ms_tb_selection_changed(NULL, (gpointer) widget); +} + +static void ms_defs_modified(SPObject * /*defs*/, guint /*flags*/, GtkWidget *widget) +{ + ms_tb_selection_changed(NULL, (gpointer) widget); +} + +static void ms_disconnect_sigc(GObject * /*obj*/, sigc::connection *connection) { + connection->disconnect(); + delete connection; +} + + +/* + * Callback functions for user actions + */ + +static void ms_new_type_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gint typemode = ege_select_one_action_get_active( act ) == 0 ? SP_GRADIENT_MESH_TYPE_NORMAL : SP_GRADIENT_MESH_TYPE_CONICAL; + prefs->setInt("/tools/mesh/mesh_type", typemode); +} + +static void ms_new_fillstroke_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Inkscape::PaintTarget fsmode = (ege_select_one_action_get_active( act ) == 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; + prefs->setInt("/tools/gradient/newfillorstroke", (fsmode == Inkscape::FOR_FILL) ? 1 : 0); +} + +static void ms_row_changed (GtkAdjustment *adj, GObject *tbl ) { + + if (blocked) { + return; + } + + blocked = TRUE; + + int rows = gtk_adjustment_get_value(adj); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + prefs->setInt("/tools/mesh/mesh_rows", rows); + + blocked = FALSE; +} + +static void ms_col_changed (GtkAdjustment *adj, GObject *tbl ) { + + if (blocked) { + return; + } + + blocked = TRUE; + + int cols = gtk_adjustment_get_value(adj); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + prefs->setInt("/tools/mesh/mesh_cols", cols); + + blocked = FALSE; +} + +static void ms_edit_fillstroke_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Inkscape::PaintTarget fsmode = (ege_select_one_action_get_active( act ) == 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; + prefs->setInt("/tools/gradient/editfillorstroke", (fsmode == Inkscape::FOR_FILL) ? 1 : 0); +} + +/** + * Mesh auxiliary toolbar construction and setup. + * + */ +void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) +{ + Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); + + EgeAdjustmentAction* eact = 0; + + /* New mesh: normal or conical */ + { + GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); + + GtkTreeIter iter; + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("normal"), 1, _("Create mesh gradient"), 2, INKSCAPE_ICON("paint-gradient-mesh"), -1 ); + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("conical"), 1, _("Create conical gradient"), 2, INKSCAPE_ICON("paint-gradient-conical"), -1 ); + + EgeSelectOneAction* act = ege_select_one_action_new( "MeshNewTypeAction", (""), (""), NULL, GTK_TREE_MODEL(model) ); + g_object_set( act, "short_label", _("New:"), NULL ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "mesh_new_type_action", act ); + + ege_select_one_action_set_appearance( act, "full" ); + ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE ); + g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL ); + ege_select_one_action_set_icon_column( act, 2 ); + ege_select_one_action_set_tooltip_column( act, 1 ); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gint mode = prefs->getInt("/tools/mesh/mesh_type", SP_GRADIENT_MESH_TYPE_NORMAL) != SP_GRADIENT_MESH_TYPE_NORMAL; + ege_select_one_action_set_active( act, mode ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(ms_new_type_changed), holder ); + } + + /* New gradient on fill or stroke*/ + { + GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); + + GtkTreeIter iter; + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("fill"), 1, _("Create gradient in the fill"), 2, INKSCAPE_ICON("object-fill"), -1 ); + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("stroke"), 1, _("Create gradient in the stroke"), 2, INKSCAPE_ICON("object-stroke"), -1 ); + + EgeSelectOneAction* act = ege_select_one_action_new( "MeshNewFillStrokeAction", (""), (""), NULL, GTK_TREE_MODEL(model) ); + g_object_set( act, "short_label", _("on:"), NULL ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "mesh_new_fillstroke_action", act ); + + ege_select_one_action_set_appearance( act, "full" ); + ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE ); + g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL ); + ege_select_one_action_set_icon_column( act, 2 ); + ege_select_one_action_set_tooltip_column( act, 1 ); + + /// @todo Convert to boolean? + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool fillstrokemode = !prefs->getBool("/tools/gradient/newfillorstroke", true); + ege_select_one_action_set_active( act, fillstrokemode ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(ms_new_fillstroke_changed), holder ); + } + + /* Number of mesh rows */ + { + gchar const* labels[] = {}; + gdouble values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + eact = create_adjustment_action( "MeshRowAction", + _("Rows"), _("Rows:"), _("Number of rows in new mesh"), + "/tools/mesh/mesh_rows", 1, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + 1, 20, 1, 1, + labels, values, G_N_ELEMENTS(labels), + ms_row_changed, + 1.0, 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } + + /* Number of mesh columns */ + { + gchar const* labels[] = {}; + gdouble values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + eact = create_adjustment_action( "MeshColumnAction", + _("Columns"), _("Columns:"), _("Number of columns in new mesh"), + "/tools/mesh/mesh_cols", 1, + GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + 1, 20, 1, 1, + labels, values, G_N_ELEMENTS(labels), + ms_col_changed, + 1.0, 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } + + /* Edit fill mesh */ + { + InkToggleAction* act = ink_toggle_action_new( "MeshEditFillAction", + _("Edit Fill"), + _("Edit fill mesh"), + INKSCAPE_ICON("object-fill"), + secondarySize ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/mesh/edit_fill"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } + + /* Edit stroke mesh */ + { + InkToggleAction* act = ink_toggle_action_new( "MeshEditStrokeAction", + _("Edit Stroke"), + _("Edit stroke mesh"), + INKSCAPE_ICON("object-stroke"), + secondarySize ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/mesh/edit_stroke"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } + + /* Show/hide side and tensor handles */ + { + InkToggleAction* act = ink_toggle_action_new( "MeshShowHandlesAction", + _("Show Handles"), + _("Show side and tensor handles"), + INKSCAPE_ICON("show-node-handles"), + secondarySize ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/mesh/show_handles"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } + + + Inkscape::Selection *selection = sp_desktop_selection (desktop); + SPDocument *document = sp_desktop_document (desktop); + + g_object_set_data(holder, "desktop", desktop); + + // connect to selection modified and changed signals + sigc::connection *conn1 = new sigc::connection( + selection->connectChanged(sigc::bind(sigc::ptr_fun(&ms_tb_selection_changed), (gpointer) holder))); + sigc::connection *conn2 = new sigc::connection( + selection->connectModified(sigc::bind(sigc::ptr_fun(&ms_tb_selection_modified), (gpointer) holder))); + sigc::connection *conn3 = new sigc::connection( + desktop->connectToolSubselectionChanged( sigc::bind(sigc::ptr_fun(&ms_drag_selection_changed), (gpointer) holder))); + + // when holder is destroyed, disconnect + g_signal_connect(G_OBJECT(holder), "destroy", G_CALLBACK(ms_disconnect_sigc), conn1); + g_signal_connect(G_OBJECT(holder), "destroy", G_CALLBACK(ms_disconnect_sigc), conn2); + g_signal_connect(G_OBJECT(holder), "destroy", G_CALLBACK(ms_disconnect_sigc), conn3); + + // connect to release and modified signals of the defs (i.e. when someone changes mesh) + sigc::connection *release_connection = new sigc::connection(); + *release_connection = document->getDefs()->connectRelease(sigc::bind<1>(sigc::ptr_fun(&ms_defs_release), GTK_WIDGET(holder))); + sigc::connection *modified_connection = new sigc::connection(); + *modified_connection = document->getDefs()->connectModified(sigc::bind<2>(sigc::ptr_fun(&ms_defs_modified), GTK_WIDGET(holder))); + + // when holder is destroyed, disconnect + g_signal_connect(G_OBJECT(holder), "destroy", G_CALLBACK(ms_disconnect_sigc), release_connection); + g_signal_connect(G_OBJECT(holder), "destroy", G_CALLBACK(ms_disconnect_sigc), modified_connection); + +} + +/* + 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 : diff --git a/src/widgets/mesh-toolbar.h b/src/widgets/mesh-toolbar.h new file mode 100644 index 000000000..277525804 --- /dev/null +++ b/src/widgets/mesh-toolbar.h @@ -0,0 +1,22 @@ +#ifndef SEEN_MESH_TOOLBAR_H +#define SEEN_MESH_TOOLBAR_H + +/* + * Mesh aux toolbar + * + * Authors: + * bulia byak <bulia@dr.com> + * Tavmjong Bah <tavmjong@free.fr> + * + * Copyright (C) 2012 authors + * Copyright (C) 2005 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <gtk/gtk.h> +struct SPDesktop; + +void sp_mesh_toolbox_prep( SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder); + +#endif /* !SEEN_MESH_TOOLBAR_H */ diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 78d0683f3..f8aed71a8 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -76,6 +76,7 @@ #include "erasor-toolbar.h" #include "gradient-toolbar.h" #include "lpe-toolbar.h" +#include "mesh-toolbar.h" #include "measure-toolbar.h" #include "node-toolbar.h" #include "rect-toolbar.h" @@ -157,6 +158,7 @@ static struct { { "SPTextContext", "text_tool", SP_VERB_CONTEXT_TEXT, SP_VERB_CONTEXT_TEXT_PREFS }, { "SPConnectorContext","connector_tool", SP_VERB_CONTEXT_CONNECTOR, SP_VERB_CONTEXT_CONNECTOR_PREFS }, { "SPGradientContext", "gradient_tool", SP_VERB_CONTEXT_GRADIENT, SP_VERB_CONTEXT_GRADIENT_PREFS }, + { "SPMeshContext", "mesh_tool", SP_VERB_CONTEXT_MESH, SP_VERB_CONTEXT_MESH_PREFS }, { "SPDropperContext", "dropper_tool", SP_VERB_CONTEXT_DROPPER, SP_VERB_CONTEXT_DROPPER_PREFS }, { NULL, NULL, 0, 0 } }; @@ -209,8 +211,10 @@ static struct { SP_VERB_INVALID, 0, 0}, { "SPConnectorContext", "connector_toolbox", 0, sp_connector_toolbox_prep, "ConnectorToolbar", SP_VERB_INVALID, 0, 0}, - { "SPGradientContext", "gradient_toolbox", 0, sp_gradient_toolbox_prep, "GradientToolbar", - SP_VERB_INVALID, 0, 0}, + { "SPGradientContext", "gradient_toolbox", 0, sp_gradient_toolbox_prep, "GradientToolbar", + SP_VERB_INVALID, 0, 0}, + { "SPMeshContext", "mesh_toolbox", 0, sp_mesh_toolbox_prep, "MeshToolbar", + SP_VERB_INVALID, 0, 0}, { "SPFloodContext", "paintbucket_toolbox", 0, sp_paintbucket_toolbox_prep, "PaintbucketToolbar", SP_VERB_CONTEXT_PAINTBUCKET_PREFS, "/tools/paintbucket", N_("Style of Paint Bucket fill objects")}, { NULL, NULL, NULL, NULL, NULL, SP_VERB_INVALID, NULL, NULL } @@ -506,6 +510,18 @@ static gchar const * ui_descr = " <toolitem action='GradientEditDeleteAction' />" " </toolbar>" + " <toolbar name='MeshToolbar'>" + " <toolitem action='MeshNewTypeAction' />" + " <toolitem action='MeshNewFillStrokeAction' />" + " <toolitem action='MeshRowAction' />" + " <toolitem action='MeshColumnAction' />" + " <separator />" +// " <toolitem action='MeshEditFillAction' />" +// " <toolitem action='MeshEditStrokeAction' />" +// " <toolitem action='MeshShowHandlesAction' />" + " <separator />" + " </toolbar>" + " <toolbar name='DropperToolbar'>" " <toolitem action='DropperOpacityAction' />" " <toolitem action='DropperPickAlphaAction' />" @@ -1330,6 +1346,9 @@ void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) " <!-- Fill -->" " <toolitem action='ToolPaintBucket' />" " <toolitem action='ToolGradient' />" +#ifdef WITH_MESH + " <toolitem action='ToolMesh' />" +#endif " <toolitem action='ToolDropper' />" " <toolitem action='ToolConnector' />" |
