diff --git a/src/IntelliHelper/IntelliColorPicker.cpp b/src/IntelliHelper/IntelliColorPicker.cpp index 76ba561..65586c7 100644 --- a/src/IntelliHelper/IntelliColorPicker.cpp +++ b/src/IntelliHelper/IntelliColorPicker.cpp @@ -2,7 +2,7 @@ IntelliColorPicker::IntelliColorPicker(){ firstColor = {255,0,0,255}; - secondColor = {0,0,255,255}; + secondColor = {0,255,255,255}; } IntelliColorPicker::~IntelliColorPicker(){ diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 5ee6434..c835b24 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -20,9 +20,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ - // Testing Area - // test yout tool here and reset after accomplished test - this->Tool = new IntelliToolFloodFill(this, &colorPicker); + this->Tool = new IntelliToolPolygon(this, &colorPicker); this->setUp(maxWidth, maxHeight); this->addLayer(200,200,0,0,ImageType::Shaped_Image); layerBundle[0].image->drawPlain(QColor(0,0,255,255)); @@ -194,12 +192,12 @@ void PaintingArea::createLineTool(){ Tool = new IntelliToolLine(this, &colorPicker); } -int PaintingArea::getWidthActiveLayer(){ - return layerBundle.operator[](activeLayer).width; +int PaintingArea::getWidthOfActive(){ + return this->layerBundle[activeLayer].width; } -int PaintingArea::getHeightActiveLayer(){ - return layerBundle.operator[](activeLayer).hight; +int PaintingArea::getHeightOfActive(){ + return this->layerBundle[activeLayer].hight; } // If a mouse button is pressed check if it was the diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 868a56c..07b43a0 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -56,9 +56,8 @@ public: void createPlainTool(); void createLineTool(); - //get Width and Height of active Layer - int getWidthActiveLayer(); - int getHeightActiveLayer(); + int getWidthOfActive(); + int getHeightOfActive(); public slots: // Events to handle diff --git a/src/Tool/IntelliToolFloodFill.cpp b/src/Tool/IntelliToolFloodFill.cpp index 6d655ea..1f1503d 100644 --- a/src/Tool/IntelliToolFloodFill.cpp +++ b/src/Tool/IntelliToolFloodFill.cpp @@ -23,6 +23,9 @@ void IntelliToolFloodFill::onMouseRightReleased(int x, int y){ } void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ + if(!(x>=0 && xgetWidthOfActive() && y>=0 && ygetHeightOfActive())){ + return; + } IntelliTool::onMouseLeftPressed(x,y); QPoint start(x,y); @@ -50,11 +53,11 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ Canvas->image->drawPixel(left,newColor); Q.push(left); } - if((top.y() < Canvas->hight) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)){ + if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)){ Canvas->image->drawPixel(top,newColor); Q.push(top); } - if((down.y() >= 0) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)){ + if((down.y() < Canvas->hight) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)){ Canvas->image->drawPixel(down,newColor); Q.push(down); } diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index d075529..080168d 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -2,43 +2,36 @@ #include "Layer/PaintingArea.h" #include #include +#include IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker) :IntelliTool(Area, colorPicker){ - lineWidth = 5; - isDrawing = false; + this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); + lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);; PointIsNearStart = false; - drawingPoint.setX(0); - drawingPoint.setY(0); - Point.setX(0); - Point.setY(0); + isDrawing = false; } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing){ - width = Area->getWidthActiveLayer(); - height = Area->getHeightActiveLayer(); - } - if(!isDrawing && x > 0 && y > 0 && x < width && y < height){ - isDrawing = true; - drawingPoint.setX(x); - drawingPoint.setY(y); - QPointList.push_back(drawingPoint); + if(!isDrawing && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()){ IntelliTool::onMouseLeftPressed(x,y); - this->Canvas->image->drawPlain(Qt::transparent); + QPoint drawingPoint = QPoint(x,y); + + isDrawing = true; + QPointList.push_back(drawingPoint); + this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth); this->Canvas->image->calculateVisiblity(); } else if(isDrawing && isNearStart(x,y,QPointList.front())){ - PointIsNearStart = isNearStart(x,y,QPointList.front()); + PointIsNearStart = true; this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth); this->Canvas->image->calculateVisiblity(); } else if(isDrawing){ - drawingPoint.setX(x); - drawingPoint.setY(y); + QPoint drawingPoint(x,y); QPointList.push_back(drawingPoint); - this->Canvas->image->drawLine(QPointList.operator[](QPointList.size() - 2), QPointList.back(), colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth); this->Canvas->image->calculateVisiblity(); } } @@ -52,29 +45,35 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(PointIsNearStart && QPointList.size() > 1){ - this->Canvas->image->calculateVisiblity(); PointIsNearStart = false; isDrawing = false; - Triangles = IntelliHelper::calculateTriangles(QPointList); - for(int i = 0; i < width; i++){ - for(int j = 0; j < height; j++){ - Point.setX(i); - Point.setY(j); + std::vector Triangles = IntelliHelper::calculateTriangles(QPointList); + QPoint Point; + QColor colorTwo(colorPicker->getSecondColor()); + colorTwo.setAlpha(alphaInner); + for(int i = 0; i < Active->width; i++){ + for(int j = 0; j < Active->hight; j++){ + Point = QPoint(i,j); if(IntelliHelper::isInPolygon(Triangles,Point)){ - this->Canvas->image->drawPixel(QPoint(i,j), colorPicker->getFirstColor()); + this->Canvas->image->drawPixel(Point, colorTwo); } } } + for(int i=0; iCanvas->image->drawLine(QPointList[i], QPointList[next], colorPicker->getFirstColor(), lineWidth); + } QPointList.clear(); IntelliTool::onMouseLeftReleased(x,y); } } void IntelliToolPolygon::onMouseRightReleased(int x, int y){ - + IntelliTool::onMouseRightReleased(x,y); } void IntelliToolPolygon::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); if(!isDrawing){ if(lineWidth + value < 10){ lineWidth += value; @@ -86,7 +85,7 @@ void IntelliToolPolygon::onWheelScrolled(int value){ } void IntelliToolPolygon::onMouseMoved(int x, int y){ - + IntelliTool::onMouseMoved(x,y); } bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index da9fa7c..3f53d76 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -10,6 +10,39 @@ */ class IntelliToolPolygon : public IntelliTool { + /*! + * \brief Checks if the given Point lies near the starting Point. + * \param x - x coordinate of a point. + * \param y - y coordinate of a point. + * \param Startpoint - The startingpoint to check for. + * \return Returns true if the (x,y) point is near to the startpoint, otherwise false. + */ + bool isNearStart(int x, int y, QPoint Startpoint); + + /*! + * \brief LineWidth of the drawing polygon. + */ + int lineWidth; + + /*! + * \brief IsDrawing true while drawing, else false. + */ + bool isDrawing; + + /*! + * \brief PointIsNearStart true, when last click near startpoint, else false. + */ + bool PointIsNearStart; + + /*! + * \brief The alpha value of the inner circle. + */ + int alphaInner; + + /*! + * \brief QPointList list of all points of the polygon. + */ + std::vector QPointList; public: /*! * \brief IntelliToolPolygon Constructor Define the Tool-intern Parameters @@ -27,52 +60,7 @@ public: virtual void onMouseMoved(int x, int y) override; -private: - /*! - * \brief isNearStart - * \param x - * \param y - * \param Startpoint - * \return true : Near Startpoint, else false - */ - bool isNearStart(int x, int y, QPoint Startpoint); - /*! - * \brief lineWidth of the Drawing Polygon - */ - int lineWidth; - /*! - * \brief width of the active Layer - */ - int width; - /*! - * \brief height of the active Layer - */ - int height; - /*! - * \brief isDrawing true while drawing, else false - */ - bool isDrawing; - /*! - * \brief PointIsNearStart true, when last click near Startpoint, else false - */ - bool PointIsNearStart; - /*! - * \brief drawingPoint Current Point after Left-Click - */ - QPoint drawingPoint; - /*! - * \brief Point Needed to look, if Point is in Polygon - */ - QPoint Point; - /*! - * \brief QPointList List of all Points of the Polygon - */ - std::vector QPointList; - /*! - * \brief Triangles Transformed QPointList into triangulated Form of the Polygon - */ - std::vector Triangles; };