static void sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item, Geom::Point mouse_p, guint32 /*etime*/) { // item is the selected item. mouse_p the location in doc coordinates of where to add the stop SPEventContext *ec = SP_EVENT_CONTEXT(rc); SPDesktop *desktop = SP_EVENT_CONTEXT (rc)->desktop; double tolerance = (double) ec->tolerance; ec->get_drag()->addStopNearPoint (item, mouse_p, tolerance/desktop->current_zoom()); sp_document_done (sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop")); ec->get_drag()->updateDraggers(); }
/** Split row/column near the mouse point. */ static void sp_mesh_context_split_near_point(SPMeshContext *rc, SPItem *item, Geom::Point mouse_p, guint32 /*etime*/) { #ifdef DEBUG_MESH std::cout << "sp_mesh_context_split_near_point: entrance: " << mouse_p << std::endl; #endif // item is the selected item. mouse_p the location in doc coordinates of where to add the stop SPEventContext *ec = SP_EVENT_CONTEXT(rc); SPDesktop *desktop = SP_EVENT_CONTEXT (rc)->desktop; double tolerance = (double) ec->tolerance; ec->get_drag()->addStopNearPoint (item, mouse_p, tolerance/desktop->current_zoom()); DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_MESH, _("Split mesh row/column")); ec->get_drag()->updateDraggers(); }
void gr_item_activate (GtkMenuItem *menuitem, gpointer data) { SPGradient *gr = (SPGradient *) g_object_get_data (G_OBJECT (menuitem), "gradient"); gr = sp_gradient_ensure_vector_normalized(gr); SPDesktop *desktop = (SPDesktop *) data; Inkscape::Selection *selection = sp_desktop_selection (desktop); SPEventContext *ev = sp_desktop_event_context (desktop); gr_apply_gradient (selection, ev? ev->get_drag() : NULL, gr); sp_document_done (sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT, _("Assign gradient to object")); }
static void gr_tb_selection_changed (Inkscape::Selection *, gpointer data) { GtkWidget *widget = (GtkWidget *) data; SPDesktop *desktop = (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) return; SPEventContext *ev = sp_desktop_event_context (desktop); GtkWidget *om = (GtkWidget *) g_object_get_data (G_OBJECT (widget), "menu"); if (om) gtk_widget_destroy (om); SPGradient *gr_selected = NULL; bool gr_multi = false; SPGradientSpread spr_selected = (SPGradientSpread) INT_MAX; // meaning undefined bool spr_multi = false; gr_read_selection (selection, ev? ev->get_drag() : NULL, &gr_selected, &gr_multi, &spr_selected, &spr_multi); om = gr_vector_list (desktop, selection->isEmpty(), gr_selected, gr_multi); g_object_set_data (G_OBJECT (widget), "menu", om); GtkWidget *buttons = (GtkWidget *) g_object_get_data (G_OBJECT(widget), "buttons"); gtk_widget_set_sensitive (buttons, (gr_selected && !gr_multi)); gtk_box_pack_start (GTK_BOX (widget), om, TRUE, TRUE, 0); gtk_widget_show_all (widget); }
GtkWidget * gr_change_widget (SPDesktop *desktop) { Inkscape::Selection *selection = sp_desktop_selection (desktop); SPDocument *document = sp_desktop_document (desktop); SPEventContext *ev = sp_desktop_event_context (desktop); SPGradient *gr_selected = NULL; bool gr_multi = false; SPGradientSpread spr_selected = (SPGradientSpread) INT_MAX; // meaning undefined bool spr_multi = false; GtkTooltips *tt = gtk_tooltips_new(); gr_read_selection (selection, ev? ev->get_drag() : NULL, &gr_selected, &gr_multi, &spr_selected, &spr_multi); GtkWidget *widget = gtk_hbox_new(FALSE, FALSE); gtk_object_set_data(GTK_OBJECT(widget), "dtw", desktop->canvas); g_object_set_data (G_OBJECT (widget), "desktop", desktop); GtkWidget *om = gr_vector_list (desktop, selection->isEmpty(), gr_selected, gr_multi); g_object_set_data (G_OBJECT (widget), "menu", om); gtk_box_pack_start (GTK_BOX (widget), om, TRUE, TRUE, 0); { GtkWidget *buttons = gtk_hbox_new(FALSE, 1); /* Edit... */ { GtkWidget *hb = gtk_hbox_new(FALSE, 1); GtkWidget *b = gtk_button_new_with_label(_("Edit...")); gtk_tooltips_set_tip(tt, b, _("Edit the stops of the gradient"), NULL); gtk_widget_show(b); gtk_container_add(GTK_CONTAINER(hb), b); gtk_signal_connect(GTK_OBJECT(b), "clicked", GTK_SIGNAL_FUNC(gr_edit), widget); gtk_box_pack_start (GTK_BOX(buttons), hb, FALSE, FALSE, 0); } gtk_box_pack_end (GTK_BOX(widget), buttons, FALSE, FALSE, 0); g_object_set_data (G_OBJECT(widget), "buttons", buttons); gtk_widget_set_sensitive (buttons, (gr_selected && !gr_multi)); } // connect to selection modified and changed signals sigc::connection *conn1 = new sigc::connection (selection->connectChanged( sigc::bind ( sigc::ptr_fun(&gr_tb_selection_changed), (gpointer)widget ) )); sigc::connection *conn2 = new sigc::connection (selection->connectModified( sigc::bind ( sigc::ptr_fun(&gr_tb_selection_modified), (gpointer)widget ) )); sigc::connection *conn3 = new sigc::connection (desktop->connectToolSubselectionChanged( sigc::bind ( sigc::ptr_fun(&gr_drag_selection_changed), (gpointer)widget ) )); // when widget is destroyed, disconnect g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(gr_disconnect_sigc), conn1); g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(gr_disconnect_sigc), conn2); g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(gr_disconnect_sigc), conn3); // connect to release and modified signals of the defs (i.e. when someone changes gradient) sigc::connection *release_connection = new sigc::connection(); *release_connection = SP_DOCUMENT_DEFS(document)->connectRelease(sigc::bind<1>(sigc::ptr_fun(&gr_defs_release), widget)); sigc::connection *modified_connection = new sigc::connection(); *modified_connection = SP_DOCUMENT_DEFS(document)->connectModified(sigc::bind<2>(sigc::ptr_fun(&gr_defs_modified), widget)); // when widget is destroyed, disconnect g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(gr_disconnect_sigc), release_connection); g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(gr_disconnect_sigc), modified_connection); gtk_widget_show_all (widget); return widget; }