/* * Map each gradient to its usage count for both fill and stroke styles */ void gr_get_usage_counts(SPDocument *doc, std::map<SPGradient *, gint> *mapUsageCount ) { if (!doc) return; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); bool ingroups = TRUE; GSList *all_list = get_all_doc_items(NULL, doc->getRoot(), onlyvisible, onlysensitive, ingroups, NULL); for (GSList *i = all_list; i != NULL; i = i->next) { SPItem *item = SP_ITEM(i->data); if (!item->getId()) continue; SPGradient *gr = NULL; gr = gr_item_get_gradient(item, true); // fill if (gr) { mapUsageCount->count(gr) > 0 ? (*mapUsageCount)[gr] += 1 : (*mapUsageCount)[gr] = 1; } gr = gr_item_get_gradient(item, false); // stroke if (gr) { mapUsageCount->count(gr) > 0 ? (*mapUsageCount)[gr] += 1 : (*mapUsageCount)[gr] = 1; } } }
bool Equipment::unequip(SPItem item, unsigned int skillBase, unsigned int magicBase, bool removeOnly) { if (item->getUsageType() == ItemUsageType::equip && item->getEquippedStatus() == ItemEquippedStatus::equipped) { // check required skill / magic, check unequip as on client EquipmentType et = getEquipmentType(item); std::cout << "et: " << et << ((items[et].get()!=0) ? " not null" : "null") << std::endl; if (et != et_invalid && items[et].get()!=0 && items[et]->getId() == item->getId()) { if (!removeOnly) { items[et]->setEquippedStatus(ItemEquippedStatus::not_equipped); } items[et] = SPItem(); // null item // check if other items need to be unequipped as a consequence of this item being removed (skill / magic might have dropped) checkUnequipUnsupportedItems(skillBase, magicBase, removeOnly); calculateEffects(); return true; } } return false; }
static void sp_item_widget_label_changed( GtkWidget */*widget*/, SPWidget *spw ) { if (gtk_object_get_data (GTK_OBJECT (spw), "blocked")) return; SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); g_return_if_fail (item != NULL); gtk_object_set_data (GTK_OBJECT (spw), "blocked", GUINT_TO_POINTER (TRUE)); /* Retrieve the label widget for the object's id */ GtkWidget *id_entry = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "id")); gchar *id = (gchar *) gtk_entry_get_text (GTK_ENTRY (id_entry)); g_strcanon (id, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.:", '_'); GtkWidget *id_label = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "id_label")); if (!strcmp (id, item->getId())) { gtk_label_set_markup_with_mnemonic (GTK_LABEL (id_label), _("_Id")); } else if (!*id || !isalnum (*id)) { gtk_label_set_text (GTK_LABEL (id_label), _("Id invalid! ")); } else if (SP_ACTIVE_DOCUMENT->getObjectById(id) != NULL) { gtk_label_set_text (GTK_LABEL (id_label), _("Id exists! ")); } else { SPException ex; gtk_label_set_markup_with_mnemonic (GTK_LABEL (id_label), _("_Id")); SP_EXCEPTION_INIT (&ex); sp_object_setAttribute (SP_OBJECT (item), "id", id, &ex); sp_document_done (SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object ID")); } /* Retrieve the label widget for the object's label */ GtkWidget *label_entry = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "label")); gchar *label = (gchar *)gtk_entry_get_text (GTK_ENTRY (label_entry)); g_assert(label != NULL); /* Give feedback on success of setting the drawing object's label * using the widget's label text */ SPObject *obj = (SPObject*)item; if (strcmp (label, obj->defaultLabel())) { obj->setLabel(label); sp_document_done (SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object label")); } /* Retrieve the title */ GtkWidget *w = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(spw), "title")); gchar *title = (gchar *)gtk_entry_get_text(GTK_ENTRY (w)); if (obj->setTitle(title)) sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object title")); /* Retrieve the description */ GtkTextView *tv = GTK_TEXT_VIEW(gtk_object_get_data(GTK_OBJECT(spw), "desc")); GtkTextBuffer *buf = gtk_text_view_get_buffer(tv); GtkTextIter start, end; gtk_text_buffer_get_bounds(buf, &start, &end); gchar *desc = gtk_text_buffer_get_text(buf, &start, &end, TRUE); if (obj->setDesc(desc)) sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object description")); g_free(desc); gtk_object_set_data (GTK_OBJECT (spw), "blocked", GUINT_TO_POINTER (FALSE)); } // end of sp_item_widget_label_changed()
/** * Takes a list of inkscape items, extracts the graph defined by * connectors between them, and uses graph layout techniques to find * a nice layout */ void graphlayout(std::vector<SPItem*> const &items) { if(items.empty()) { return; } list<SPItem *> selected; filterConnectors(items,selected); if (selected.empty()) return; const unsigned n=selected.size(); //Check 2 or more selected objects if (n < 2) return; // add the connector spacing to the size of node bounding boxes // so that connectors can always be routed between shapes SPDesktop* desktop = SP_ACTIVE_DESKTOP; double spacing = 0; if(desktop) spacing = desktop->namedview->connector_spacing+0.1; map<string,unsigned> nodelookup; vector<Rectangle*> rs; vector<Edge> es; for (list<SPItem *>::iterator i(selected.begin()); i != selected.end(); ++i) { SPItem *u=*i; Geom::OptRect const item_box = u->desktopVisualBounds(); if(item_box) { Geom::Point ll(item_box->min()); Geom::Point ur(item_box->max()); nodelookup[u->getId()]=rs.size(); rs.push_back(new Rectangle(ll[0]-spacing,ur[0]+spacing, ll[1]-spacing,ur[1]+spacing)); } else { // I'm not actually sure if it's possible for something with a // NULL item-box to be attached to a connector in which case we // should never get to here... but if such a null box can occur it's // probably pretty safe to simply ignore //fprintf(stderr,"NULL item_box found in graphlayout, ignoring!\n"); } } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SimpleConstraints scx,scy; double ideal_connector_length = prefs->getDouble("/tools/connector/length", 100.0); double directed_edge_height_modifier = 1.0; bool directed = prefs->getBool("/tools/connector/directedlayout"); bool avoid_overlaps = prefs->getBool("/tools/connector/avoidoverlaplayout"); for (list<SPItem *>::iterator i(selected.begin()); i != selected.end(); ++i) { SPItem *iu=*i; map<string,unsigned>::iterator i_iter=nodelookup.find(iu->getId()); map<string,unsigned>::iterator i_iter_end=nodelookup.end(); if(i_iter==i_iter_end) { continue; } unsigned u=i_iter->second; std::vector<SPItem *> nlist=iu->avoidRef->getAttachedConnectors(Avoid::runningFrom); list<SPItem *> connectors; connectors.insert(connectors.end(), nlist.begin(), nlist.end()); for (list<SPItem *>::iterator j(connectors.begin()); j != connectors.end(); ++j) { SPItem *conn=*j; SPItem *iv; SPItem *items[2]; assert(isConnector(conn)); SP_PATH(conn)->connEndPair.getAttachedItems(items); if(items[0]==iu) { iv=items[1]; } else { iv=items[0]; } if (iv == NULL) { // The connector is not attached to anything at the // other end so we should just ignore it. continue; } // If iv not in nodelookup we again treat the connector // as disconnected and continue map<string,unsigned>::iterator v_pair=nodelookup.find(iv->getId()); if(v_pair!=nodelookup.end()) { unsigned v=v_pair->second; //cout << "Edge: (" << u <<","<<v<<")"<<endl; es.push_back(make_pair(u,v)); if(conn->style->marker_end.set) { if(directed && strcmp(conn->style->marker_end.value,"none")) { scy.push_back(new SimpleConstraint(v, u, (ideal_connector_length * directed_edge_height_modifier))); } } } } } const unsigned E = es.size(); double eweights[E]; fill(eweights,eweights+E,1); vector<Component*> cs; connectedComponents(rs,es,scx,scy,cs); for(unsigned i=0;i<cs.size();i++) { Component* c=cs[i]; if(c->edges.size()<2) continue; CheckProgress test(0.0001,100,selected,rs,nodelookup); ConstrainedMajorizationLayout alg(c->rects,c->edges,eweights,ideal_connector_length,test); alg.setupConstraints(NULL,NULL,avoid_overlaps, NULL,NULL,&c->scx,&c->scy,NULL,NULL); alg.run(); } separateComponents(cs); for (list<SPItem *>::iterator it(selected.begin()); it != selected.end(); ++it) { SPItem *u=*it; if(!isConnector(u)) { map<string,unsigned>::iterator i=nodelookup.find(u->getId()); if(i!=nodelookup.end()) { Rectangle* r=rs[i->second]; Geom::OptRect item_box = u->desktopVisualBounds(); if (item_box) { Geom::Point const curr(item_box->midpoint()); Geom::Point const dest(r->getCentreX(),r->getCentreY()); sp_item_move_rel(u, Geom::Translate(dest - curr)); } } } } for(unsigned i=0;i<scx.size();i++) { delete scx[i]; } for(unsigned i=0;i<scy.size();i++) { delete scy[i]; } for(unsigned i=0;i<rs.size();i++) { delete rs[i]; } }