Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if 10
- #include <SFML/Graphics.hpp>
- #include <iostream>
- #include <vector>
- #include "Constants.hpp"
- #include "Node.hpp"
- int main() {
- sf::RenderWindow window(sf::VideoMode(Constants::Width, Constants::Height), "InterSchem", sf::Style::Close);
- window.setVerticalSyncEnabled(true);
- sf::Font font;
- if (!font.loadFromFile("Fonts\\Poppins\\Poppins-Regular.ttf")) {
- std::cout << "Could not load the font\n";
- exit(1);
- }
- std::vector<Node*> nodes;
- nodes.clear();
- nodes.push_back(new Node(Constants::StartNode, font));
- nodes.push_back(new Node(Constants::AssignNode, font));
- nodes.push_back(new Node(Constants::ConditionalNode, font));
- nodes.push_back(new Node(Constants::OutputNode, font));
- nodes.push_back(new Node(Constants::StopNode, font));
- nodes[0]->setNodeCoordonates(sf::Vector2f{80, 50});
- nodes[1]->setNodeCoordonates(sf::Vector2f{80, 100});
- nodes[2]->setNodeCoordonates(sf::Vector2f{80, 150});
- nodes[3]->setNodeCoordonates(sf::Vector2f{80, 200});
- nodes[4]->setNodeCoordonates(sf::Vector2f{80, 250});
- nodes[0]->setTextString("Start");
- nodes[1]->setTextString("Assign");
- nodes[2]->setTextString("If");
- nodes[3]->setTextString("Output");
- nodes[4]->setTextString("Stop");
- while (window.isOpen()) {
- sf::Event event;
- while (window.pollEvent(event)) {
- switch (event.type) {
- case sf::Event::Closed: // window closed
- window.close();
- break;
- case sf::Event::TextEntered: // key pressed
- std::cout << char(event.text.unicode);
- break;
- // we don't process other types of events
- default:
- break;
- }
- }
- window.clear(sf::Color(255, 128, 0, 100));
- for(std::size_t index = 0; index < nodes.size(); ++index) {
- window.draw(nodes[index]->getShape());
- window.draw(nodes[index]->text);
- // window.draw(nodes[index]->hitbox); // Pentru debug
- }
- window.display();
- }
- return 0;
- }
- #else
- #include <SFML/Graphics.hpp>
- #include <bits/stdc++.h>
- #define WindowHeight 720
- #define WindowWidth 1280
- using namespace sf;
- using namespace std;
- bool isInside(Vector2f MousePos, RectangleShape q)
- {
- Vector2f qOrigin = q.getPosition();
- Vector2f qSize = q.getSize();
- Vector2f susStanga = qOrigin;
- Vector2f josDreapta = qOrigin;
- susStanga.x -= qSize.x / 2;
- susStanga.y -= qSize.y / 2;
- josDreapta.x += qSize.x / 2;
- josDreapta.y += qSize.y / 2;
- cout << MousePos.x << ' ' << MousePos.y << '\n';
- cout << susStanga.x << ' ' << susStanga.y << '\n';
- cout << josDreapta.x << ' ' << josDreapta.y << '\n';
- cout << "\n\n";
- if(josDreapta.x >= MousePos.x && MousePos.x >= susStanga.x &&
- josDreapta.y >= MousePos.y && MousePos.y >= susStanga.y)
- {
- cout << "GOOD\n";
- return 1;
- }
- return 0;
- }
- void adauga_nod(vector <RectangleShape> &D)
- {
- RectangleShape patrat2(Vector2f(100.0f,100.0f));
- patrat2.setFillColor(Color::Green);
- patrat2.setOrigin(50.0f, 50.0f);
- patrat2.setPosition(200.0f, 200.f);
- D.push_back(patrat2);
- }
- int main()
- {
- RenderWindow window(VideoMode(WindowWidth,WindowHeight), "Interschem", Style::Close | Style::Titlebar);
- RectangleShape patrat(Vector2f(100.0f,100.0f));
- patrat.setFillColor(Color::Red);
- patrat.setOrigin(50.0f, 50.0f);
- patrat.setPosition(550.0f, 500.0f);
- RectangleShape workbench(Vector2f(1100.0f,900.0f));
- workbench.setFillColor(Color(59,71,57,255));
- workbench.setOrigin(0.0f, 0.0f);
- workbench.setPosition(125.0f, 0.0f);
- RectangleShape button(Vector2f(125.0f,50.0f));
- button.setFillColor(Color::Blue);
- button.setOrigin(62.5f, 25.0f);
- button.setPosition(62.5f, 75.0f);
- vector <RectangleShape> D;
- D.push_back(patrat);
- /*
- */
- Font font;
- font.loadFromFile("Fonts\\Poppins\\Poppins-Regular.ttf");
- Text text;
- text.setFont(font);
- text.setString("Adauga Nod");
- text.setCharacterSize(18);
- text.setFillColor(Color::White);
- text.setPosition(5.0f, 58.0f);
- bool hold = false;
- Vector2i oldPos;
- int target = -1;
- int emptyRectangle = -1;
- while (window.isOpen())
- {
- Event evnt;
- while (window.pollEvent(evnt))
- {
- if(evnt.type == Event::Closed)
- {
- window.close();
- }
- else if(evnt.type == Event::Resized)
- {
- cout << evnt.size.width << ' ' << evnt.size.width << '\n';
- }
- else if(evnt.type == Event::MouseButtonPressed)
- {
- if(evnt.mouseButton.button == Mouse::Left)
- {
- hold = true;
- oldPos = Mouse::getPosition(window);
- Vector2f pos;
- pos.x = static_cast<float>(oldPos.x);
- pos.y = static_cast<float>(oldPos.y);
- for(int i = 0; i < D.size(); ++i)
- if(isInside(pos, D[i]))
- {
- target = i;
- break;
- }
- if(isInside(pos, button))
- {
- adauga_nod(D);
- }
- }
- else if(evnt.mouseButton.button == Mouse::Right)
- {
- oldPos = Mouse::getPosition(window);
- Vector2f pos;
- pos.x = static_cast<float>(oldPos.x);
- pos.y = static_cast<float>(oldPos.y);
- bool deletee = 0;
- for(int i = 0; i < D.size(); ++i)
- if(isInside(pos, D[i]))
- {
- swap(D[i], D[D.size()-1]);
- deletee = 1;
- break;
- }
- if(deletee)
- D.pop_back();
- }
- }
- /*
- else if(hold && evnt.type == Event::MouseMoved)
- {
- cout << "M AM MUTAT\n";
- if(D[target].getFillColor() == Color::Red)
- cout << "RED" << '\n';
- else if(D[target].getFillColor() == Color::Green)
- cout << "GREEN" << '\n';
- Vector2i pozitieMouse = Mouse::getPosition(window);
- D[target].setPosition(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
- }
- */
- else if(evnt.type == Event::MouseButtonReleased)
- {
- target = -1;
- hold = false;
- }
- }
- if(hold && target != -1)
- {
- Vector2i pozitieMouse = Mouse::getPosition(window);
- D[target].setPosition(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
- //D[target].setOrigin(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
- }
- /*
- if(Mouse::isButtonPressed(Mouse::Left))
- {
- Vector2i pozitieMouse = Mouse::getPosition(window);
- patrat.setPosition(static_cast<float>(pozitieMouse.x), static_cast<float>(pozitieMouse.y));
- }
- */
- window.clear();
- window.draw(workbench);
- for(auto it : D)
- window.draw(it);
- window.draw(button);
- window.draw(text);
- window.display();
- }
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement