A5/Polygon.cpp

34 lines
730 B
C++
Raw Normal View History

2024-11-06 17:02:59 -07:00
#include <SFML/Graphics/ConvexShape.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include "Coordinate.h"
#include "Polygon.h"
APolygon::APolygon() {
_color = sf::Color::White;
mNumVertices = 0;
mVertices = nullptr;
}
APolygon::~APolygon() {
delete[] mVertices;
}
void APolygon::setColor(const sf::Color COLOR) {
_color = COLOR;
}
void APolygon::draw(sf::RenderTarget& window) {
sf::ConvexShape shape(mNumVertices);
for (int i = 0; i < mNumVertices; i++) {
shape.setPoint(i, sf::Vector2f(mVertices[i].x, mVertices[i].y));
}
shape.setFillColor(_color);
window.draw(shape);
}
void APolygon::setCoordinate(const int IDX, const Coordinate COORD) {
mVertices[IDX] = COORD;
}