Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ToolFill.h"
- ToolFill::ToolFill() : Tool("Fill", 3, 0) {}
- ToolFill::~ToolFill() {}
- void floodFill(std::vector<glm::vec2> points, sf::Vector2u size, int x, int y, glm::vec4 col)
- {
- // Base cases
- if (std::find(points.begin(), points.end(), glm::vec2(x, y)) != points.end() || x < 0 || x >= size.x || y < 0 || y >= size.y)
- return;
- if (readColor(size, x, y) != col)
- return;
- // Replace the color at (x, y)
- points.push_back({x, y});
- // Recur for north, east, south and west
- floodFill(points, size, x+1, y, col);
- floodFill(points, size, x-1, y, col);
- floodFill(points, size, x, y+1, col);
- floodFill(points, size, x, y-1, col);
- }
- bool ToolFill::mousePressed(ListenerContext<sf::Event::MouseButtonEvent> ctx)
- {
- sf::Vector2u size = ctx.getUI()->getEngine()->getSize();
- glm::vec4 col = readColor(size, ctx.event.x, ctx.event.y);
- std::vector<glm::vec2> points;
- floodFill(points, size, ctx.event.x, ctx.event.y, col);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement