void Editor::onMapReady() { myUi->graphicsView->scene()->setSceneRect(0, 0, myGame->generator()->width(), myGame->generator()->height()); for (unsigned int i = 0; i < myGame->generator()->regions().size(); i++) { QPolygonF qring, sqring; auto ring = boost::geometry::exterior_ring(myGame->generator()->regions()[i].poly); boost::geometry::convert(ring, qring); boost::geometry::simplify(qring, sqring, 1); QPen pen; pen.setColor(QColor(0,0,0)); pen.setStyle(Qt::PenStyle::DashLine); QBrush brush; brush.setStyle(Qt::BrushStyle::SolidPattern); std::string colour = myGame->biomes()[myGame->generator()->regions()[i].biome]->jsonValue["mapColour"].asString(); pen.setColor(QColor(colour.c_str())); brush.setColor(QColor(colour.c_str())); QGraphicsPolygonItem * pi = new RegionPolygonItem(this); pi->setPen(pen); pi->setBrush(brush); pi->setPolygon(sqring); QPolygonF convex; boost::geometry::convex_hull(sqring, convex); double area = boost::geometry::area(convex); pi->setZValue(-area); pi->setData(0, i); pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsFocusable, true); pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsSelectable, true); myUi->graphicsView->scene()->addItem(pi); } }
void rce::gui::RImageMarkerScene:: addPolygonObject(const QPolygonF &polygon, const QBrush &brush, const QPen &pen, quint32 id) { // remove old if exists deletePolygon(id); // create new QPolygonF closedPolygon = polygon; closePolygon(closedPolygon); QGraphicsPolygonItem *newItem = addPolygon(closedPolygon, pen, brush); newItem->setData(RCE_ITEM_TYPE_DATA_INDEX, PolygonType); newItem->setData(RCE_ITEM_ID_DATA_INDEX, id); newItem->setZValue(1); polygonItems_[id] = newItem; }