From d7b8dd23a95bf54fd559cddc58ccb1c57806d112 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 22 Jul 2020 15:28:36 +0900 Subject: [PATCH] Impl drawing of white triangles --- src/state.cpp | 31 +++++++++++++++++++++++++++---- src/state.hpp | 5 +++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/state.cpp b/src/state.cpp index 1356073..be6e256 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -17,8 +17,11 @@ currentTri_state(CurrentState::NONE) ImGui::SFML::Init(window); window.setFramerateLimit(60); - currentTri.setPointCount(3); - currentTri.setFillColor(sf::Color::White); + pointCircle.setRadius(7.0f); + pointCircle.setOrigin(7.0f, 7.0f); + pointCircle.setFillColor(sf::Color::White); + pointCircle.setOutlineColor(sf::Color::Black); + pointCircle.setOutlineThickness(1.0f); } Tri::State::~State() { @@ -39,12 +42,21 @@ void Tri::State::handle_events() { } else if(event.type == sf::Event::MouseButtonPressed) { switch(currentTri_state) { case CurrentState::NONE: + currentTri[0] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y); + currentTri_state = CurrentState::FIRST; break; case CurrentState::FIRST: + currentTri[1] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y); + currentTri_state = CurrentState::SECOND; break; case CurrentState::SECOND: - break; - case CurrentState::THIRD: + currentTri[2] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y); + 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; } } @@ -64,6 +76,17 @@ void Tri::State::draw() { window.clear(); 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(); } diff --git a/src/state.hpp b/src/state.hpp index a48328e..b0c43ae 100644 --- a/src/state.hpp +++ b/src/state.hpp @@ -25,8 +25,9 @@ namespace Tri { sf::RenderWindow window; std::vector tris; - sf::ConvexShape currentTri; - enum CurrentState { NONE, FIRST, SECOND, THIRD } currentTri_state; + sf::Vector2f currentTri[3]; + enum CurrentState { NONE = 0, FIRST = 1, SECOND = 2} currentTri_state; + sf::CircleShape pointCircle; sf::Event event;