Advertisement
halexandru11

main.cpp

Dec 7th, 2021
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.25 KB | None | 0 0
  1. #if 10
  2.  
  3. #include <SFML/Graphics.hpp>
  4.  
  5. #include <iostream>
  6. #include <vector>
  7.  
  8. #include "Constants.hpp"
  9. #include "Node.hpp"
  10.  
  11. int main() {
  12.     sf::RenderWindow window(sf::VideoMode(Constants::Width, Constants::Height), "InterSchem", sf::Style::Close);
  13.     window.setVerticalSyncEnabled(true);
  14.  
  15.     std::vector<Node*> nodes;
  16.     nodes.clear();
  17.     nodes.push_back(new Node(Constants::StartNode));
  18.     nodes.push_back(new Node(Constants::AssignNode));
  19.     nodes.push_back(new Node(Constants::ConditionalNode));
  20.     nodes.push_back(new Node(Constants::StopNode));
  21.  
  22.     nodes[0]->setCoordonates(sf::Vector2f{80,  50});
  23.     nodes[1]->setCoordonates(sf::Vector2f{80, 100});
  24.     nodes[2]->setCoordonates(sf::Vector2f{80, 150});
  25.     nodes[3]->setCoordonates(sf::Vector2f{80, 200});
  26. //
  27. //    Node node(Constants::StopNode);
  28. //    node.setCoordonates(sf::Vector2f{70, 50});
  29.  
  30.     while (window.isOpen()) {
  31.  
  32.         sf::Event event;
  33.         while (window.pollEvent(event)) {
  34.             switch (event.type) {
  35.                 case sf::Event::Closed:  // window closed
  36.                     window.close();
  37.                     break;
  38.                 case sf::Event::TextEntered: // key pressed
  39.                     std::cout << char(event.text.unicode);
  40.                     break;
  41.  
  42.                 // we don't process other types of events
  43.                 default:
  44.                     break;
  45.             }
  46.         }
  47.  
  48.         window.clear(sf::Color(255, 128, 0, 100));
  49.  
  50.         for(std::size_t index = 0; index < nodes.size(); ++index) {
  51.             window.draw(nodes[index]->getShape());
  52.             window.draw(nodes[index]->hitbox);
  53.         }
  54.         window.display();
  55.     }
  56.  
  57.     return 0;
  58. }
  59.  
  60. #else
  61.  
  62. #include <SFML/Graphics.hpp>
  63. #include <bits/stdc++.h>
  64. #define WindowHeight 900
  65. #define WindowWidth 1600
  66. using namespace sf;
  67. using namespace std;
  68.  
  69. bool isInside(Vector2f MousePos, RectangleShape q)
  70. {
  71.     Vector2f qOrigin = q.getPosition();
  72.     Vector2f qSize = q.getSize();
  73.     Vector2f susStanga = qOrigin;
  74.     Vector2f josDreapta = qOrigin;
  75.     susStanga.x -= qSize.x / 2;
  76.     susStanga.y -= qSize.y / 2;
  77.     josDreapta.x += qSize.x / 2;
  78.     josDreapta.y += qSize.y / 2;
  79.     cout << MousePos.x << ' ' << MousePos.y << '\n';
  80.     cout << susStanga.x << ' ' << susStanga.y << '\n';
  81.     cout << josDreapta.x << ' ' << josDreapta.y << '\n';
  82.     cout << "\n\n";
  83.     if(josDreapta.x >= MousePos.x && MousePos.x >= susStanga.x &&
  84.         josDreapta.y >= MousePos.y && MousePos.y >= susStanga.y)
  85.         {
  86.             cout << "GOOD\n";
  87.             return 1;
  88.         }
  89.     return 0;
  90. }
  91.  
  92. void adauga_nod(vector <RectangleShape> &D)
  93. {
  94.     RectangleShape patrat2(Vector2f(100.0f,100.0f));
  95.     patrat2.setFillColor(Color::Green);
  96.     patrat2.setOrigin(50.0f, 50.0f);
  97.     patrat2.setPosition(200.0f, 200.f);
  98.     D.push_back(patrat2);
  99. }
  100. int main()
  101. {
  102.     RenderWindow window(VideoMode(WindowWidth,WindowHeight), "Interschem", Style::Close | Style::Titlebar);
  103.     RectangleShape patrat(Vector2f(100.0f,100.0f));
  104.     patrat.setFillColor(Color::Red);
  105.     patrat.setOrigin(50.0f, 50.0f);
  106.     patrat.setPosition(550.0f, 500.0f);
  107.  
  108.     RectangleShape workbench(Vector2f(1100.0f,900.0f));
  109.     workbench.setFillColor(Color(59,71,57,255));
  110.     workbench.setOrigin(0.0f, 0.0f);
  111.     workbench.setPosition(125.0f, 0.0f);
  112.  
  113.  
  114.     RectangleShape button(Vector2f(125.0f,50.0f));
  115.     button.setFillColor(Color::Blue);
  116.     button.setOrigin(62.5f, 25.0f);
  117.     button.setPosition(62.5f, 75.0f);
  118.  
  119.     vector <RectangleShape> D;
  120.     D.push_back(patrat);
  121.     /*
  122.     */
  123.  
  124.     Font font;
  125.     font.loadFromFile("arial.ttf");
  126.     Text text;
  127.     text.setFont(font);
  128.     text.setString("Adauga Nod");
  129.     text.setCharacterSize(20);
  130.     text.setFillColor(Color::White);
  131.     text.setPosition(5.0f, 58.0f);
  132.     bool hold = false;
  133.     Vector2i oldPos;
  134.     int target = -1;
  135.     int emptyRectangle = -1;
  136.     while (window.isOpen())
  137.     {
  138.         Event evnt;
  139.         while (window.pollEvent(evnt))
  140.         {
  141.             if(evnt.type == Event::Closed)
  142.             {
  143.                 window.close();
  144.             }
  145.             else if(evnt.type == Event::Resized)
  146.             {
  147.                 cout << evnt.size.width << ' ' << evnt.size.width << '\n';
  148.             }
  149.             else if(evnt.type == Event::MouseButtonPressed)
  150.             {
  151.                 if(evnt.mouseButton.button == Mouse::Left)
  152.                 {
  153.                     hold = true;
  154.                     oldPos = Mouse::getPosition(window);
  155.                     Vector2f pos;
  156.                     pos.x = static_cast<float>(oldPos.x);
  157.                     pos.y = static_cast<float>(oldPos.y);
  158.                     for(int i = 0; i < D.size(); ++i)
  159.                         if(isInside(pos, D[i]))
  160.                         {
  161.                             target = i;
  162.                             break;
  163.                         }
  164.                     if(isInside(pos, button))
  165.                     {
  166.                         adauga_nod(D);
  167.                     }
  168.                 }
  169.                 else if(evnt.mouseButton.button == Mouse::Right)
  170.                 {
  171.                     oldPos = Mouse::getPosition(window);
  172.                     Vector2f pos;
  173.                     pos.x = static_cast<float>(oldPos.x);
  174.                     pos.y = static_cast<float>(oldPos.y);
  175.                     bool deletee = 0;
  176.                     for(int i = 0; i < D.size(); ++i)
  177.                         if(isInside(pos, D[i]))
  178.                         {
  179.                             swap(D[i], D[D.size()-1]);
  180.                             deletee = 1;
  181.                             break;
  182.                         }
  183.                     if(deletee)
  184.                         D.pop_back();
  185.                 }
  186.             }
  187.             /*
  188.             else if(hold && evnt.type == Event::MouseMoved)
  189.             {
  190.                 cout << "M AM MUTAT\n";
  191.                 if(D[target].getFillColor() == Color::Red)
  192.                     cout << "RED" << '\n';
  193.                 else if(D[target].getFillColor() == Color::Green)
  194.                     cout << "GREEN" << '\n';
  195.                 Vector2i pozitieMouse = Mouse::getPosition(window);
  196.                 D[target].setPosition(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
  197.             }
  198.             */
  199.             else if(evnt.type == Event::MouseButtonReleased)
  200.             {
  201.                 target = -1;
  202.                 hold = false;
  203.             }
  204.         }
  205.         if(hold && target != -1)
  206.         {
  207.             Vector2i pozitieMouse = Mouse::getPosition(window);
  208.             D[target].setPosition(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
  209.             //D[target].setOrigin(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
  210.         }
  211.         /*
  212.         if(Mouse::isButtonPressed(Mouse::Left))
  213.         {
  214.             Vector2i pozitieMouse = Mouse::getPosition(window);
  215.             patrat.setPosition(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
  216.         }
  217.         */
  218.         window.clear();
  219.         window.draw(workbench);
  220.         for(auto it : D)
  221.             window.draw(it);
  222.         window.draw(button);
  223.         window.draw(text);
  224.         window.display();
  225.     }
  226.  
  227.     return 0;
  228. }
  229.  
  230.  
  231.  
  232. #endif
  233.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement