Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include "ToolFill.h"
  2.  
  3. ToolFill::ToolFill() : Tool("Fill", 3, 0) {}
  4.  
  5. ToolFill::~ToolFill() {}
  6.  
  7. void floodFill(std::vector<glm::vec2> points, sf::Vector2u size, int x, int y, glm::vec4 col)
  8. {
  9. // Base cases
  10. if (std::find(points.begin(), points.end(), glm::vec2(x, y)) != points.end() || x < 0 || x >= size.x || y < 0 || y >= size.y)
  11. return;
  12. if (readColor(size, x, y) != col)
  13. return;
  14.  
  15. // Replace the color at (x, y)
  16. points.push_back({x, y});
  17.  
  18. // Recur for north, east, south and west
  19. floodFill(points, size, x+1, y, col);
  20. floodFill(points, size, x-1, y, col);
  21. floodFill(points, size, x, y+1, col);
  22. floodFill(points, size, x, y-1, col);
  23. }
  24.  
  25. bool ToolFill::mousePressed(ListenerContext<sf::Event::MouseButtonEvent> ctx)
  26. {
  27. sf::Vector2u size = ctx.getUI()->getEngine()->getSize();
  28. glm::vec4 col = readColor(size, ctx.event.x, ctx.event.y);
  29. std::vector<glm::vec2> points;
  30. floodFill(points, size, ctx.event.x, ctx.event.y, col);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement