diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 4254f63..0a4b919 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -5,6 +5,7 @@ IntelliImage::IntelliImage(int weight, int height) : imageData(QSize(weight, height), QImage::Format_ARGB32){ imageData.fill(QColor(255,255,255,255)); + } IntelliImage::~IntelliImage(){ diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index be99c1d..04315c3 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -8,13 +8,7 @@ #include #include -/*! - * \brief The Types, which an Image can be. - */ -enum class ImageType { - Raster_Image, - Shaped_Image -}; +#include "IntelliHelper/IntelliHelper.h" class IntelliTool; @@ -23,6 +17,16 @@ class IntelliTool; */ class IntelliImage { friend IntelliTool; +public: + +/*! + * \brief The Types, which an Image can be. + */ +enum class ImageType { + Raster_Image, + Shaped_Image +}; + protected: void resizeImage(QImage*image, const QSize &newSize); @@ -30,6 +34,11 @@ void resizeImage(QImage*image, const QSize &newSize); * \brief The underlying image data. */ QImage imageData; + +/*! + * \brief The Type, an Image is. + */ +ImageType TypeOfImage; public: /*! * \brief The Construcor of the IntelliImage. Given the Image dimensions. @@ -114,6 +123,10 @@ virtual std::vector getPolygonData(){ return std::vector(); } +virtual ImageType getTypeOfImage(){ + return TypeOfImage; +} + /*! * \brief A function that loads and sclaes an image to the fitting dimensions. * \param filePath - The path+name of the image which to loaded. diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index c7b3d48..8e8f918 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -5,7 +5,7 @@ IntelliRasterImage::IntelliRasterImage(int weight, int height) : IntelliImage(weight, height){ - + TypeOfImage = IntelliImage::ImageType::Raster_Image; } IntelliRasterImage::~IntelliRasterImage(){ @@ -15,6 +15,7 @@ IntelliRasterImage::~IntelliRasterImage(){ IntelliImage* IntelliRasterImage::getDeepCopy(){ IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height()); raster->imageData.fill(Qt::transparent); + raster->TypeOfImage = IntelliImage::ImageType::Raster_Image; return raster; } diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index cd2457f..b61cb23 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -6,6 +6,7 @@ IntelliShapedImage::IntelliShapedImage(int weight, int height) : IntelliRasterImage(weight, height){ + TypeOfImage = IntelliImage::ImageType::Shaped_Image; } IntelliShapedImage::~IntelliShapedImage(){ @@ -20,6 +21,7 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){ IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height()); shaped->setPolygon(this->polygonData); shaped->imageData.fill(Qt::transparent); + shaped->TypeOfImage = IntelliImage::ImageType::Shaped_Image; return shaped; } diff --git a/src/Image/IntelliShapedImage.h b/src/Image/IntelliShapedImage.h index 5d1288d..0140aa8 100644 --- a/src/Image/IntelliShapedImage.h +++ b/src/Image/IntelliShapedImage.h @@ -3,7 +3,6 @@ #include "Image/IntelliRasterImage.h" #include -#include "IntelliHelper/IntelliHelper.h" /*! * \brief The IntelliShapedImage manages a Shapedimage. diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 638fe99..82380ec 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -22,7 +22,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QWidget(parent){ this->Tool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); - this->addLayer(200,200,0,0,ImageType::Shaped_Image); + this->addLayer(200,200,0,0,IntelliImage::ImageType::Shaped_Image); layerBundle[0].image->drawPlain(QColor(0,0,255,255)); std::vector polygon; polygon.push_back(QPoint(100,000)); @@ -31,7 +31,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) polygon.push_back(QPoint(000,100)); layerBundle[0].image->setPolygon(polygon); - this->addLayer(200,200,150,150); + this->addLayer(200,200,150,150,IntelliImage::ImageType::Raster_Image); layerBundle[1].image->drawPlain(QColor(0,255,0,255)); layerBundle[1].alpha=200; @@ -53,15 +53,15 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ } -int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){ +int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ LayerObject newLayer; newLayer.width = width; newLayer.height = height; newLayer.widthOffset = widthOffset; newLayer.heightOffset = heightOffset; - if(type==ImageType::Raster_Image) { + if(type==IntelliImage::ImageType::Raster_Image) { newLayer.image = new IntelliRasterImage(width,height); - }else if(type==ImageType::Shaped_Image) { + }else if(type==IntelliImage::ImageType::Shaped_Image) { newLayer.image = new IntelliShapedImage(width, height); } newLayer.alpha = 255; @@ -234,6 +234,14 @@ int PaintingArea::getHeightOfActive(){ return this->layerBundle[static_cast(activeLayer)].height; } +IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){ + return this->layerBundle[static_cast(activeLayer)].image->getTypeOfImage(); +} + +std::vector PaintingArea::getPolygonDataOfRealLayer(){ + return this->layerBundle[static_cast(activeLayer)].image->getPolygonData(); +} + // If a mouse button is pressed check if it was the // left button and if so store the current position // Set that we are currently drawing diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 9719ac0..81e4af2 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -79,7 +79,7 @@ public: * \param type - Defining the ImageType of the new layer * \return Returns the number of layers in the project */ - int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image); + int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::Raster_Image); /*! * \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack * \param idx - ID of the position the new layer should be added @@ -90,7 +90,7 @@ public: * \param type - Defining the ImageType of the new layer * \return Returns the id of the layer position */ - int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image); + int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::Raster_Image); /*! * \brief The deleteLayer method removes a layer at a given index * \param index - The index of the layer to be removed @@ -161,6 +161,10 @@ public: */ int getHeightOfActive(); + IntelliImage::ImageType getTypeOfImageRealLayer(); + + std::vector getPolygonDataOfRealLayer(); + public slots: // Events to handle /*! diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 671a50f..fce3ff5 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -49,8 +49,8 @@ void IntelliTool::onWheelScrolled(int value){ void IntelliTool::createToolLayer(){ Area->createTempTopLayer(Area->activeLayer); - this->activeLayer=&Area->layerBundle[static_cast(Area->activeLayer)]; - this->Canvas=&Area->layerBundle[static_cast(Area->activeLayer+1)]; + this->activeLayer=&Area->layerBundle[static_cast(Area->activeLayer)]; + this->Canvas=&Area->layerBundle[static_cast(Area->activeLayer+1)]; } void IntelliTool::mergeToolLayer(){ diff --git a/src/Tool/IntelliToolPen.cpp b/src/Tool/IntelliToolPen.cpp index 3b9eb09..90146e0 100644 --- a/src/Tool/IntelliToolPen.cpp +++ b/src/Tool/IntelliToolPen.cpp @@ -25,7 +25,7 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){ void IntelliToolPen::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->previousPoint=QPoint(x,y); - this->Canvas->image->drawPixel(previousPoint, colorPicker->getFirstColor()); + this->Canvas->image->drawPoint(previousPoint, colorPicker->getFirstColor(), penWidth); Canvas->image->calculateVisiblity(); } diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index a4a6685..4eb3eb7 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -1,8 +1,8 @@ #include "IntelliToolPolygon.h" #include "Layer/PaintingArea.h" -#include #include #include +#include IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker) : IntelliTool(Area, colorPicker){ @@ -10,6 +10,7 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* c lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",5,1,10,1); isPointNearStart = false; isDrawing = false; + isInside = false; this->ActiveType = Tooltype::POLYGON; } @@ -20,7 +21,16 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Shaped_Image && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()){ + std::vector Triangles = IntelliHelper::calculateTriangles(Area->getPolygonDataOfRealLayer()); + QPoint Point(x,y); + isInside = IntelliHelper::isInPolygon(Triangles,Point); + } + else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Raster_Image && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()){ + isInside = true; + } + + if(isInside && !isDrawing) { IntelliTool::onMouseLeftPressed(x,y); QPoint drawingPoint = QPoint(x,y); @@ -37,6 +47,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ this->Canvas->image->calculateVisiblity(); } else{ + isInside = false; isDrawing = false; QPointList.clear(); IntelliTool::onMouseRightPressed(x,y); @@ -52,6 +63,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ } void IntelliToolPolygon::onMouseRightPressed(int x, int y){ + isInside = false; isDrawing = false; isPointNearStart = false; QPointList.clear(); @@ -60,6 +72,7 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(isPointNearStart) { + isInside = false; isPointNearStart = false; isDrawing = false; std::vector Triangles = IntelliHelper::calculateTriangles(QPointList); diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index 297173f..baa68eb 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -29,6 +29,11 @@ int lineWidth; */ bool isDrawing; +/*! + * \brief isInside Checks if Point is inside Image + */ +bool isInside; + /*! * \brief PointIsNearStart true, when last click near startpoint, else false. */