Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. #include "function.hpp"
  2.  
  3.  
  4. vector<vector<string> > getData(){
  5. string line;
  6. string word;
  7. int nbarg = 0;
  8. vector<vector<string> > data;
  9.  
  10.  
  11. ifstream file("dessin.txt", ios::in);
  12.  
  13. if(file.is_open()){
  14. while(getline(file, line)){
  15. if(line.size() > 0){
  16. vector<string> buffer;
  17. stringstream s(line);
  18. while(s >> word){
  19. nbarg++;
  20. buffer.push_back(word);
  21. }
  22. data.push_back(buffer);
  23. }
  24. }
  25. }
  26. else {
  27. cerr << "Fichier non trouvé !" << endl;
  28. }
  29. file.close();
  30. return data;
  31. };
  32.  
  33.  
  34. int useData(WindowParameters & options, Cursor & cursor, vector<vector<string>> & data, int begin_line){
  35. for(unsigned int i = begin_line; i < data.size(); i++){
  36. //cout << i << endl;
  37. if(data[i][0] == "start_repeat"){
  38. int repeat;
  39. if(data[i].size() == 1){
  40. repeat = 2;
  41. }
  42. else{
  43. repeat = stoi(data[i][1]);
  44. }
  45.  
  46. int count = 0;
  47. for(int j = 0; j < repeat; j++){
  48. count = useData(options, cursor, data, i+1);
  49. }
  50. //cout << i << " " << count << endl;
  51. i = count + 1;
  52. //cout << i << " " << count << endl;
  53. }
  54. if(data[i][0] == "end_repeat"){
  55. //cout << i << endl;
  56. return i;
  57. }
  58. if(data[i][0] == "go"){
  59. if(data[i].size() == 1){
  60. cursor.goForward(100, options.window);
  61. }
  62. else{
  63. cursor.goForward(stoi(data[i][1]), options.window);
  64. }
  65. }
  66. if(data[i][0] == "rotate"){
  67. float orientation = cursor.getOrientation();
  68. if(data[i].size() == 1){
  69. cursor.setOrientation(orientation + 90);
  70. }
  71. else{
  72. cursor.setOrientation(orientation + stof(data[i][1]));
  73. }
  74.  
  75. }
  76. if(data[i][0] == "move_cursor"){
  77. cursor.setX(cursor.getX() + stoi(data[i][1]));
  78. cursor.setY(cursor.getY() + stoi(data[i][2]));
  79. //cout << "changed" << endl;
  80. }
  81. if(data[i][0] == "set_position"){
  82. cursor.setX(stoi(data[i][1]));
  83. cursor.setY(stoi(data[i][2]));
  84. }
  85. if(data[i][0] == "set_orientation"){
  86. cursor.setOrientation(stof(data[i][1]));
  87. }
  88. if(data[i][0] == "set_thickness"){
  89. if(data[i].size() == 1){
  90. cursor.setWidth(1);
  91. }
  92. else{
  93. cursor.setWidth(stoi(data[i][1]));
  94. }
  95. }
  96. if(data[i][0] == "circle"){
  97. if(data[i].size() == 1){
  98. cursor.makeArc(options.window, 100, 360);
  99. }
  100. else{
  101. cursor.makeArc(options.window, stoi(data[i][1]), 360);
  102. }
  103. }
  104. if(data[i][0] == "arc"){
  105. cursor.makeArc(options.window, stoi(data[i][1]), stof(data[i][2]));
  106. }
  107. if(data[i][0] == "line_color"){
  108. cursor.setColor(stoi(data[i][1]), stoi(data[i][2]), stoi(data[i][3]));
  109. }
  110. if(data[i][0] == "name"){
  111. options.setName(data[i][1]);
  112. }
  113. if(data[i][0] == "font_color"){
  114. options.setColor(stoi(data[i][1]), stoi(data[i][2]), stoi(data[i][3]));
  115. }
  116. }
  117. return 0;
  118. }
  119.  
  120.  
  121.  
  122. void windowPrint(WindowParameters & options, Cursor & cursor, vector<vector<string>> & data){
  123. options.setColor(255,255,255);
  124. useData(options, cursor, data, 0);
  125. options.window.display();
  126.  
  127. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement