Advertisement
0110101001

pastebinNG1

Apr 9th, 2020
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <SFML/Graphics.hpp>
  3.  
  4. int main()
  5. {
  6.     sf::RenderWindow window(sf::VideoMode(700, 700), "sfml work", sf::Style::None | sf::Style::Close);
  7.     sf::View vue;
  8.     sf::RectangleShape shape(sf::Vector2f(150, 150));
  9.     sf::Event eventSF;
  10.     shape.setFillColor(sf::Color::Blue);
  11.     shape.setPosition(350, 350);
  12.     while (window.isOpen())
  13.     {
  14.         while (window.pollEvent(eventSF))
  15.         {
  16.             if (eventSF.type == sf::Event::Closed)
  17.             {
  18.                 window.close();
  19.                 //exit(0);
  20.             }
  21.  
  22.             if (eventSF.type == sf::Event::MouseButtonPressed)
  23.             {
  24.                 if (shape.getGlobalBounds().contains(sf::Vector2f(sf::Mouse::getPosition(window))))
  25.                 {
  26.                     std::cout << "Contain\n";
  27.                 }
  28.                 else
  29.                 {
  30.                     std::cout << "non\n";
  31.                     std::cout << sf::Mouse::getPosition(window).x << " // " << sf::Mouse::getPosition(window).y << "\n";
  32.                     std::cout << shape.getGlobalBounds().getPosition().x << " // " << shape.getGlobalBounds().getPosition().y << "\n";
  33.                     std::cout << shape.getPosition().x                   << " // " << shape.getPosition().y                   << "\n";
  34.                 }
  35.             }
  36.         }
  37.  
  38.         window.clear();
  39.         window.setView(vue);
  40.         window.draw(shape);
  41.         window.display();
  42.     }
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement