| 32 | } |
| 33 | |
| 34 | void drawPolygon(RenderTarget surface, std::vector<Transform::UnitVector>& points, |
| 35 | const DrawPolygonOptions& options) |
| 36 | { |
| 37 | const bool drawLines = findOptionOrDefault(options, "lines", true); |
| 38 | const bool drawPoints = findOptionOrDefault(options, "points", true); |
| 39 | const float pointRadius = findOptionOrDefault(options, "radius", 6.f); |
| 40 | const sf::Color lineColor |
| 41 | = findOptionOrDefault(options, "line_color", sf::Color::White); |
| 42 | const sf::Color pointColor |
| 43 | = findOptionOrDefault(options, "point_color", sf::Color::White); |
| 44 | sf::CircleShape polyPt; |
| 45 | polyPt.setRadius(pointRadius); |
| 46 | polyPt.setPointCount(100); |
| 47 | polyPt.setFillColor(pointColor); |
| 48 | for (std::size_t i = 0; i < points.size(); i++) |
| 49 | { |
| 50 | const Transform::UnitVector& point1 |
| 51 | = points[i].to<Transform::Units::ScenePixels>(); |
| 52 | const Transform::UnitVector& point2 |
| 53 | = points[(i == points.size() - 1) ? 0 : i + 1] |
| 54 | .to<Transform::Units::ScenePixels>(); |
| 55 | if (drawLines) |
| 56 | { |
| 57 | const sf::Color currentLineColor = findOptionOrDefault( |
| 58 | options, ("line_color_" + std::to_string(i)).c_str(), lineColor); |
| 59 | drawLine( |
| 60 | surface, point1.x, point1.y, point2.x, point2.y, 2, currentLineColor); |
| 61 | } |
| 62 | } |
| 63 | for (std::size_t i = 0; i < points.size(); i++) |
| 64 | { |
| 65 | const Transform::UnitVector& point1 |
| 66 | = points[i].to<Transform::Units::ScenePixels>(); |
| 67 | if (drawPoints) |
| 68 | { |
| 69 | const sf::Color currentPointColor = findOptionOrDefault( |
| 70 | options, ("point_color_" + std::to_string(i)).c_str(), pointColor); |
| 71 | polyPt.setFillColor(currentPointColor); |
| 72 | polyPt.setPosition(point1.x - pointRadius, point1.y - pointRadius); |
| 73 | surface.draw(polyPt); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } // namespace obe::Graphics::Utils |
no test coverage detected