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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Xrey274

Pages: [1] 2
1
General / Making Flood Fill Algorithm more efficient.
« on: February 12, 2020, 02:50:01 pm »
I am working on a Flood Fill Algorithm. Unfortunately I have been having performance issues with said algorithm. It hammers the CPU. It's constantly at 100%(or at least one of the cores is, since the app is single threaded). This is what I have come up with so far:

sf::Image BucketTool::rgbFill(sf::Image& canvas_image, sf::Vector2f origin, sf::Color discriminator)
{
        if(origin.x < 0 || origin.x >= canvas_image.getSize().x || origin.y < 0 || origin.y >= canvas_image.getSize().y)
        {
        return canvas_image;
        }

        if(canvas_image.getPixel(origin.x, origin.y) != discriminator)
        {
                return canvas_image;
        }

        canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);

        ///std::cout<<origin.x<<" "<<origin.y<<std::endl;

        rgbFill(canvas_image, sf::Vector2f(origin.x + 1, origin.y), discriminator);
        rgbFill(canvas_image, sf::Vector2f(origin.x - 1, origin.y), discriminator);
        rgbFill(canvas_image, sf::Vector2f(origin.x, origin.y + 1), discriminator);
        rgbFill(canvas_image, sf::Vector2f(origin.x, origin.y - 1), discriminator);

        canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);
        canvas_image.saveToFile("example.png");

        return canvas_image;
}

2
General / Single line of code breaks program.
« on: October 02, 2019, 09:57:03 pm »
I am having a proble m with a personal project of mine. Whenever I try to remove this line in file "Canvas.cpp" in function draw my program breaks. Nothing is displayed.

File: Canvas.cpp Function: draw() Line: 69
if(!circle.isSelectingSize())
{
    texture.draw(circle); //this line
}
 

Github page for code :https://github.com/Xrey274/Splash/tree/beta

I know it's a big project with many files, but I have removed every trace of the Circle class, even from CMakeLists.txt(meaning it was not even compiled), but no matter what I did this problem persisted. If you are on Linux you can compile it for youself and try it out.

3
General / Interpolation method?
« on: September 04, 2019, 03:42:45 pm »
What would be the best interpolation method to use for drawing a line(with mouse)? I am currently thinking about bezier curve. The line is consists of circle shapes that need to be connected. I have tried by connecting them with a rectangle shape, which works only if your fps is >1000 for the lines to be smooth when curved. So what do you think will work best in this case?

PS: I am not asking for a code, nor guidence on how to implement it, just your opinion on what would be the best in my case.

4
General / RenderTexture offset;
« on: August 25, 2019, 11:10:02 pm »
I am testing out some code where the rendertexture is acting like a canvas to which things are being drawn. One problem is that when I set the position of the sf::Sprite, that has the rendertexture, to the center of the screen there is an offset.

#include <iostream>
#include <SFML/Graphics.hpp>

sf::CircleShape newCircle(sf::Vector2f pos)
{
        sf::CircleShape circle;

        circle.setPosition(pos);
        circle.setRadius(10);
        circle.setOrigin(circle.getRadius(), circle.getRadius());
        circle.setFillColor(sf::Color::Green);

        return circle;
}

int main()
{
        sf::ContextSettings settings;
        settings.antialiasingLevel = 8;

        sf::RenderWindow window(sf::VideoMode(1600, 1200), "RenderTexture", sf::Style::Default, settings);
        sf::RenderTexture canvas;

        canvas.create(800, 600);
        canvas.clear(sf::Color::White);

        sf::Event event;

        std::vector<sf::CircleShape> circles;

        bool isMoving = false;

        while(window.isOpen())
        {
                sf::Vector2f mouseCoords = window.mapPixelToCoords(sf::Mouse::getPosition(window), window.getView());

                while(window.pollEvent(event))
                {
                        switch(event.type)
                        {
                                case sf::Event::Closed:
                                        window.close();

                                        break;
                                case sf::Event::MouseButtonPressed:
                                        isMoving = true;

                                        break;
                                case sf::Event::MouseMoved:
                                        if(isMoving == true)
                                        {
                                                circles.push_back(newCircle(mouseCoords));
                                        }

                                        break;
                                case sf::Event::MouseButtonReleased:
                                        isMoving = false;

                                        circles.clear();
                        }

                        if(event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }

                for(int i = 0; i < circles.size(); ++i)
                {
                        canvas.draw(circles[i]);
                }

                canvas.display();

                window.clear(sf::Color(31, 31, 31));

                sf::Sprite sprite(canvas.getTexture());
                sprite.setPosition(sf::Vector2f(400, 300));
                window.draw(sprite);

                window.display();
        }
}
 
 

5
General / How to convert shape to vertex array.
« on: August 25, 2019, 12:13:28 am »
I'm working on a drawing program and I'm curious how would one go about transforming a (ex.) sf::CircleShape to a vertex array? I've read on various topic on this forum that .draw() calls are quite performance taxing. My line tool is basically a bunch of circle shapes connected with rectanagle shapes, which means a ton of draw calls for a single line.

6
General / Scaling into a canvas.
« on: June 02, 2019, 08:50:53 pm »
I am working on a painting program, and I have been wondering how to make canvases that are bigger(resolution wise) than the window(for ex. 8000 x 6000). Pretty much every painting program does this. My idea for now is just using setScale, but won't that ruin the image resolution?

Edit: To clarify the "canvas" is a renderTexture to which things are drawn to.

7
General / sf::CircleShape getPosition() returns big number
« on: March 31, 2019, 09:17:48 pm »
I've been messing around with interpolation and I've almost reached something that I could call usable and then bam big problem. I first experimented by just interpolating between 2 static points and now I added lines that are draw when the mouse moves. The probem is after a couple of seconds the whole thing crashes and I see that .getPosition() returns numbers with 6 or more digits.

Here's the code:
#include <SFML/Graphics.hpp>
#include <iostream>

int setMaxValue(sf::CircleShape circle, bool& y)
{
    int a = 0;

    if(circle.getPosition().y > circle.getPosition().x)
    {
        a = circle.getPosition().y;
        y = true;
    }
    else
        a = circle.getPosition().x;

    return a;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(1920, 1080), "Test");

    sf::Event event;

    std::vector<sf::CircleShape> circles;

    sf::Vector2f mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window))), oldMouseCoords = mouseCoords;

    bool ended = false, isY = false;
    int maxValue0, maxValue1, maxValue2;

    while(window.isOpen())
    {
        mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window)));

        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }

            if(event.type == sf::Event::MouseMoved)
            {
                sf::CircleShape newCircle;

                newCircle.setRadius(50);
                newCircle.setOrigin(newCircle.getRadius(), newCircle.getRadius());
                newCircle.setPosition(mouseCoords);
                newCircle.setFillColor(sf::Color::Red);

                circles.push_back(newCircle);

                ended = false;
            }
        }

        if(ended == false && circles.size() > 1)
        {
            maxValue0 = setMaxValue(circles[circles.size() - 2], isY);
            maxValue1 = setMaxValue(circles[circles.size() - 1], isY);

            if(maxValue0 > maxValue1)
                maxValue2 = maxValue0 - maxValue1;
            else
                maxValue2 = maxValue1 - maxValue0;

                std::cout<<circles.size()<<std::endl;
                std::cout<<circles[circles.size() - 2].getPosition().x<<" "<<circles[circles.size() - 2].getPosition().y<<std::endl;

            for(int i = 0; i < maxValue2; ++i)
            {
                sf::CircleShape newCircle;

                int x, y;

                if(isY == true)
                {
                    y = circles[circles.size() - 2].getPosition().y + i;
                    x = (((y - circles[circles.size() - 2].getPosition().y) * (circles[circles.size() - 1].getPosition().x - circles[circles.size() - 2].getPosition().x)) / (circles[circles.size() - 1].getPosition().y - circles[circles.size() - 2].getPosition().y)) + circles[circles.size() - 2].getPosition().x;
                }
                else
                {
                    x = circles[circles.size() - 2].getPosition().x + i;
                    y = (((x - circles[circles.size() - 1].getPosition().x) * (circles[circles.size() - 1].getPosition().y - circles[circles.size() - 2].getPosition().y)) / (circles[circles.size() - 1].getPosition().x - circles[circles.size() - 2].getPosition().x)) + circles[circles.size() - 2].getPosition().y;
                }

                sf::Vector2f finalPos(x, y);

                newCircle.setRadius(50);
                newCircle.setOrigin(newCircle.getRadius(), newCircle.getRadius());
                newCircle.setPosition(finalPos);
                newCircle.setFillColor(sf::Color::Red);

                circles.push_back(newCircle);

                if(i == maxValue2 - 1)
                {
                    ended = true;
                }
            }
        }

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

        for(auto i : circles)
        {
            window.draw(i);
        }

        window.display();
    }
}
 

8
Graphics / Is it possible to create a line with circles?
« on: March 23, 2019, 10:52:37 pm »
So i am trying to draw a consistent free line with circles along(sf::CircleShape). It works if I move the mouse slowly, but the circles get big gaps if i move it quickly. I was wondering if it possible to resolve this?

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1920, 1080), "Test");

    sf::Event event;

    std::vector<sf::CircleShape> circles;

    sf::Vector2f mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window)));

    while(window.isOpen())
    {
        mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window)));

        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }

            if(event.type == sf::Event::MouseMoved)
            {
                sf::CircleShape newCircle;

                newCircle.setPosition(mouseCoords);
                newCircle.setRadius(3);
                newCircle.setFillColor(sf::Color::Black);

                circles.push_back(newCircle);
            }
        }
        window.clear(sf::Color::White);

        for(auto i : circles)
        {
            window.draw(i);
        }

        window.display();
    }
}
 

9
General / Accurate globalBounds of circle.
« on: March 18, 2019, 09:50:16 pm »
What I want is for the global bounds to be the same size and shape as the circle. Currently the globalBounds is basically a rectangle. Current code literally just simulates the code of getGlobalBounds function.

#include <iostream>
#include <SFML/Graphics.hpp>

bool calculate(sf::Vector2f pos, sf::Vector2f mouse, int r)
{
    std::cout<<pos.x - mouse.x<<" "<<pos.y - mouse.y <<std::endl;

    if(pos.x - mouse.x >= 0 && pos.x - mouse.x <= r)
    {
        if(pos.y - mouse.y >= 0 && pos.y - mouse.y <= r)
        {
            return true;
        }
        else if(pos.y - mouse.y <= 0 && pos.y - mouse.y >= -r)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else if(pos.x - mouse.x <= 0 && pos.x - mouse.x >= -r)
    {
        if(pos.y - mouse.y <= 0 && pos.y - mouse.y >= -r)
        {
            return true;
        }
        else if(pos.y - mouse.y >= 0 && pos.y - mouse.y <= r)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return 0;
    }
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Test");

    sf::Event event;
    sf::Vector2f mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window)));

    sf::CircleShape circle;
    circle.setRadius(150);
    circle.setPosition(sf::Vector2f(400, 300));
    circle.setFillColor(sf::Color::Blue);
    circle.setOrigin(circle.getRadius(), circle.getRadius());

    while(window.isOpen())
    {
        mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window)));

        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }

            if(event.type == sf::Event::MouseMoved)
            {
                if(calculate(circle.getPosition(), mouseCoords, circle.getRadius()) == true)
                {
                    circle.setFillColor(sf::Color::Red);
                }
                else
                {
                    circle.setFillColor(sf::Color::Blue);
                }
            }
        }

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

        window.draw(circle);

        window.display();
    }
}
 

10
General / Text gets blurry when resizing window.
« on: March 09, 2019, 06:19:57 pm »
Whenever I resize the window the text gets blurred. I even made a "text update" function, but that doesn't seem to matter.

11
General / Texture going down when clicking.
« on: February 28, 2019, 12:22:35 pm »
I made a little project that is supposed to merge with my main one when it is finished, tho I am having problems. Basically the code is supposed to create a window on which you can freely draw. That being said when I click to draw the whole sprite gets moved down a couple of pixels or so.(the line vertexes get saved as a texture which is applied to a sprite and then drawn). The thing is if VideoMode and the texture size are something like 800x600 this doesn't happen, but the moment they are set to 1080p(monitors native resolution) it happens. This is the code :
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>

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;
    sprite.setPosition(0, 0);
    texture.create(800, 600);

    sf::Event event;

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

    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        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))
            {
                sf::Vertex point;
                point.color = sf::Color::Black;
                point.position = sf::Vector2f(sf::Mouse::getPosition(window));

                lines.push_back(point);
            }
            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::White);

        sprite.setTexture(texture);

        window.draw(sprite);

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

        window.display();

    }

    return 0;
}

12
General / For loop in event loop.
« on: February 26, 2019, 09:53:23 pm »
So i'm probably just overlooking something very obvious here, but basically I have a for loop inside the event loop. There's a switch and under the case of left clicking there is a for loop. After the for loop there is an if statement and the program seems to completely ignore the for loop and jumps straight to the if statement.

case sf::Event::MouseButtonPressed:  // the left click case in the switch
                    if(event.mouseButton.button == sf::Mouse::Left)
                    {
                        for(int i = 0; i < circles.size(); i++) //the for loop
                        {
                            if(circles[i].getGlobalBounds().contains(mouseCoords))
                            {
                                Circle newCircle;
                                int radius = circles[i].getCircleRadius();

                                std::cout<<"Hello"<<std::endl;

                                circles.pop_back();

                                newCircle.CreateCircle(placementCoords, radius, r, g, b, 124, 170, 204);

                                circles.push_back(newCircle);
                            }
                        }

                        //if requarments are met a new instance of shapes will be created, then given info(position, color, etc..) and be saved into a vector
                        if(canvas.getGlobalBounds().contains(mouseCoords)) //if statement I was talking about
                        {
                            Circle newCircle;

                            newCircle.CreateCircle(mouseCoords, defaultRadius, 176, 214, 242, 124, 170, 204);

                            circles.push_back(newCircle);

                            placementCoords = mouseCoords;

                            selectingSize = true;
                        }
                    }

13
General / Compiling for Windows
« on: February 24, 2019, 11:13:41 pm »
Currently using Linux(Solus) and Code::Blocks to develop my program and I want to know how to compile it for Windows. It tried renaming the executable .exe(dumb idea I know) and an error popped up on Windows "This app can't run on your pc". So could you please tell me how to do it?

14
Graphics / Circle Shape not updating dynamicly
« on: July 09, 2018, 04:12:32 pm »
I'm working on a small paint like program which for now only can make circles. I am working on a feature, which show what the circle will look like before it's placed. You can move the mouse to shrink or expand the circle preview if you haven't released the right mouse button. It seems to be working, but I have 2 problems:

1. The shape is not dynamicly updating when moving the mouse

2.I need to find a way to calculate the radius of the circle depending on how many pixels the mouse has moved. Is the size measured in pixels?
main.cpp
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include "Shapes.h"
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

constexpr float pi = 3.14;


sf::CircleShape sizeSelection(sf::Vector2f mousePosition, int shapeSize)
{
    sf::CircleShape circle;

    circle.setFillColor(sf::Color(136, 167, 216));
    circle.setPosition(mousePosition);
    circle.setRadius(shapeSize);

    return circle;
}

int main()
{
    std::string versionString = "1.2.2";
    std::string title = "Little Painter " + versionString;


    //window related stuff
    sf::VideoMode screenSize = sf::VideoMode::getDesktopMode();
    sf::RenderWindow window(sf::VideoMode(screenSize.width / 2, screenSize.height / 2), title);
    sf::View defaultView(sf::FloatRect(0.f, 0.f, screenSize.width, screenSize.height));

    window.setView(defaultView);

    window.setFramerateLimit(60);

    sf::Event event;

    //gui elements
    sf::RectangleShape brushTypeGUI(sf::Vector2f(200, 30)), dotColorGUI(sf::Vector2f(200, 30)), canvas(sf::Vector2f(1020, 800)), clearCanvasGUI(sf::Vector2f(200, 30)), changeBrushGUI(sf::Vector2f(200, 30));

    //gui setters
    brushTypeGUI.setPosition(0, 0);
    dotColorGUI.setPosition(202, 0);
    clearCanvasGUI.setPosition(404, 0);
    canvas.setPosition(120 ,112);

    //text elements
    sf::Text brushTypeText, dotColorText, clearCanvasText;
    sf::Font font;

    //text setters
    brushTypeText.setString("Change Brush");
    brushTypeText.setCharacterSize(24);
    brushTypeText.setFillColor(sf::Color::White);
    brushTypeText.setFont(font);
    brushTypeText.setPosition(25, 0);

    dotColorText.setString("Dot Color");
    dotColorText.setCharacterSize(24);
    dotColorText.setFillColor(sf::Color::White);
    dotColorText.setFont(font);
    dotColorText.setPosition(252, 1);

    clearCanvasText.setString("Clear Canvas");
    clearCanvasText.setCharacterSize(24);
    clearCanvasText.setFillColor(sf::Color::White);
    clearCanvasText.setFont(font);
    clearCanvasText.setPosition(433, 1);

    font.loadFromFile("expressway rg.ttf");

    //time
    sf::Time sleepTime = sf::milliseconds(10);

    //ranodom stuff
    std::vector<sf::CircleShape> circles;
    std::vector<sf::RectangleShape> rectangles;

    sf::VertexArray lines(sf::LinesStrip, 4);

    int defaultSize = 15, r = 0, g = 100, b = 0;
    bool selectingSize = false;

    sf::Vector2i oldPosition = sf::Mouse::getPosition(window);

    Shapes brush;

    brush.setBrushType("circle");

    while(window.isOpen() == true)
    {

        while(window.pollEvent(event))
        {
            //gui setters
            brushTypeGUI.setFillColor(sf::Color(33, 33, 33));
            dotColorGUI.setFillColor(sf::Color(33, 33, 33));
            clearCanvasGUI.setFillColor(sf::Color(33, 33, 33));

            //mouse position
            sf::Vector2i mousePosition = sf::Mouse::getPosition(window);
            sf::Vector2f mouseCoords = window.mapPixelToCoords(mousePosition);

            //setting bounds of gui elements
            sf::FloatRect dotColorGUIBounds = dotColorGUI.getGlobalBounds();
            sf::FloatRect clearCanvasGUIBounds = clearCanvasGUI.getGlobalBounds();
            sf::FloatRect canvasBounds = canvas.getGlobalBounds();

            int r;

            if(event.type == sf::Event::Closed)
            {
                window.close();
            }

            if(event.type == sf::Event::Resized)
            {
                window.setView(defaultView);
            }

            if(event.type == sf::Event::MouseButtonPressed)
            {
                if(canvasBounds.contains(mouseCoords))
                {
                    //if reset the position of lastPosition
                    if(oldPosition == sf::Vector2i(0, 0))
                    {
                        oldPosition = mousePosition;
                    }

                    //check if mouse has moved since the begging of the size selection
                    if(oldPosition != mousePosition)
                    {
                        //try to calculate the radius of a
                        r = ((oldPosition.x - mousePosition.x) - (oldPosition.y - mousePosition.y)) / 2;
                        std::cout<<r<<" "<<mousePosition.x<<" "<<mousePosition.y<<std::endl;

                        circles.pop_back();

                        //set the oldPosition to current mousePosition
                        oldPosition = mousePosition;

                        circles.push_back(sizeSelection(mouseCoords, r));
                    }
                    //if mouse hasn't moved set the size to the defaultSize
                    else
                    {
                        circles.push_back(sizeSelection(mouseCoords, defaultSize));
                    }

                    selectingSize = true;
                }
            }

            if(event.type == sf::Event::MouseButtonReleased && selectingSize == true)
            {
                if(event.mouseButton.button == sf::Mouse::Right)
                {
                    if(canvasBounds.contains(mouseCoords))
                    {
                        //remove the size Selection circle
                        circles.pop_back();

                        //set oldPosition to 0, 0 so it can be reset
                        oldPosition = (sf::Vector2i(0, 0));

                        //go out of selectingSize
                        selectingSize = false;

                        brush.setData(mouseCoords, defaultSize, r, g, b);

                        switch(brush.getBrushType())
                        {
                            case Shapes::Circle:
                                    circles.push_back(brush.drawCircle());
                                    break;
                            case Shapes::Rectangle:
                                    rectangles.push_back(brush.drawRectangle());
                                    break;
                        }
                    }

                }

            }

            if(dotColorGUIBounds.contains(mouseCoords))
            {
                dotColorGUI.setFillColor(sf::Color(40, 50, 95));

                if(event.type == sf::Event::MouseButtonPressed)
                {
                    if(event.mouseButton.button == sf::Mouse::Left)
                    {
                        r = rand() % 255;
                        g = rand() % 255;
                        b = rand() % 255;
                    }
                }
            }

            if(clearCanvasGUIBounds.contains(mouseCoords))
            {
                clearCanvasGUI.setFillColor(sf::Color(40, 50, 95));

                if(event.type == sf::Event::MouseButtonPressed && event.key.code == sf::Mouse::Left)
                {
                    circles.clear();
                }
            }

            if(event.type == sf::Event::MouseWheelMoved)
            {
                defaultSize += (event.mouseWheel.delta + 0.8);
            }
        }
        window.clear(sf::Color(61,61,61));

        window.draw(brushTypeGUI);
        window.draw(brushTypeText);

        window.draw(dotColorGUI);
        window.draw(dotColorText);

        window.draw(clearCanvasGUI);
        window.draw(clearCanvasText);

        window.draw(canvas);
        for(const auto it : circles)
        {
            window.draw(it);
        }

        window.draw(lines);
        window.display();
    }
}

 

15
General / Dot going out of the canvas.
« on: June 02, 2018, 10:31:41 pm »
I am making a little drawing program, which for now can only place dots. My problem is when i click on the edge of the canvas it draws it outside of it. Also the when i resize the window everything goes out of proportion.

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

sf::CircleShape drawDot(sf::Vector2f position, unsigned int dotSize, unsigned int r, unsigned int g, unsigned int b)
{
    sf::CircleShape dot;

    dot.setRadius(dotSize);
    dot.setFillColor(sf::Color(r, g, b));
    dot.setPosition(position);

    return dot;
}

int main()
{
    sf::VideoMode screenSize = sf::VideoMode::getDesktopMode();
    sf::RenderWindow window(screenSize, "Little Painter");

    window.setFramerateLimit(60);

    sf::Event event;
    sf::Vector2f dotPosition;
    sf::Mouse mouse;
    sf::RectangleShape menuGUI(sf::Vector2f(200, 30)), canvas(sf::Vector2f(1020, 800));
    sf::Text guiText;
    sf::Font font;

    font.loadFromFile("expressway rg.ttf");

    guiText.setString("Dot Color");
    guiText.setCharacterSize(24);
    guiText.setFillColor(sf::Color::White);
    guiText.setFont(font);
    guiText.setPosition(44, 1.1f);



    canvas.setPosition(120 ,112);

    vector<sf::CircleShape> circles;

    int defaultSize = 15, r = 0, g = 100, b = 0;;

    while(window.isOpen() == true)
    {

        while(window.pollEvent(event))
        {

            menuGUI.setFillColor(sf::Color(33, 33, 33));

            sf::Vector2i mousePos = sf::Mouse::getPosition(window);
            sf::Vector2f mouseInBox = window.mapPixelToCoords(mousePos);

            sf::FloatRect menuGUIBounds = menuGUI.getGlobalBounds();
            sf::FloatRect canvasBounds = canvas.getGlobalBounds();

            if(event.type == sf::Event::Closed)
            {
                window.close();
            }

            if(event.type == sf::Event::MouseButtonPressed && event.key.code == sf::Mouse::Right)
            {
                if(canvasBounds.contains(mouseInBox))
                {
                    dotPosition = static_cast<sf::Vector2f>(mouse.getPosition(window));

                    circles.push_back(drawDot(dotPosition, defaultSize, r, g, b));
                }

            }

            if(menuGUIBounds.contains(mouseInBox))
            {
                menuGUI.setFillColor(sf::Color::Blue);

                if(event.type == sf::Event::MouseButtonPressed && event.key.code == sf::Mouse::Left)
                {
                    r = rand() % 255;
                    g = rand() % 255;
                    b = rand() % 255;
                }
            }


            if(event.type == sf::Event::MouseWheelMoved)
            {
                defaultSize += event.mouseWheel.delta;
                cout<<event.mouseWheel.delta<<endl;
            }

            window.clear(sf::Color(61,61,61));

            window.draw(menuGUI);
            window.draw(guiText);
            window.draw(canvas);
            for(vector<sf::CircleShape>::iterator it = circles.begin(); it != circles.end(); ++it)
            {
                window.draw(*it);
            }
 
            window.display();
        }

    }
}
 

Pages: [1] 2
anything