/* MapThingsClipboardItem::addThings * Copies [things] *******************************************************************/ void MapThingsClipboardItem::addThings(vector<MapThing*>& things) { // Copy things double min_x = 99999999; double min_y = 99999999; double max_x = -99999999; double max_y = -99999999; for (unsigned a = 0; a < things.size(); a++) { MapThing* copy_thing = new MapThing(); copy_thing->copy(things[a]); this->things.push_back(copy_thing); if (things[a]->xPos() < min_x) min_x = things[a]->xPos(); if (things[a]->yPos() < min_y) min_y = things[a]->yPos(); if (things[a]->xPos() > max_x) max_x = things[a]->xPos(); if (things[a]->yPos() > max_y) max_y = things[a]->yPos(); } // Get midpoint double mid_x = min_x + ((max_x - min_x) * 0.5); double mid_y = min_y + ((max_y - min_y) * 0.5); this->midpoint.set(mid_x, mid_y); // Adjust thing positions for (unsigned a = 0; a < this->things.size(); a++) { MapThing* thing = this->things[a]; thing->setPos(thing->xPos() - mid_x, thing->yPos() - mid_y); } }
/* MapThingsClipboardItem::pasteToMap * Pastes copied things to [map] at [position] *******************************************************************/ void MapThingsClipboardItem::pasteToMap(SLADEMap* map, fpoint2_t position) { for (unsigned a = 0; a < things.size(); a++) { MapThing* newthing = map->createThing(0, 0); newthing->copy(things[a]); newthing->setPos(position.x + things[a]->xPos(), position.y + things[a]->yPos()); } }