-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
92 lines (68 loc) · 2.31 KB
/
Copy pathmain.cpp
File metadata and controls
92 lines (68 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include <thread>
#include "headers/sorting.hpp"
#include "headers/draw.hpp"
#include "headers/initialize.hpp"
#include "headers/stepStruct.hpp"
int main()
{
//click logic
bool wasLeftPressed = false;
bool wasRightPressed = false;
int arrSize = 35;
std::vector<int> arr(arrSize);
std::vector<sf::RectangleShape> rectangleList(arrSize);
std::vector<stepStruct> steps;
//std::vector<std::vector<int>> steps;
initialize(arr, arrSize);
//create window, get size (size should probably be taken in main every frame)
sf::RenderWindow window(sf::VideoMode({800, 600}), "Algorithm visualiser");
insertionSort(arr, arrSize, steps);
//mergeSort(arr, 0, arrSize - 1, steps);
long long unsigned stepIndex = 0;
steps.emplace_back(arr, 0, 0);
stepStruct currentStepStruct = steps.at(stepIndex);
//loop to keep open
while(window.isOpen()){
while (const std::optional event = window.pollEvent()){
if(event->is<sf::Event::Closed>()){
window.close();
}
}
//fill display with black
window.clear(sf::Color(0,0,0));
drawRectangles(rectangleList, currentStepStruct, window);
//display what is set up
window.display();
bool isLeftPressed = sf::Mouse::isButtonPressed(sf::Mouse::Button::Left);
if(isLeftPressed && !wasLeftPressed){
if(stepIndex < steps.size() - 1){
stepIndex++;
}
}
wasLeftPressed = isLeftPressed;
bool isRightPressed = sf::Mouse::isButtonPressed(sf::Mouse::Button::Right);
if(isRightPressed && !wasRightPressed){
if(stepIndex >= 1){
stepIndex--;
}
}
wasRightPressed = isRightPressed;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right))
{
if(stepIndex < steps.size() - 1){
stepIndex++;
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left))
{
if(stepIndex >= 1){
stepIndex--;
}
}
currentStepStruct = steps.at(stepIndex);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}