So i'm probably just overlooking something very obvious here, but basically I have a for loop inside the event loop. There's a switch and under the case of left clicking there is a for loop. After the for loop there is an if statement and the program seems to completely ignore the for loop and jumps straight to the if statement.
case sf::Event::MouseButtonPressed: // the left click case in the switch
if(event.mouseButton.button == sf::Mouse::Left)
{
for(int i = 0; i < circles.size(); i++) //the for loop
{
if(circles[i].getGlobalBounds().contains(mouseCoords))
{
Circle newCircle;
int radius = circles[i].getCircleRadius();
std::cout<<"Hello"<<std::endl;
circles.pop_back();
newCircle.CreateCircle(placementCoords, radius, r, g, b, 124, 170, 204);
circles.push_back(newCircle);
}
}
//if requarments are met a new instance of shapes will be created, then given info(position, color, etc..) and be saved into a vector
if(canvas.getGlobalBounds().contains(mouseCoords)) //if statement I was talking about
{
Circle newCircle;
newCircle.CreateCircle(mouseCoords, defaultRadius, 176, 214, 242, 124, 170, 204);
circles.push_back(newCircle);
placementCoords = mouseCoords;
selectingSize = true;
}
}
Btw since this thread is still fresh - could you please tell me why is the window going down after I draw something? When I set the window size to 1080p and the texture size to 1080p after drawing something it moves down a couple of pixels - again and again.. Doesn't happen if I set them to 800x600 for example.
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
std::vector <sf::Vertex> lines;
sf::Texture texture;
sf::Sprite sprite;
sprite.setPosition(0, 0);
texture.create(800, 600);
sf::Event event;
int mousedown = 0;
// run the program as long as the window is open
window.setFramerateLimit(60);
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
else if ((event.type == sf::Event::MouseMoved) && (mousedown == 1))
{
sf::Vertex point;
point.color = sf::Color::Black;
point.position = sf::Vector2f(sf::Mouse::getPosition(window));
lines.push_back(point);
}
else if (event.type == sf::Event::MouseButtonPressed)
{
mousedown = 1;
}
else if (event.type == sf::Event::MouseButtonReleased)
{
mousedown = 0;
texture.update(window);
lines.clear();
}
}
window.clear(sf::Color::White);
sprite.setTexture(texture);
window.draw(sprite);
window.draw(&lines[0], lines.size(), sf::LinesStrip);
window.display();
}
return 0;
}