From 7cbcbf9eb18f2af5311f70d09f9c149be7941f9d Mon Sep 17 00:00:00 2001 From: Julian Kandlhoer Date: Mon, 19 Aug 2019 00:23:34 +0200 Subject: [PATCH 1/3] Fixed missing File in CMakeLists.txt causing linking error --- .gitignore | 6 +++++- strategy/CMakeLists.txt | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9a0d47b..5b751da 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,8 @@ bin/ Debug/ Release/ -.sln \ No newline at end of file +.sln + +#CLion +cmake-build-debug/ +.idea/ diff --git a/strategy/CMakeLists.txt b/strategy/CMakeLists.txt index b25e61d..ca18d77 100644 --- a/strategy/CMakeLists.txt +++ b/strategy/CMakeLists.txt @@ -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}) From dfdf6f830177f7dc96350c539ebfd03b85c473d0 Mon Sep 17 00:00:00 2001 From: Julian Kandlhoer Date: Mon, 19 Aug 2019 01:50:25 +0200 Subject: [PATCH 2/3] Fixed bucket tool crash --- strategy/src/tool_strategy/fill_bucket_tool_strategy.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/strategy/src/tool_strategy/fill_bucket_tool_strategy.cpp b/strategy/src/tool_strategy/fill_bucket_tool_strategy.cpp index 7a671a4..83ae505 100644 --- a/strategy/src/tool_strategy/fill_bucket_tool_strategy.cpp +++ b/strategy/src/tool_strategy/fill_bucket_tool_strategy.cpp @@ -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++); From ba6d4cd1beba15484a9b94ae46a05d98a0b4846d Mon Sep 17 00:00:00 2001 From: Julian Kandlhoer Date: Mon, 19 Aug 2019 02:00:18 +0200 Subject: [PATCH 3/3] Simplified makeButton call --- strategy/src/button.cpp | 6 ++++-- strategy/src/button.h | 3 ++- strategy/src/main.cpp | 37 ++++++++++--------------------------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/strategy/src/button.cpp b/strategy/src/button.cpp index 8ad51cd..0f123fc 100644 --- a/strategy/src/button.cpp +++ b/strategy/src/button.cpp @@ -2,11 +2,13 @@ #include -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); diff --git a/strategy/src/button.h b/strategy/src/button.h index 964081f..75d3762 100644 --- a/strategy/src/button.h +++ b/strategy/src/button.h @@ -9,7 +9,7 @@ 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; @@ -17,4 +17,5 @@ class Button { private: sf::RectangleShape m_button; + sf::Texture m_texture; }; \ No newline at end of file diff --git a/strategy/src/main.cpp b/strategy/src/main.cpp index 029b009..6dd06bf 100644 --- a/strategy/src/main.cpp +++ b/strategy/src/main.cpp @@ -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; } @@ -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 currentTool = std::make_unique(); Options options;