Oi oi oi,
I've been working on a sorting program, that takes the users input and then displays the sorting process in real time. The plan is, to display every number as a bar in a bar graph and update the graph after every single sorting step. The code for the sfml-graphics window looks like this:
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
window.clear();
// Draw X- and Y-Axis
sf::RectangleShape xAxis(sf::Vector2f(xAxisLength, 3));
xAxis.setFillColor(sf::Color::White);
xAxis.setPosition(x0xAxis, y0xAxis);
sf::RectangleShape yAxis(sf::Vector2f(3, yAxisLength));
yAxis.setFillColor(sf::Color::White);
yAxis.setPosition(x0yAxis, y0yAxis);
window.draw(xAxis);
window.draw(yAxis);
// Draw the bars
int i;
for (i = 0; i < entries; i++)
{
sf::RectangleShape bar(sf::Vector2f(barWidth, data[i] * factor));
bar.setFillColor(sf::Color::Blue);
bar.setPosition(3 + x0yAxis + i * barWidth, y0xAxis - data[i] * factor);
window.draw(bar);
}
window.display();
// Perform one step of the sorting process on the array "data"
startSort(method, data, entries);
Sleep(500);
}
}
Where "data" is an array full of the users data, "entries" is the number of entries, and "method" is an identifier, that defines which sorting method is used.
The program works with one little problem: The window is only updated every 500 milliseconds while i constantly move my cursor across the graphics window. If I don't move my cursor, nothing happens at all. So not only the graphics, but the entire program appears to be frozen until I move my mouse again.
Any suggestions on how to refresh the window automatically?
Thanks in advance,
HABEYOUSEENCHEFPLS?