115 lines
2.5 KiB
C++
115 lines
2.5 KiB
C++
// for now juist CLI, print an arr, then print each it
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include <SFML/Graphics/Color.hpp>
|
|
#include <SFML/Graphics/Font.hpp>
|
|
#include <SFML/Graphics/RenderWindow.hpp>
|
|
#include <SFML/Graphics/Text.hpp>
|
|
#include <SFML/Window/Window.hpp>
|
|
#include <SFML/Window.hpp>
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
#include "timer.hpp"
|
|
#include "sorters.hpp"
|
|
|
|
using namespace std::chrono;
|
|
using namespace std;
|
|
|
|
bool displaynumbers(vector<int> input) {
|
|
for (size_t i = 0; i < input.size(); ++i) {
|
|
printf("array:%d ", input[i]);
|
|
}
|
|
printf("\n");
|
|
return false;
|
|
}
|
|
|
|
string arraytostr(SortInput input) {
|
|
string myoutput;
|
|
ostringstream stringrep;
|
|
for (size_t i = 0; i < input.values.size(); ++i) {
|
|
stringrep << input.values[i] <<" | ";
|
|
}
|
|
return stringrep.str();
|
|
}
|
|
|
|
vector<int> dataprovider(){
|
|
return vector<int> {9,8,1,2,7,3,6,4,5};
|
|
}
|
|
|
|
void setupsorttimers(TimerManager &mytimermanager, SteppedBsort &mysession){
|
|
unique_ptr<Timer> mytimer = make_unique<Timer>(
|
|
"sort1", 0,
|
|
[&mysession](){return mysession.step();},
|
|
milliseconds(250));
|
|
mytimermanager.add_timer(std::move(mytimer));
|
|
}
|
|
|
|
struct App{
|
|
sf::RenderWindow mywindow;
|
|
sf::Font myfont;
|
|
sf::Text text;
|
|
TimerManager mytimermanager;
|
|
SortInput input;
|
|
SteppedBsort mystb;
|
|
|
|
sf::Font load_font(const string &filename) {
|
|
sf::Font font;
|
|
if (!font.openFromFile(filename)){
|
|
fprintf(stderr, "failed to load font");
|
|
std::exit(1);
|
|
}
|
|
return font;
|
|
}
|
|
|
|
App(SortInput input):
|
|
mywindow(sf::VideoMode({800,600}), "mywindow"),
|
|
myfont(load_font("assets/NS-R.ttf")),
|
|
text(myfont),
|
|
input(std::move(input)),
|
|
mystb(this->input)
|
|
{
|
|
text.setFont(myfont);
|
|
text.setString("Hello world");
|
|
text.setCharacterSize(24);
|
|
text.setFillColor(sf::Color::Red);
|
|
|
|
setupsorttimers(mytimermanager, mystb);
|
|
}
|
|
|
|
void run(){
|
|
//set up ui
|
|
while (mywindow.isOpen()){
|
|
while (const optional event = mywindow.pollEvent()){
|
|
if (event->is<sf::Event::Closed>())
|
|
mywindow.close();
|
|
}
|
|
|
|
mywindow.clear(sf::Color::Black);
|
|
mywindow.draw(text);
|
|
text.setString(arraytostr(input));
|
|
|
|
mytimermanager.update_timers();
|
|
|
|
displaynumbers(input.values);
|
|
|
|
mywindow.display();
|
|
this_thread::sleep_for(milliseconds(250));
|
|
}
|
|
}
|
|
};
|
|
|
|
int main() {
|
|
SortInput myinput("arr1", dataprovider());
|
|
App myapp(myinput);
|
|
myapp.run();
|
|
}
|