daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Jun 22nd, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void main()
  2. {
  3.     sf::RenderWindow window(sf::VideoMode(800, 600), "title");
  4.     window.setVerticalSyncEnabled(true);
  5.  
  6.     bool dragging(false);
  7.     sf::Vector2f click_pos;
  8.     sf::RectangleShape shape;
  9.     shape.setOutlineThickness(1);
  10.     shape.setOutlineColor(sf::Color(51, 153, 255));
  11.     shape.setFillColor(sf::Color(51, 153, 255, 100));
  12.  
  13.     while (window.isOpen())
  14.     {
  15.         sf::Event event;
  16.         while (window.pollEvent(event))
  17.         {
  18.             if (event.type == sf::Event::EventType::Closed)
  19.             {
  20.                 window.close();
  21.             }
  22.             else if (event.type == sf::Event::EventType::MouseMoved)
  23.             {
  24.                 if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
  25.                 {
  26.                     shape.setSize(sf::Vector2f(sf::Mouse::getPosition(window).x - click_pos.x, sf::Mouse::getPosition(window).y - click_pos.y));
  27.                 }
  28.             }
  29.             else if (event.type == sf::Event::EventType::MouseButtonPressed)
  30.             {
  31.                 if (event.key.code == sf::Mouse::Button::Left)
  32.                 {
  33.                     click_pos = sf::Vector2f(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);
  34.                     shape.setPosition(click_pos);
  35.  
  36.                     dragging = true;
  37.                 }
  38.             }
  39.             else if (event.type == sf::Event::EventType::MouseButtonReleased)
  40.             {
  41.                 if (event.key.code == sf::Mouse::Button::Left && dragging)
  42.                 {
  43.                     shape.setSize(sf::Vector2f(0, 0));
  44.  
  45.                     dragging = false;
  46.                 }
  47.             }
  48.         }
  49.  
  50.         window.clear(sf::Color::White);
  51.  
  52.         window.draw(shape);
  53.  
  54.         window.display();
  55.     }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top