Decouple drawing selected points from drawing tris

This commit is contained in:
Stephen Seo 2020-07-22 21:17:49 +09:00
parent fea2379d58
commit c278bddc27
2 changed files with 9 additions and 12 deletions

View file

@ -129,7 +129,6 @@ void Tri::State::handle_events() {
}
} else if(event.type == sf::Event::MouseButtonPressed) {
if(!is_in_clickable_menu()) {
flags.set(7);
switch(currentTri_state) {
case CurrentState::NONE:
currentTri[0] = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
@ -160,6 +159,7 @@ void Tri::State::handle_events() {
tris.back().setFillColor(pointCircle.getFillColor());
currentTri_state = CurrentState::NONE;
currentTri_maxState = CurrentState::NONE;
flags.set(7);
break;
}
}
@ -217,27 +217,24 @@ void Tri::State::draw() {
draw_to_target(&window);
}
for(unsigned int i = 0; i < currentTri_state; ++i) {
pointCircle.setPosition(currentTri[i]);
window.draw(pointCircle);
}
// draw gui stuff
ImGui::SFML::Render(window);
window.display();
}
void Tri::State::draw_to_target(sf::RenderTarget *target, bool draw_points) {
void Tri::State::draw_to_target(sf::RenderTarget *target) {
target->clear(bgColor);
// draw tris
for(unsigned int i = 0; i < trisIndex; ++i) {
target->draw(tris[i]);
}
// draw points
if(draw_points) {
for(unsigned int i = 0; i < currentTri_state; ++i) {
pointCircle.setPosition(currentTri[i]);
target->draw(pointCircle);
}
}
}
unsigned int Tri::State::get_width() const {
@ -280,7 +277,7 @@ bool Tri::State::do_save() {
return false;
}
draw_to_target(&saveTexture, false);
draw_to_target(&saveTexture);
saveTexture.display();
sf::Image saveImage = saveTexture.getTexture().copyToImage();

View file

@ -61,7 +61,7 @@ namespace Tri {
void draw();
private:
void draw_to_target(sf::RenderTarget *target, bool draw_points = true);
void draw_to_target(sf::RenderTarget *target);
public:
unsigned int get_width() const;