-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a59670e
commit 73ec82a
Showing
6 changed files
with
115 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } |