Impl drawing of white triangles
This commit is contained in:
parent
b9d7a0496d
commit
d7b8dd23a9
2 changed files with 30 additions and 6 deletions
|
@ -17,8 +17,11 @@ currentTri_state(CurrentState::NONE)
|
||||||
ImGui::SFML::Init(window);
|
ImGui::SFML::Init(window);
|
||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
|
|
||||||
currentTri.setPointCount(3);
|
pointCircle.setRadius(7.0f);
|
||||||
currentTri.setFillColor(sf::Color::White);
|
pointCircle.setOrigin(7.0f, 7.0f);
|
||||||
|
pointCircle.setFillColor(sf::Color::White);
|
||||||
|
pointCircle.setOutlineColor(sf::Color::Black);
|
||||||
|
pointCircle.setOutlineThickness(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tri::State::~State() {
|
Tri::State::~State() {
|
||||||
|
@ -39,12 +42,21 @@ void Tri::State::handle_events() {
|
||||||
} else if(event.type == sf::Event::MouseButtonPressed) {
|
} else if(event.type == sf::Event::MouseButtonPressed) {
|
||||||
switch(currentTri_state) {
|
switch(currentTri_state) {
|
||||||
case CurrentState::NONE:
|
case CurrentState::NONE:
|
||||||
|
currentTri[0] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
|
||||||
|
currentTri_state = CurrentState::FIRST;
|
||||||
break;
|
break;
|
||||||
case CurrentState::FIRST:
|
case CurrentState::FIRST:
|
||||||
|
currentTri[1] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
|
||||||
|
currentTri_state = CurrentState::SECOND;
|
||||||
break;
|
break;
|
||||||
case CurrentState::SECOND:
|
case CurrentState::SECOND:
|
||||||
break;
|
currentTri[2] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
|
||||||
case CurrentState::THIRD:
|
tris.emplace_back(sf::ConvexShape(3));
|
||||||
|
tris.back().setPoint(0, currentTri[0]);
|
||||||
|
tris.back().setPoint(1, currentTri[1]);
|
||||||
|
tris.back().setPoint(2, currentTri[2]);
|
||||||
|
tris.back().setFillColor(sf::Color::White); // TODO use chosen color
|
||||||
|
currentTri_state = CurrentState::NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +76,17 @@ void Tri::State::draw() {
|
||||||
window.clear();
|
window.clear();
|
||||||
ImGui::SFML::Render(window);
|
ImGui::SFML::Render(window);
|
||||||
|
|
||||||
|
// draw tris
|
||||||
|
for(auto& tri : tris) {
|
||||||
|
window.draw(tri);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw points
|
||||||
|
for(unsigned int i = 0; i < currentTri_state; ++i) {
|
||||||
|
pointCircle.setPosition(currentTri[i]);
|
||||||
|
window.draw(pointCircle);
|
||||||
|
}
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,9 @@ namespace Tri {
|
||||||
|
|
||||||
sf::RenderWindow window;
|
sf::RenderWindow window;
|
||||||
std::vector<sf::ConvexShape> tris;
|
std::vector<sf::ConvexShape> tris;
|
||||||
sf::ConvexShape currentTri;
|
sf::Vector2f currentTri[3];
|
||||||
enum CurrentState { NONE, FIRST, SECOND, THIRD } currentTri_state;
|
enum CurrentState { NONE = 0, FIRST = 1, SECOND = 2} currentTri_state;
|
||||||
|
sf::CircleShape pointCircle;
|
||||||
|
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue