Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "function.hpp"
- vector<vector<string> > getData(){
- string line;
- string word;
- int nbarg = 0;
- vector<vector<string> > data;
- ifstream file("dessin.txt", ios::in);
- if(file.is_open()){
- while(getline(file, line)){
- if(line.size() > 0){
- vector<string> buffer;
- stringstream s(line);
- while(s >> word){
- nbarg++;
- buffer.push_back(word);
- }
- data.push_back(buffer);
- }
- }
- }
- else {
- cerr << "Fichier non trouvé !" << endl;
- }
- file.close();
- return data;
- };
- int useData(WindowParameters & options, Cursor & cursor, vector<vector<string>> & data, int begin_line){
- for(unsigned int i = begin_line; i < data.size(); i++){
- //cout << i << endl;
- if(data[i][0] == "start_repeat"){
- int repeat;
- if(data[i].size() == 1){
- repeat = 2;
- }
- else{
- repeat = stoi(data[i][1]);
- }
- int count = 0;
- for(int j = 0; j < repeat; j++){
- count = useData(options, cursor, data, i+1);
- }
- //cout << i << " " << count << endl;
- i = count + 1;
- //cout << i << " " << count << endl;
- }
- if(data[i][0] == "end_repeat"){
- //cout << i << endl;
- return i;
- }
- if(data[i][0] == "go"){
- if(data[i].size() == 1){
- cursor.goForward(100, options.window);
- }
- else{
- cursor.goForward(stoi(data[i][1]), options.window);
- }
- }
- if(data[i][0] == "rotate"){
- float orientation = cursor.getOrientation();
- if(data[i].size() == 1){
- cursor.setOrientation(orientation + 90);
- }
- else{
- cursor.setOrientation(orientation + stof(data[i][1]));
- }
- }
- if(data[i][0] == "move_cursor"){
- cursor.setX(cursor.getX() + stoi(data[i][1]));
- cursor.setY(cursor.getY() + stoi(data[i][2]));
- //cout << "changed" << endl;
- }
- if(data[i][0] == "set_position"){
- cursor.setX(stoi(data[i][1]));
- cursor.setY(stoi(data[i][2]));
- }
- if(data[i][0] == "set_orientation"){
- cursor.setOrientation(stof(data[i][1]));
- }
- if(data[i][0] == "set_thickness"){
- if(data[i].size() == 1){
- cursor.setWidth(1);
- }
- else{
- cursor.setWidth(stoi(data[i][1]));
- }
- }
- if(data[i][0] == "circle"){
- if(data[i].size() == 1){
- cursor.makeArc(options.window, 100, 360);
- }
- else{
- cursor.makeArc(options.window, stoi(data[i][1]), 360);
- }
- }
- if(data[i][0] == "arc"){
- cursor.makeArc(options.window, stoi(data[i][1]), stof(data[i][2]));
- }
- if(data[i][0] == "line_color"){
- cursor.setColor(stoi(data[i][1]), stoi(data[i][2]), stoi(data[i][3]));
- }
- if(data[i][0] == "name"){
- options.setName(data[i][1]);
- }
- if(data[i][0] == "font_color"){
- options.setColor(stoi(data[i][1]), stoi(data[i][2]), stoi(data[i][3]));
- }
- }
- return 0;
- }
- void windowPrint(WindowParameters & options, Cursor & cursor, vector<vector<string>> & data){
- options.setColor(255,255,255);
- useData(options, cursor, data, 0);
- options.window.display();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement