diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index 359768e..0911288 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -27,14 +27,17 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){ } void IntelliShapedImage::calculateVisiblity(){ - if(fastRenderering) { + if(polygonData.size()<2){ + return; + } + if(fastRenderering) { this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); } if(polygonData.size()<=2) { QColor clr; for(int y=0; y& polygonData){ this->polygonData.push_back(QPoint(element.x(), element.y())); } triangles = IntelliTriangulation::calculateTriangles(polygonData); + if(fastRenderering){ + imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + for(int y = 0; y=0&&idx(layerBundle.size())) { if(layerBundle[static_cast(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){ - qDebug() << "Todo Implement here set Polygon"; + delete this->Tool; + this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); } } } @@ -438,5 +439,20 @@ IntelliImage* PaintingArea::getImageOfActiveLayer(){ if(activeLayer<0) { return nullptr; } - return layerBundle[activeLayer].image; + return layerBundle[static_cast(activeLayer)].image; +} + +QImage PaintingArea::getImageDataOfActiveLayer(){ + QImage returnImage; + if(activeLayer<0) { + returnImage = QImage(QSize(10,10),QImage::Format_ARGB32); + returnImage.fill(QColor(255,255,255,255)); + } + else{ + returnImage = layerBundle[static_cast(activeLayer)].image->getImageData(); + if(renderSettings.isFastRenderering()){ + returnImage = returnImage.convertToFormat(QImage::Format_ARGB32); + } + } + return returnImage; } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 5e3d03a..ac394f5 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -182,6 +182,12 @@ int getNumberOfActiveLayer(); IntelliImage* getImageOfActiveLayer(); +/*! + * \brief getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer it return a 10*10 white picture) + * \return return the image as an rgba32bit qImage + */ +QImage getImageDataOfActiveLayer(); + IntelliToolsettings Toolsettings; IntelliColorPicker colorPicker; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 995c37e..1ec2d0c 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -33,7 +33,7 @@ void IntelliTool::onMouseLeftPressed(int x, int y){ void IntelliTool::onMouseLeftReleased(int x, int y){ if(isDrawing) { isDrawing=false; - this->mergeToolLayer(); + this->mergeToolLayer(); this->deleteToolLayer(); activeLayer->image->calculateVisiblity(); } @@ -62,25 +62,25 @@ void IntelliTool::mergeToolLayer(){ QColor clr_1; QImage updatedImage = activeLayer->image->getImageData(); - for(int y=0; yheight; y++) { - for(int x=0; xwidth; x++) { - clr_0=updatedImage.pixelColor(x,y); - clr_1=Canvas->image->imageData.pixelColor(x,y); - float t = static_cast(clr_1.alpha())/255.f; - int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); - int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); - int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(clr_0.blue()*(1.f-t))+0.5f); - int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); - clr_0.setRed(r); - clr_0.setGreen(g); - clr_0.setBlue(b); - clr_0.setAlpha(a); + for(int y=0; yheight; y++) { + for(int x=0; xwidth; x++) { + clr_0=updatedImage.pixelColor(x,y); + clr_1=Canvas->image->imageData.pixelColor(x,y); + float t = static_cast(clr_1.alpha())/255.f; + int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); + int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); + int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(clr_0.blue()*(1.f-t))+0.5f); + int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); + clr_0.setRed(r); + clr_0.setGreen(g); + clr_0.setBlue(b); + clr_0.setAlpha(a); - updatedImage.setPixelColor(x, y, clr_0); - } - } + updatedImage.setPixelColor(x, y, clr_0); + } + } activeLayer->image->setImageData(updatedImage); - if(Canvas->image->getPolygonData().size() != 0){ + if(Canvas->image->getPolygonData().size() > 0){ activeLayer->image->setPolygon(Canvas->image->getPolygonData()); } Area->DummyGui->UpdateGui(); diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 84923c3..32c416f 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -4,11 +4,12 @@ #include #include -IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) +IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon) : IntelliTool(Area, colorPicker, Toolsettings){ isPointNearStart = false; isDrawing = false; isInside = false; + this->isSettingPolygon = isSettingPolygon; this->ActiveType = Tooltype::POLYGON; } @@ -19,10 +20,13 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); QPoint Point(x,y); isInside = IntelliTriangulation::isInPolygon(Triangles,Point); + if(isSettingPolygon){ + isInside = true; + } } else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { isInside = true; @@ -36,14 +40,18 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ QPointList.push_back(drawingPoint); this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - this->Canvas->image->calculateVisiblity(); + if(!isSettingPolygon){ + this->Canvas->image->calculateVisiblity(); + } } else if(isDrawing && isNearStart(x,y,QPointList.front())) { if(QPointList.size() > 2) { isPointNearStart = true; this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - this->Canvas->image->calculateVisiblity(); - } + if(!isSettingPolygon){ + this->Canvas->image->calculateVisiblity(); + } + } else{ isInside = false; isDrawing = false; @@ -56,7 +64,9 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ QPoint drawingPoint(x,y); QPointList.push_back(drawingPoint); this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - this->Canvas->image->calculateVisiblity(); + if(!isSettingPolygon){ + this->Canvas->image->calculateVisiblity(); + } } } @@ -73,7 +83,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ isInside = false; isPointNearStart = false; isDrawing = false; - if(false){ + if(!isSettingPolygon){ std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; QColor colorTwo(colorPicker->getSecondColor()); @@ -94,6 +104,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ } else{ Canvas->image->setPolygon(QPointList); + Canvas->image->setImageData(Area->getImageDataOfActiveLayer()); } IntelliTool::onMouseLeftReleased(x,y); QPointList.clear(); diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index d4a7561..d50adc4 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -29,6 +29,11 @@ bool isDrawing; */ bool isInside; +/*! + * \brief isSettingPolygon is the flag for calling the setPolygon method. + */ +bool isSettingPolygon; + /*! * \brief PointIsNearStart true, when last click near startpoint, else false. */ @@ -43,8 +48,9 @@ public: * \brief A constructor setting the general paintingArea and colorPicker. * \param Area - The general paintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. + * \param isSettingPolygon - The flag for the set polygon method, standart is false */ -IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); +IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon = false); /*! * \brief A Destructor. */