Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ bin/
Debug/
Release/

.sln
.sln

#CLion
cmake-build-debug/
.idea/
1 change: 1 addition & 0 deletions strategy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(SOURCES
src/tool_strategy/pencil_tool_strategy.cpp
src/tool_strategy/spray_can_strategy.cpp
src/tool_strategy/square_tool_strategy.cpp
src/tool_strategy/eraser_tool_strategy.cpp
)

add_executable(${PROJECT_NAME} ${SOURCES})
Expand Down
6 changes: 4 additions & 2 deletions strategy/src/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <iostream>

Button::Button(int x, int y, const sf::Texture& texture)
Button::Button(int x, int y, const std::string &iconPath)
: m_button ({Button::BUTTON_SIZE, Button::BUTTON_SIZE})
{

m_texture.loadFromFile(iconPath);
m_button.setPosition((float)x, (float)y);
m_button.setTexture(&texture);
m_button.setTexture(&m_texture);

m_button.setOutlineColor(sf::Color::Black);
m_button.setOutlineThickness(2);
Expand Down
3 changes: 2 additions & 1 deletion strategy/src/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ class Button {
public:
constexpr static unsigned BUTTON_SIZE = 32;

Button(int x, int y, const sf::Texture& texture);
Button(int x, int y, const std::string &iconPath);

bool isClicked(sf::Event e) const;

void render(sf::RenderWindow& window);

private:
sf::RectangleShape m_button;
sf::Texture m_texture;
};
37 changes: 10 additions & 27 deletions strategy/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#include "button.h"
#include "tool_strategy/tool_type_strategy.h"

Button makeButton(const sf::Texture& icon) {

Button makeButton(const std::string &iconPath) {
static int currentX = 10;

Button paintBrushButton(currentX, HEIGHT - 10 - Button::BUTTON_SIZE, icon);
Button paintBrushButton(currentX, HEIGHT - 10 - Button::BUTTON_SIZE, iconPath);
currentX += Button::BUTTON_SIZE * 2;
return paintBrushButton;
}
Expand All @@ -40,31 +41,13 @@ int main() {
toolbar.setOutlineColor(sf::Color::Black);
toolbar.setOutlineThickness(3);

//Toolbar button textures
sf::Texture paintBrushIcon;
sf::Texture fillIcon;
sf::Texture lineIcon;
sf::Texture pencilIcon;
sf::Texture sprayCanIcon;
sf::Texture squareIcon;
sf::Texture eraserIcon;
paintBrushIcon.loadFromFile("res/paintbrush.png");
fillIcon.loadFromFile("res/fill.png");
lineIcon.loadFromFile("res/line.png");
pencilIcon.loadFromFile("res/pencil.png");
sprayCanIcon.loadFromFile("res/spraycan.png");
squareIcon.loadFromFile("res/square.png");
eraserIcon.loadFromFile("res/erase.png");

auto paintBrushButton = makeButton(paintBrushIcon);
auto fillButton = makeButton(fillIcon);
auto lineButton = makeButton(lineIcon);
auto pencilButton = makeButton(pencilIcon);
auto sprayButton = makeButton(sprayCanIcon);
auto squareButton = makeButton(squareIcon);
auto eraserButton = makeButton(eraserIcon);


auto paintBrushButton = makeButton("res/paintbrush.png");
auto fillButton = makeButton("res/fill.png");
auto lineButton = makeButton("res/line.png");
auto pencilButton = makeButton("res/pencil.png");
auto sprayButton = makeButton("res/spraycan.png");
auto squareButton = makeButton("res/square.png");
auto eraserButton = makeButton("res/erase.png");

std::unique_ptr<ToolTypeStrategy> currentTool = std::make_unique<PaintBrushStrategy>();
Options options;
Expand Down
9 changes: 5 additions & 4 deletions strategy/src/tool_strategy/fill_bucket_tool_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ namespace {
}
auto pxColour = canvas.getPixelColour(x, y);
if(pxColour) {
auto r = pxColour->r;
auto g = pxColour->r;
auto b = pxColour->r;
if (r == targetColour.r && g == targetColour.g && b == targetColour.b) {
if(pxColour == fillColour) {
return;
}

if (pxColour == targetColour) {
canvas.changePixel(x, y, fillColour);
flood(canvas, fillColour, targetColour, x + 1, y, count++);
flood(canvas, fillColour, targetColour, x - 1, y, count++);
Expand Down