From 72b7ae9a7dd645c8a3a56d1cb8dbb5a4162c42c1 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 6 Nov 2018 11:26:26 +0100 Subject: [PATCH] 05_OOa: Testat bestanden --- src/05_OO/a/CMakeLists.txt | 2 ++ src/05_OO/a/Testat/Sign.cpp | 11 +++++++++++ src/05_OO/a/Testat/Sign.h | 15 +++++++++++++++ src/05_OO/a/Testat/shapes_main.cpp | 4 +++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/05_OO/a/Testat/Sign.cpp create mode 100644 src/05_OO/a/Testat/Sign.h diff --git a/src/05_OO/a/CMakeLists.txt b/src/05_OO/a/CMakeLists.txt index 2582519..8a3ac13 100644 --- a/src/05_OO/a/CMakeLists.txt +++ b/src/05_OO/a/CMakeLists.txt @@ -27,5 +27,7 @@ add_executable(05_OOa_Testat Testat/Rectangle.h Testat/Scene.cpp Testat/Scene.h + Testat/Sign.cpp + Testat/Sign.h ../../helpers/AnsiConsole.cpp ) \ No newline at end of file diff --git a/src/05_OO/a/Testat/Sign.cpp b/src/05_OO/a/Testat/Sign.cpp new file mode 100644 index 0000000..8c4fb7d --- /dev/null +++ b/src/05_OO/a/Testat/Sign.cpp @@ -0,0 +1,11 @@ +#include "Sign.h" + +Sign::Sign(int x, int y, int width, int height, Colors color, std::string _text) : +Rectangle::Rectangle(x, y, width, height, color), text(_text) { +} + +void Sign::draw() { + Rectangle::draw(); + int x = Rectangle::position.x - (text.length()/2); + ansiConsole.printText(x, Rectangle::position.y, text, Rectangle::color); +} diff --git a/src/05_OO/a/Testat/Sign.h b/src/05_OO/a/Testat/Sign.h new file mode 100644 index 0000000..1131586 --- /dev/null +++ b/src/05_OO/a/Testat/Sign.h @@ -0,0 +1,15 @@ +#ifndef C_C_SIGN_H +#define C_C_SIGN_H + +#include "Rectangle.h" + +class Sign : public Rectangle { +protected: + std::string text; +public: + Sign(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE, std::string text = "Hier Text einfügen"); + void draw() override; +}; + + +#endif diff --git a/src/05_OO/a/Testat/shapes_main.cpp b/src/05_OO/a/Testat/shapes_main.cpp index 20dbcde..2a75a41 100644 --- a/src/05_OO/a/Testat/shapes_main.cpp +++ b/src/05_OO/a/Testat/shapes_main.cpp @@ -4,6 +4,7 @@ #include "Circle.h" #include "Rectangle.h" #include "Scene.h" +#include "Sign.h" int main(int argc, char **argv) { std::vector shapes; @@ -17,7 +18,8 @@ int main(int argc, char **argv) { shapes.push_back(new Circle(30, 20, 15, Colors::GREEN)); - shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA)); + shapes.push_back(new Rectangle(5, 25, 10, 10, Colors::MAGENTA)); + shapes.push_back(new Sign(60, 10, 20, 5, Colors::CYAN, "Hallo Welt")); shapes.push_back(new Point(5, 10, Colors::WHITE)); shapes.push_back(new Point(15, 7, Colors::WHITE));