Skip to content

Commit

Permalink
Add define header
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAugust12 committed Oct 30, 2023
1 parent a59670e commit 73ec82a
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 94 deletions.
39 changes: 7 additions & 32 deletions src/POLYGON.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,12 @@ class Polygon {

public:
Polygon(float thickness = 0, const sf::Color& fillColor = sf::Color::White,
const sf::Color& strokeColor = sf::Color::White)
: fill_color(fillColor), stroke_color(strokeColor),
stroke_width(thickness) {
polygonShape.setFillColor(fill_color);
polygonShape.setOutlineColor(stroke_color);
polygonShape.setOutlineThickness(thickness);
polygonShape.setPointCount(100000);
}
void addPoint(const sf::Vector2f& point) { points.push_back(point); }
void setFillColor(sf::Color color) {
this->fill_color = color;
polygonShape.setFillColor(fill_color);
}
void setStrokeColor(sf::Color color) {
this->stroke_color = color;
polygonShape.setOutlineColor(stroke_color);
}
void setThickNess(float thickness) {
this->stroke_width = thickness;
polygonShape.setOutlineThickness(thickness);
}
void setPointCount(int cnt) { polygonShape.setPointCount(cnt); }
void draw(sf::RenderWindow& window) {
if (points.size() >= 3) {
polygonShape.setPointCount(
static_cast< unsigned int >(points.size()));
for (size_t i = 0; i < points.size(); ++i) {
polygonShape.setPoint(i, points[i]);
}
window.draw(polygonShape);
}
}
const sf::Color& strokeColor = sf::Color::White);
void addPoint(const sf::Vector2f& point);
void setFillColor(sf::Color color);
void setStrokeColor(sf::Color color);
void setThickNess(float thickness);
void setPointCount(int cnt);
void draw(sf::RenderWindow& window);
};
#endif
45 changes: 5 additions & 40 deletions src/POLYLINE.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,10 @@ class PolyLine {
static int countPoint;

public:
PolyLine(float thick = 0, const sf::Color& col = sf::Color::White)
: thickness(thick), color(col) {
polygonShape.setFillColor(sf::Color::Transparent);
polygonShape.setOutlineThickness(thickness);
polygonShape.setOutlineColor(color);
}

void addPoint(const sf::Vector2f& point) {
points.push_back(point);
countPoint++;
}

void setThickness(float thick) {
thickness = thick;
polygonShape.setOutlineThickness(thickness);
}

void setColor(sf::Color col) {
color = col;
polygonShape.setOutlineColor(color);
}

void draw(sf::RenderWindow& window) {
if (points.size() >= 2) {
std::vector< sf::Vector2f > combinedPoints;
for (const sf::Vector2f& point : points) {
combinedPoints.push_back(point);
}
for (int i = points.size() - 1; i >= 0; --i) {
combinedPoints.push_back(points[i]);
}
polygonShape.setPointCount(
static_cast< unsigned int >(combinedPoints.size()));
for (size_t i = 0; i < combinedPoints.size(); ++i) {
polygonShape.setPoint(i, combinedPoints[i]);
}
window.draw(polygonShape);
}
}
PolyLine(float thick = 0, const sf::Color& col = sf::Color::White);
void addPoint(const sf::Vector2f& point);
void setThickness(float thick);
void setColor(sf::Color col);
void draw(sf::RenderWindow& window);
};
int PolyLine::countPoint = 0;
#endif
26 changes: 4 additions & 22 deletions src/SFLINE.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,9 @@ class sfLine {

public:
sfLine(const sf::Vector2f& p1, const sf::Vector2f& p2, float thick = 1,
const sf::Color& col = sf::Color::White)
: thickness(thick), color(col), point1(p1), point2(p2) {
setPoint(point1, point2);
setColor(color);
}
void setColor(sf::Color col) {
color = col;
line.setFillColor(color);
}
void setPoint(sf::Vector2f p1, sf::Vector2f p2) {
point1 = p1;
point2 = p2;
sf::Vector2f direction = point2 - point1;
float length =
std::sqrt(direction.x * direction.x + direction.y * direction.y);
line.setSize(sf::Vector2f(length, thickness));
line.setPosition(point1);
float angle =
std::atan2(direction.y, direction.x) * 180.f / 3.14159265359f;
line.setRotation(angle);
}
void draw(sf::RenderWindow& window) { window.draw(line); }
const sf::Color& col = sf::Color::White);
void setColor(sf::Color col);
void setPoint(sf::Vector2f p1, sf::Vector2f p2);
void draw(sf::RenderWindow& window);
};
#endif
34 changes: 34 additions & 0 deletions src/polygon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "POLYGON.h"

Polygon::Polygon(float thickness, const sf::Color& fillColor,
const sf::Color& strokeColor)
: fill_color(fillColor), stroke_color(strokeColor),
stroke_width(thickness) {
polygonShape.setFillColor(fill_color);
polygonShape.setOutlineColor(stroke_color);
polygonShape.setOutlineThickness(thickness);
polygonShape.setPointCount(100000);
}
void Polygon::addPoint(const sf::Vector2f& point) { points.push_back(point); }
void Polygon::setFillColor(sf::Color color) {
this->fill_color = color;
polygonShape.setFillColor(fill_color);
}
void Polygon::setStrokeColor(sf::Color color) {
this->stroke_color = color;
polygonShape.setOutlineColor(stroke_color);
}
void Polygon::setThickNess(float thickness) {
this->stroke_width = thickness;
polygonShape.setOutlineThickness(thickness);
}
void Polygon::setPointCount(int cnt) { polygonShape.setPointCount(cnt); }
void Polygon::draw(sf::RenderWindow& window) {
if (points.size() >= 3) {
polygonShape.setPointCount(static_cast< unsigned int >(points.size()));
for (size_t i = 0; i < points.size(); ++i) {
polygonShape.setPoint(i, points[i]);
}
window.draw(polygonShape);
}
}
41 changes: 41 additions & 0 deletions src/polyline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "POLYLINE.h"
int PolyLine::countPoint = 0;
PolyLine::PolyLine(float thick, const sf::Color& col)
: thickness(thick), color(col) {
polygonShape.setFillColor(sf::Color::Transparent);
polygonShape.setOutlineThickness(thickness);
polygonShape.setOutlineColor(color);
}

void PolyLine::addPoint(const sf::Vector2f& point) {
points.push_back(point);
countPoint++;
}

void PolyLine::setThickness(float thick) {
thickness = thick;
polygonShape.setOutlineThickness(thickness);
}

void PolyLine::setColor(sf::Color col) {
color = col;
polygonShape.setOutlineColor(color);
}

void PolyLine::draw(sf::RenderWindow& window) {
if (points.size() >= 2) {
std::vector< sf::Vector2f > combinedPoints;
for (const sf::Vector2f& point : points) {
combinedPoints.push_back(point);
}
for (int i = points.size() - 1; i >= 0; --i) {
combinedPoints.push_back(points[i]);
}
polygonShape.setPointCount(
static_cast< unsigned int >(combinedPoints.size()));
for (size_t i = 0; i < combinedPoints.size(); ++i) {
polygonShape.setPoint(i, combinedPoints[i]);
}
window.draw(polygonShape);
}
}
24 changes: 24 additions & 0 deletions src/sfline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "SFLINE.h"

sfLine::sfLine(const sf::Vector2f& p1, const sf::Vector2f& p2, float thick,
const sf::Color& col)
: thickness(thick), color(col), point1(p1), point2(p2) {
setPoint(point1, point2);
setColor(color);
}
void sfLine::setColor(sf::Color col) {
color = col;
line.setFillColor(color);
}
void sfLine::setPoint(sf::Vector2f p1, sf::Vector2f p2) {
point1 = p1;
point2 = p2;
sf::Vector2f direction = point2 - point1;
float length =
std::sqrt(direction.x * direction.x + direction.y * direction.y);
line.setSize(sf::Vector2f(length, thickness));
line.setPosition(point1);
float angle = std::atan2(direction.y, direction.x) * 180.f / 3.14159265359f;
line.setRotation(angle);
}
void sfLine::draw(sf::RenderWindow& window) { window.draw(line); }

0 comments on commit 73ec82a

Please sign in to comment.