本文整理汇总了C++中inkscape::Selection::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Selection::set方法的具体用法?C++ Selection::set怎么用?C++ Selection::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inkscape::Selection
的用法示例。
在下文中一共展示了Selection::set方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
OriginalPathParam::on_select_original_button_click()
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
SPItem *original = ref.getObject();
if (desktop == NULL || original == NULL) {
return;
}
Inkscape::Selection *selection = sp_desktop_selection(desktop);
selection->clear();
selection->set(original);
}
示例2: sp_selection_move_screen
static gint
sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
{
SPItem *item = NULL;
SPItem *item_at_point = NULL, *group_at_point = NULL, *item_in_group = NULL;
gint ret = FALSE;
SPDesktop *desktop = event_context->desktop;
SPSelectContext *sc = SP_SELECT_CONTEXT(event_context);
Inkscape::SelTrans *seltrans = sc->_seltrans;
Inkscape::Selection *selection = sp_desktop_selection(desktop);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// make sure we still have valid objects to move around
if (sc->item && SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))==NULL) {
sp_select_context_abort(event_context);
}
switch (event->type) {
case GDK_2BUTTON_PRESS:
if (event->button.button == 1) {
if (!selection->isEmpty()) {
SPItem *clicked_item = (SPItem *) selection->itemList()->data;
if (SP_IS_GROUP(clicked_item) && !SP_IS_BOX3D(clicked_item)) { // enter group if it's not a 3D box
desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item));
sp_desktop_selection(desktop)->clear();
sc->dragging = false;
sp_event_context_discard_delayed_snap_event(event_context);
desktop->canvas->end_forced_full_redraws();
} else { // switch tool
Geom::Point const button_pt(event->button.x, event->button.y);
Geom::Point const p(desktop->w2d(button_pt));
tools_switch_by_item (desktop, clicked_item, p);
}
} else {
sp_select_context_up_one_layer(desktop);
}
ret = TRUE;
}
break;
case GDK_BUTTON_PRESS:
if (event->button.button == 1 && !event_context->space_panning) {
// save drag origin
xp = (gint) event->button.x;
yp = (gint) event->button.y;
within_tolerance = true;
Geom::Point const button_pt(event->button.x, event->button.y);
Geom::Point const p(desktop->w2d(button_pt));
if (event->button.state & GDK_MOD1_MASK)
Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH);
Inkscape::Rubberband::get(desktop)->start(desktop, p);
if (sc->grabbed) {
sp_canvas_item_ungrab(sc->grabbed, event->button.time);
sc->grabbed = NULL;
}
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK,
NULL, event->button.time);
sc->grabbed = SP_CANVAS_ITEM(desktop->acetate);
// remember what modifiers were on before button press
sc->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false;
sc->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false;
sc->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false;
sc->moved = FALSE;
rb_escaped = drag_escaped = 0;
ret = TRUE;
} else if (event->button.button == 3) {
// right click; do not eat it so that right-click menu can appear, but cancel dragging & rubberband
sp_select_context_abort(event_context);
}
break;
case GDK_MOTION_NOTIFY:
tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) {
Geom::Point const motion_pt(event->motion.x, event->motion.y);
Geom::Point const p(desktop->w2d(motion_pt));
if ( within_tolerance
&& ( abs( (gint) event->motion.x - xp ) < tolerance )
&& ( abs( (gint) event->motion.y - yp ) < 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 move the object, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
within_tolerance = false;
if (sc->button_press_ctrl || (sc->button_press_alt && !sc->button_press_shift && !selection->isEmpty())) {
// if it's not click and ctrl or alt was pressed (the latter with some selection
// but not with shift) we want to drag rather than rubberband
sc->dragging = TRUE;
desktop->setCursor(SP_SELECT_D_CURSOR);
//.........这里部分代码省略.........
示例3: path
void
sp_selected_path_combine(SPDesktop *desktop)
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
SPDocument *doc = sp_desktop_document(desktop);
if (g_slist_length((GSList *) selection->itemList()) < 1) {
sp_desktop_message_stack(desktop)->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();
GSList *items = g_slist_copy((GSList *) selection->itemList());
items = sp_degroup_list (items); // descend into any groups in selection
GSList *to_paths = NULL;
for (GSList *i = items; i != NULL; i = i->next) {
SPItem *item = (SPItem *) i->data;
if (!SP_IS_PATH(item) && !SP_IS_GROUP(item))
to_paths = g_slist_prepend(to_paths, item);
}
GSList *converted = NULL;
bool did = sp_item_list_to_curves(to_paths, &items, &converted);
g_slist_free(to_paths);
for (GSList *i = converted; i != NULL; i = i->next)
items = g_slist_prepend(items, doc->getObjectByRepr((Inkscape::XML::Node*)(i->data)));
items = sp_degroup_list (items); // converting to path may have added more groups, descend again
items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position);
items = g_slist_reverse(items);
// 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 (GSList *i = items; i != NULL; i = i->next) { // going from top to bottom
SPItem *item = (SPItem *) i->data;
if (!SP_IS_PATH(item)) {
continue;
}
if (!did) {
selection->clear();
did = true;
}
SPCurve *c = SP_PATH(item)->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();
}
}
g_slist_free(items);
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);
//.........这里部分代码省略.........
示例4: button_dt
static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event)
{
static bool dragging;
SPDesktop *desktop = event_context->desktop;
SPDocument *document = sp_desktop_document (desktop);
Inkscape::Selection *selection = sp_desktop_selection (desktop);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
Box3DContext *bc = SP_BOX3D_CONTEXT(event_context);
Persp3D *cur_persp = document->getCurrentPersp3D();
event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
gint ret = FALSE;
switch (event->type) {
case GDK_BUTTON_PRESS:
if ( event->button.button == 1 && !event_context->space_panning) {
Geom::Point const 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;
// remember clicked item, *not* disregarding groups (since a 3D box is a group), honoring Alt
event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, event->button.state & GDK_CONTROL_MASK);
dragging = true;
/* */
Geom::Point button_dt(desktop->w2d(button_w));
bc->drag_origin = from_2geom(button_dt);
bc->drag_ptB = from_2geom(button_dt);
bc->drag_ptC = from_2geom(button_dt);
// This can happen after saving when the last remaining perspective was purged and must be recreated.
if (!cur_persp) {
sp_box3d_context_ensure_persp_in_defs(document);
cur_persp = document->getCurrentPersp3D();
}
/* Projective preimages of clicked point under current perspective */
bc->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(button_dt), 0, Proj::Z);
bc->drag_ptB_proj = bc->drag_origin_proj;
bc->drag_ptC_proj = bc->drag_origin_proj;
bc->drag_ptC_proj.normalize();
bc->drag_ptC_proj[Proj::Z] = 0.25;
/* Snap center */
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, true, bc->item);
m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
bc->center = from_2geom(button_dt);
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
( GDK_KEY_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON_PRESS_MASK ),
NULL, event->button.time);
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 motion_dt(desktop->w2d(motion_w));
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, true, bc->item);
m.freeSnapReturnByRef(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
bc->ctrl_dragged = event->motion.state & GDK_CONTROL_MASK;
if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) {
// once shift is pressed, set bc->extruded
bc->extruded = true;
}
if (!bc->extruded) {
bc->drag_ptB = from_2geom(motion_dt);
bc->drag_ptC = from_2geom(motion_dt);
bc->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(motion_dt), 0, Proj::Z);
//.........这里部分代码省略.........
示例5: 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) {
//.........这里部分代码省略.........
示例6: 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()) {
//.........这里部分代码省略.........
示例7: 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 {
//.........这里部分代码省略.........