-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.cpp
More file actions
42 lines (32 loc) · 1.44 KB
/
Copy pathdraw.cpp
File metadata and controls
42 lines (32 loc) · 1.44 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
#include <vector>
#include <SFML/Graphics.hpp>
#include "headers/draw.hpp"
#include "headers/stepStruct.hpp"
//assumes maxValue is the size of array, should be fine for how it's used before
void drawRectangles(std::vector<sf::RectangleShape> rectangleList, stepStruct currentStepStruct, sf::RenderWindow& window){
std::vector<int> currentStep = currentStepStruct.step;
int arrSize = currentStep.size();
int maxValue = arrSize;
for (int i = 0; i < arrSize; i++){
float windowSizeY = window.getSize().y;
float windowSizeX = window.getSize().x;
float height = -(windowSizeY/maxValue) * currentStep.at(i);
sf::RectangleShape rectangle = rectangleList[i];
rectangle.setSize({10.f, height});
if(i == currentStepStruct.keyIndex && i == currentStepStruct.comparatorIndex){
rectangle.setFillColor(sf::Color::Yellow);
}
else if(i == currentStepStruct.keyIndex){
rectangle.setFillColor(sf::Color::Red);
} else if(i == currentStepStruct.comparatorIndex){
rectangle.setFillColor(sf::Color::Green);
}
else{
rectangle.setFillColor(sf::Color::White);
}
//this is useless after first call, but I don't feel like doing 2 functions
float currentXPosition = (windowSizeX/arrSize) * i + 5.f;
rectangle.setPosition({currentXPosition, window.getSize().y});
window.draw(rectangle);
}
}