本文整理汇总了C++中inkscape::Selection::itemList方法的典型用法代码示例。如果您正苦于以下问题:C++ Selection::itemList方法的具体用法?C++ Selection::itemList怎么用?C++ Selection::itemList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inkscape::Selection
的用法示例。
在下文中一共展示了Selection::itemList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
sp_selected_path_reverse(SPDesktop *desktop)
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
GSList *items = (GSList *) selection->itemList();
if (!items) {
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse."));
return;
}
// set "busy" cursor
desktop->setWaitingCursor();
bool did = false;
desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths..."));
for (GSList *i = items; i != NULL; i = i->next) {
if (!SP_IS_PATH(i->data)) {
continue;
}
did = true;
SPPath *path = SP_PATH(i->data);
SPCurve *rcurve = path->get_curve_reference()->create_reverse();
gchar *str = sp_svg_write_path(rcurve->get_pathvector());
if ( path->hasPathEffectRecursive() ) {
path->getRepr()->setAttribute("inkscape:original-d", str);
} else {
path->getRepr()->setAttribute("d", str);
}
g_free(str);
rcurve->unref();
// reverse nodetypes order (Bug #179866)
gchar *nodetypes = g_strdup(path->getRepr()->attribute("sodipodi:nodetypes"));
if ( nodetypes ) {
path->getRepr()->setAttribute("sodipodi:nodetypes", g_strreverse(nodetypes));
g_free(nodetypes);
}
}
desktop->clearWaitingCursor();
if (did) {
DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_REVERSE,
_("Reverse path"));
} else {
sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection."));
}
}
示例2:
void
sp_selected_path_reverse(SPDesktop *desktop)
{
Inkscape::Selection *selection = desktop->getSelection();
std::vector<SPItem*> items = selection->itemList();
if (items.empty()) {
desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse."));
return;
}
// set "busy" cursor
desktop->setWaitingCursor();
bool did = false;
desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths..."));
for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i){
SPPath *path = dynamic_cast<SPPath *>(*i);
if (!path) {
continue;
}
did = true;
SPCurve *rcurve = path->get_curve_reference()->create_reverse();
gchar *str = sp_svg_write_path(rcurve->get_pathvector());
if ( path->hasPathEffectRecursive() ) {
path->getRepr()->setAttribute("inkscape:original-d", str);
} else {
path->getRepr()->setAttribute("d", str);
}
g_free(str);
rcurve->unref();
// reverse nodetypes order (Bug #179866)
gchar *nodetypes = g_strdup(path->getRepr()->attribute("sodipodi:nodetypes"));
if ( nodetypes ) {
path->getRepr()->setAttribute("sodipodi:nodetypes", g_strreverse(nodetypes));
g_free(nodetypes);
}
}
desktop->clearWaitingCursor();
if (did) {
DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_REVERSE,
_("Reverse path"));
} else {
desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection."));
}
}
示例3: stop
static void
gradient_selection_changed (Inkscape::Selection *, gpointer data)
{
SPGradientContext *rc = (SPGradientContext *) data;
GrDrag *drag = rc->_grdrag;
Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(rc)->desktop);
guint n_obj = g_slist_length((GSList *) selection->itemList());
if (!drag->isNonEmpty() || selection->isEmpty())
return;
guint n_tot = drag->numDraggers();
guint n_sel = drag->numSelected();
//The use of ngettext in the following code is intentional even if the English singular form would never be used
if (n_sel == 1) {
if (drag->singleSelectedDraggerNumDraggables() == 1) {
gchar * message = g_strconcat(
//TRANSLATORS: %s will be substituted with the point name (see previous messages); This is part of a compound message
_("%s selected"),
//TRANSLATORS: Mind the space in front. This is part of a compound message
ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
message,_(gr_handle_descr[drag->singleSelectedDraggerSingleDraggableType()]), n_tot, n_obj);
} else {
gchar * message = g_strconcat(
//TRANSLATORS: This is a part of a compound message (out of two more indicating: grandint handle count & object count)
ngettext("One handle merging %d stop (drag with <b>Shift</b> to separate) selected",
"One handle merging %d stops (drag with <b>Shift</b> to separate) selected",drag->singleSelectedDraggerNumDraggables()),
ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj);
}
} else if (n_sel > 1) {
//TRANSLATORS: The plural refers to number of selected gradient handles. This is part of a compound message (part two indicates selected object count)
gchar * message = g_strconcat(ngettext("<b>%d</b> gradient handle selected out of %d","<b>%d</b> gradient handles selected out of %d",n_sel),
//TRANSLATORS: Mind the space in front. (Refers to gradient handles selected). This is part of a compound message
ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message, n_sel, n_tot, n_obj);
} else if (n_sel == 0) {
rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
//TRANSLATORS: The plural refers to number of selected objects
ngettext("<b>No</b> gradient handles selected out of %d on %d selected object",
"<b>No</b> gradient handles selected out of %d on %d selected objects",n_obj), n_tot, n_obj);
}
}
示例4: sp_rtb_value_changed
static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name,
void (SPRect::*setter)(gdouble))
{
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
Unit const *unit = tracker->getActiveUnit();
g_return_if_fail(unit != NULL);
if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name,
Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"));
}
// quit if run by the attr_changed listener
if (g_object_get_data( tbl, "freeze" ) || tracker->isUpdating()) {
return;
}
// in turn, prevent listener from responding
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE));
bool modmade = false;
Inkscape::Selection *selection = desktop->getSelection();
std::vector<SPItem*> itemlist=selection->itemList();
for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){
if (SP_IS_RECT(*i)) {
if (gtk_adjustment_get_value(adj) != 0) {
(SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"));
} else {
(*i)->getRepr()->setAttribute(value_name, NULL);
}
modmade = true;
}
}
sp_rtb_sensitivize( tbl );
if (modmade) {
DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_RECT,
_("Change rectangle"));
}
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
示例5: sp_spray_dilate
static bool sp_spray_dilate(SPSprayContext *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse)
{
Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(tc)->desktop);
SPDesktop *desktop = SP_EVENT_CONTEXT(tc)->desktop;
if (selection->isEmpty()) {
return false;
}
bool did = false;
double radius = get_dilate_radius(tc);
double path_force = get_path_force(tc);
if (radius == 0 || path_force == 0) {
return false;
}
double path_mean = get_path_mean(tc);
if (radius == 0 || path_mean == 0) {
return false;
}
double path_standard_deviation = get_path_standard_deviation(tc);
if (radius == 0 || path_standard_deviation == 0) {
return false;
}
double move_force = get_move_force(tc);
double move_mean = get_move_mean(tc);
double move_standard_deviation = get_move_standard_deviation(tc);
for (GSList *items = g_slist_copy((GSList *) selection->itemList());
items != NULL;
items = items->next) {
SPItem *item = (SPItem *) items->data;
if (is_transform_modes(tc->mode)) {
if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, move_force, tc->population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib))
did = true;
} else {
if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, path_force, tc->population, tc->scale, tc->scale_variation, reverse, path_mean, path_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib))
did = true;
}
}
return did;
}
示例6: sp_selected_to_lpeitems
/** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */
void sp_selected_to_lpeitems(SPDesktop *desktop)
{
Inkscape::Selection *selection = desktop->getSelection();
if (selection->isEmpty()) {
return;
}
std::vector<SPItem*> selected(selection->itemList());
std::vector<Inkscape::XML::Node*> to_select;
selection->clear();
std::vector<SPItem*> items(selected);
sp_item_list_to_curves(items, selected, to_select, true);
selection->setReprList(to_select);
selection->addList(selected);
}
示例7:
/* This function is an entry point from GUI */
void
sp_selected_path_to_curves(SPDesktop *desktop, bool interactive)
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
if (interactive)
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to path."));
return;
}
bool did = false;
if (interactive) {
desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Converting objects to paths..."));
// set "busy" cursor
desktop->setWaitingCursor();
}
GSList *selected = g_slist_copy((GSList *) selection->itemList());
GSList *to_select = NULL;
selection->clear();
GSList *items = g_slist_copy(selected);
did = sp_item_list_to_curves(items, &selected, &to_select);
g_slist_free (items);
selection->setReprList(to_select);
selection->addList(selected);
g_slist_free (to_select);
g_slist_free (selected);
if (interactive) {
desktop->clearWaitingCursor();
if (did) {
sp_document_done(sp_desktop_document(desktop), SP_VERB_OBJECT_TO_CURVE,
_("Object to path"));
} else {
sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects</b> to convert to path in the selection."));
return;
}
}
}
示例8: setupIgnoreSelection
/// Setup, taking the list of items to ignore from the desktop's selection.
void SnapManager::setupIgnoreSelection(SPDesktop const *desktop,
bool snapindicator,
std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes,
SPGuide *guide_to_ignore)
{
g_assert(desktop != NULL);
if (_desktop != NULL) {
// Someone has been naughty here! This is dangerous
g_warning("The snapmanager has been set up before, but unSetup() hasn't been called afterwards. It possibly held invalid pointers");
}
_desktop = desktop;
_snapindicator = snapindicator;
_unselected_nodes = unselected_nodes;
_guide_to_ignore = guide_to_ignore;
_rotation_center_source_items.clear();
_items_to_ignore.clear();
Inkscape::Selection *sel = _desktop->selection;
std::vector<SPItem*> const items = sel->itemList();
for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i) {
_items_to_ignore.push_back(*i);
}
}
示例9: sp_selected_to_lpeitems
/** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */
void sp_selected_to_lpeitems(SPDesktop *desktop)
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
return;
}
bool did = false;
GSList *selected = g_slist_copy((GSList *) selection->itemList());
GSList *to_select = NULL;
selection->clear();
GSList *items = g_slist_copy(selected);
did = sp_item_list_to_curves(items, &selected, &to_select, true);
g_slist_free (items);
selection->setReprList(to_select);
selection->addList(selected);
g_slist_free (to_select);
g_slist_free (selected);
}
示例10: items
void
sp_selected_path_combine(SPDesktop *desktop)
{
Inkscape::Selection *selection = desktop->getSelection();
SPDocument *doc = desktop->getDocument();
std::vector<SPItem*> items(selection->itemList());
if (items.size() < 1) {
desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine."));
return;
}
desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Combining paths..."));
// set "busy" cursor
desktop->setWaitingCursor();
items = sp_degroup_list (items); // descend into any groups in selection
std::vector<SPItem*> to_paths;
for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i) {
if (!dynamic_cast<SPPath *>(*i) && !dynamic_cast<SPGroup *>(*i)) {
to_paths.push_back(*i);
}
}
std::vector<Inkscape::XML::Node*> converted;
bool did = sp_item_list_to_curves(to_paths, items, converted);
for (std::vector<Inkscape::XML::Node*>::const_iterator i = converted.begin(); i != converted.end(); ++i)
items.push_back((SPItem*)doc->getObjectByRepr(*i));
items = sp_degroup_list (items); // converting to path may have added more groups, descend again
sort(items.begin(),items.end(),less_than_items);
assert(!items.empty()); // cannot be NULL because of list length check at top of function
// remember the position, id, transform and style of the topmost path, they will be assigned to the combined one
gint position = 0;
char const *id = NULL;
char const *transform = NULL;
char const *style = NULL;
char const *path_effect = NULL;
SPCurve* curve = NULL;
SPItem *first = NULL;
Inkscape::XML::Node *parent = NULL;
if (did) {
selection->clear();
}
for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i){
SPItem *item = *i;
SPPath *path = dynamic_cast<SPPath *>(item);
if (!path) {
continue;
}
if (!did) {
selection->clear();
did = true;
}
SPCurve *c = path->get_curve_for_edit();
if (first == NULL) { // this is the topmost path
first = item;
parent = first->getRepr()->parent();
position = first->getRepr()->position();
id = first->getRepr()->attribute("id");
transform = first->getRepr()->attribute("transform");
// FIXME: merge styles of combined objects instead of using the first one's style
style = first->getRepr()->attribute("style");
path_effect = first->getRepr()->attribute("inkscape:path-effect");
//c->transform(item->transform);
curve = c;
} else {
c->transform(item->getRelativeTransform(first));
curve->append(c, false);
c->unref();
// reduce position only if the same parent
if (item->getRepr()->parent() == parent) {
position--;
}
// delete the object for real, so that its clones can take appropriate action
item->deleteObject();
}
}
if (did) {
first->deleteObject(false);
// delete the topmost.
Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
// restore id, transform, path effect, and style
repr->setAttribute("id", id);
if (transform) {
//.........这里部分代码省略.........
示例11: button_w
/**
Handles all keyboard and mouse input for meshs.
*/
static gint
sp_mesh_context_root_handler(SPEventContext *event_context, GdkEvent *event)
{
// static int count = 0;
// std::cout << "sp_mesh_context_root_handler: " << count++ << std::endl;
static bool dragging;
SPDesktop *desktop = event_context->desktop;
Inkscape::Selection *selection = sp_desktop_selection (desktop);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
SPMeshContext *rc = SP_MESH_CONTEXT(event_context);
event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
GrDrag *drag = event_context->_grdrag;
g_assert (drag);
gint ret = FALSE;
switch (event->type) {
case GDK_2BUTTON_PRESS:
#ifdef DEBUG_MESH
std::cout << "sp_mesh_context_root_handler: GDK_2BUTTON_PRESS" << std::endl;
#endif
// Double click:
// If over a mesh line, divide mesh row/column
// If not over a line, create new gradients for selected objects.
if ( event->button.button == 1 ) {
// Are we over a mesh line?
bool over_line = false;
SPCtrlCurve *line = NULL;
if (drag->lines) {
for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) {
line = (SPCtrlCurve*) l->data;
over_line |= sp_mesh_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
}
}
if (over_line) {
// We take the first item in selection, because with doubleclick, the first click
// always resets selection to the single object under cursor
sp_mesh_context_split_near_point(rc, SP_ITEM(selection->itemList()->data), rc->mousepoint_doc, event->button.time);
} else {
// Create a new gradient with default coordinates.
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
SPItem *item = SP_ITEM(i->data);
SPGradientType new_type = SP_GRADIENT_TYPE_MESH;
Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
#ifdef DEBUG_MESH
std::cout << "sp_mesh_context_root_handler: creating new mesh on: " << (fsmode == Inkscape::FOR_FILL ? "Fill" : "Stroke") << std::endl;
#endif
SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, item, fsmode);
SPGradient *priv = sp_item_set_gradient(item, vector, new_type, fsmode);
sp_gradient_reset_to_userspace(priv, item);
}
DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_MESH,
_("Create default mesh"));
}
ret = TRUE;
}
break;
case GDK_BUTTON_PRESS:
#ifdef DEBUG_MESH
std::cout << "sp_mesh_context_root_handler: GDK_BUTTON_PRESS" << std::endl;
#endif
// Button down
// If Shift key down: do rubber band selection
// Else set origin for drag. A drag creates a new gradient if one does not exist
if ( event->button.button == 1 && !event_context->space_panning ) {
Geom::Point button_w(event->button.x, event->button.y);
// save drag origin
event_context->xp = (gint) button_w[Geom::X];
event_context->yp = (gint) button_w[Geom::Y];
event_context->within_tolerance = true;
dragging = true;
Geom::Point button_dt = desktop->w2d(button_w);
if (event->button.state & GDK_SHIFT_MASK) {
Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
} else {
//.........这里部分代码省略.........
示例12: SPCurve
void
sp_selected_path_break_apart(SPDesktop *desktop)
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to break apart."));
return;
}
desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Breaking apart paths..."));
// set "busy" cursor
desktop->setWaitingCursor();
bool did = false;
for (GSList *items = g_slist_copy((GSList *) selection->itemList());
items != NULL;
items = items->next) {
SPItem *item = (SPItem *) items->data;
if (!SP_IS_PATH(item)) {
continue;
}
SPPath *path = SP_PATH(item);
SPCurve *curve = path->get_curve_for_edit();
if (curve == NULL) {
continue;
}
did = true;
Inkscape::XML::Node *parent = item->getRepr()->parent();
gint pos = item->getRepr()->position();
char const *id = item->getRepr()->attribute("id");
// XML Tree being used directly here while it shouldn't be...
gchar *style = g_strdup(item->getRepr()->attribute("style"));
// XML Tree being used directly here while it shouldn't be...
gchar *path_effect = g_strdup(item->getRepr()->attribute("inkscape:path-effect"));
Geom::PathVector apv = curve->get_pathvector() * path->transform;
curve->unref();
// it's going to resurrect as one of the pieces, so we delete without advertisement
item->deleteObject(false);
curve = new SPCurve(apv);
g_assert(curve != NULL);
GSList *list = curve->split();
curve->unref();
GSList *reprs = NULL;
for (GSList *l = list; l != NULL; l = l->next) {
curve = (SPCurve *) l->data;
Inkscape::XML::Node *repr = parent->document()->createElement("svg:path");
repr->setAttribute("style", style);
repr->setAttribute("inkscape:path-effect", path_effect);
gchar *str = sp_svg_write_path(curve->get_pathvector());
if (path_effect)
repr->setAttribute("inkscape:original-d", str);
else
repr->setAttribute("d", str);
g_free(str);
// add the new repr to the parent
parent->appendChild(repr);
// move to the saved position
repr->setPosition(pos > 0 ? pos : 0);
// if it's the first one, restore id
if (l == list)
repr->setAttribute("id", id);
reprs = g_slist_prepend (reprs, repr);
Inkscape::GC::release(repr);
}
selection->setReprList(reprs);
g_slist_free(reprs);
g_slist_free(list);
g_free(style);
g_free(path_effect);
}
desktop->clearWaitingCursor();
if (did) {
//.........这里部分代码省略.........
示例13: sp_gradient_drag
static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint /*state*/, guint32 etime)
{
SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop;
Inkscape::Selection *selection = sp_desktop_selection(desktop);
SPDocument *document = sp_desktop_document(desktop);
SPEventContext *ec = SP_EVENT_CONTEXT(&rc);
if (!selection->isEmpty()) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int type = prefs->getInt("/tools/gradient/newgradient", 1);
int fill_or_stroke = prefs->getInt("/tools/gradient/newfillorstroke", 1);
SPGradient *vector;
if (ec->item_to_select) {
// pick color from the object where drag started
vector = sp_gradient_vector_for_object(document, desktop, ec->item_to_select, fill_or_stroke);
} else {
// Starting from empty space:
// Sort items so that the topmost comes last
GSList *items = g_slist_copy ((GSList *) selection->itemList());
items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position);
// take topmost
vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(g_slist_last(items)->data), fill_or_stroke);
g_slist_free (items);
}
// HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs
SPCSSAttr *css = sp_repr_css_attr_new();
sp_repr_css_set_property(css, "fill-opacity", "1.0");
for (GSList const *i = selection->itemList(); i != NULL; i = i->next) {
//FIXME: see above
sp_repr_css_change_recursive(SP_OBJECT_REPR(i->data), css, "style");
sp_item_set_gradient(SP_ITEM(i->data), vector, (SPGradientType) type, fill_or_stroke);
if (type == SP_GRADIENT_TYPE_LINEAR) {
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false);
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_END, 0, pt, fill_or_stroke, true, false);
} else if (type == SP_GRADIENT_TYPE_RADIAL) {
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false);
sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_R1, 0, pt, fill_or_stroke, true, false);
}
SP_OBJECT (i->data)->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
if (ec->_grdrag) {
ec->_grdrag->updateDraggers();
// prevent regenerating draggers by selection modified signal, which sometimes
// comes too late and thus destroys the knot which we will now grab:
ec->_grdrag->local_change = true;
// give the grab out-of-bounds values of xp/yp because we're already dragging
// and therefore are already out of tolerance
ec->_grdrag->grabKnot (SP_ITEM(selection->itemList()->data),
type == SP_GRADIENT_TYPE_LINEAR? POINT_LG_END : POINT_RG_R1,
-1, // ignore number (though it is always 1)
fill_or_stroke, 99999, 99999, etime);
}
// We did an undoable action, but sp_document_done will be called by the knot when released
// status text; we do not track coords because this branch is run once, not all the time
// during drag
int n_objects = g_slist_length((GSList *) selection->itemList());
rc._message_context->setF(Inkscape::NORMAL_MESSAGE,
ngettext("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle",
"<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects),
n_objects);
} else {
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient."));
}
}
示例14: button_w
static gint
sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
{
static bool dragging;
SPDesktop *desktop = event_context->desktop;
Inkscape::Selection *selection = sp_desktop_selection (desktop);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
SPGradientContext *rc = SP_GRADIENT_CONTEXT(event_context);
event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
GrDrag *drag = event_context->_grdrag;
g_assert (drag);
gint ret = FALSE;
switch (event->type) {
case GDK_2BUTTON_PRESS:
if ( event->button.button == 1 ) {
bool over_line = false;
SPCtrlLine *line = NULL;
if (drag->lines) {
for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) {
line = (SPCtrlLine*) l->data;
over_line |= sp_gradient_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
}
}
if (over_line) {
// we take the first item in selection, because with doubleclick, the first click
// always resets selection to the single object under cursor
sp_gradient_context_add_stop_near_point(rc, SP_ITEM(selection->itemList()->data), rc->mousepoint_doc, event->button.time);
} else {
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
SPItem *item = SP_ITEM(i->data);
SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR);
guint new_fill = prefs->getInt("/tools/gradient/newfillorstroke", 1);
SPGradient *vector = sp_gradient_vector_for_object(sp_desktop_document(desktop), desktop, SP_OBJECT (item), new_fill);
SPGradient *priv = sp_item_set_gradient(item, vector, new_type, new_fill);
sp_gradient_reset_to_userspace(priv, item);
}
sp_document_done (sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT,
_("Create default gradient"));
}
ret = TRUE;
}
break;
case GDK_BUTTON_PRESS:
if ( event->button.button == 1 && !event_context->space_panning ) {
Geom::Point button_w(event->button.x, event->button.y);
// save drag origin
event_context->xp = (gint) button_w[Geom::X];
event_context->yp = (gint) button_w[Geom::Y];
event_context->within_tolerance = true;
dragging = true;
Geom::Point button_dt = to_2geom(desktop->w2d(button_w));
if (event->button.state & GDK_SHIFT_MASK) {
Inkscape::Rubberband::get(desktop)->start(desktop, from_2geom(button_dt));
} else {
// remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to
// enable Ctrl+doubleclick of exactly the selected item(s)
if (!(event->button.state & GDK_CONTROL_MASK))
event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
/* Snap center to nearest magnetic point */
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, button_dt);
rc->origin = from_2geom(button_dt);
}
ret = TRUE;
}
break;
case GDK_MOTION_NOTIFY:
if ( dragging
&& ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning )
{
if ( event_context->within_tolerance
&& ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
&& ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
break; // do not drag if we're within tolerance from origin
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to draw, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
event_context->within_tolerance = false;
Geom::Point const motion_w(event->motion.x,
event->motion.y);
Geom::Point const motion_dt = event_context->desktop->w2d(motion_w);
if (Inkscape::Rubberband::get(desktop)->is_started()) {
//.........这里部分代码省略.........
示例15: itemlist
void
sp_selected_path_break_apart(SPDesktop *desktop, bool skip_undo)
{
Inkscape::Selection *selection = desktop->getSelection();
if (selection->isEmpty()) {
desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to break apart."));
return;
}
desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Breaking apart paths..."));
// set "busy" cursor
desktop->setWaitingCursor();
bool did = false;
std::vector<SPItem*> itemlist(selection->itemList());
for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); ++i){
SPItem *item = *i;
SPPath *path = dynamic_cast<SPPath *>(item);
if (!path) {
continue;
}
SPCurve *curve = path->get_curve_for_edit();
if (curve == NULL) {
continue;
}
did = true;
Inkscape::XML::Node *parent = item->getRepr()->parent();
gint pos = item->getRepr()->position();
char const *id = item->getRepr()->attribute("id");
// XML Tree being used directly here while it shouldn't be...
gchar *style = g_strdup(item->getRepr()->attribute("style"));
// XML Tree being used directly here while it shouldn't be...
gchar *path_effect = g_strdup(item->getRepr()->attribute("inkscape:path-effect"));
Geom::Affine transform = path->transform;
// it's going to resurrect as one of the pieces, so we delete without advertisement
item->deleteObject(false);
GSList *list = curve->split();
curve->unref();
std::vector<Inkscape::XML::Node*> reprs;
for (GSList *l = list; l != NULL; l = l->next) {
curve = (SPCurve *) l->data;
Inkscape::XML::Node *repr = parent->document()->createElement("svg:path");
repr->setAttribute("style", style);
repr->setAttribute("inkscape:path-effect", path_effect);
gchar *str = sp_svg_write_path(curve->get_pathvector());
if (path_effect)
repr->setAttribute("inkscape:original-d", str);
else
repr->setAttribute("d", str);
g_free(str);
repr->setAttribute("transform", sp_svg_transform_write(transform));
// add the new repr to the parent
parent->appendChild(repr);
// move to the saved position
repr->setPosition(pos > 0 ? pos : 0);
// if it's the first one, restore id
if (l == list)
repr->setAttribute("id", id);
reprs.push_back(repr);
Inkscape::GC::release(repr);
}
selection->setReprList(reprs);
g_slist_free(list);
g_free(style);
g_free(path_effect);
}
desktop->clearWaitingCursor();
if (did) {
if ( !skip_undo ) {
DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_BREAK_APART,
_("Break apart"));
}
} else {
desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to break apart in the selection."));
}
}