Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Simple Paint Program Example  (Read 6883 times)

0 Members and 1 Guest are viewing this topic.

mdb

  • Newbie
  • *
  • Posts: 1
    • View Profile
Simple Paint Program Example
« on: May 20, 2013, 01:42:52 am »
#include <SFML/Graphics.hpp>
#include <vector>

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
   std::vector <sf::Vertex> lines;
   sf::Texture texture;
   sf::Sprite sprite;
   texture.create(800,600);

   int mousedown = 0;
    // run the program as long as the window is open
   window.setFramerateLimit(30);

    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();   
         else if ((event.type == sf::Event::MouseMoved) && (mousedown == 1))
         {
            lines.push_back(sf::Vertex(sf::Vector2f::Vector2(sf::Mouse::getPosition(window))));
         }
         else if (event.type == sf::Event::MouseButtonPressed)
         {
            mousedown = 1;
         }
         else if (event.type == sf::Event::MouseButtonReleased)
         {
            mousedown = 0;
            texture.update(window);
            lines.clear();
         }
      }

        window.clear(sf::Color::Black);

         window.draw(sprite);

      window.draw(&lines[0], lines.size(), sf::LinesStrip);

      sprite.setTexture(texture);
        window.display();   

    }

    return 0;
}

io

  • Jr. Member
  • **
  • Posts: 52
  • z/OS by day, SFML by night
    • View Profile
Re: Simple Paint Program Example
« Reply #1 on: May 20, 2013, 05:02:45 am »
please put code=cpp tags around your source ;], thanks for the share

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Simple Paint Program Example
« Reply #2 on: May 20, 2013, 03:26:53 pm »
A few more words and maybe a screenshot would also never hurt.... ;)

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/