From 2432bb0568ef9ea2dd889540fb24a805c3fd5b98 Mon Sep 17 00:00:00 2001 From: AshBastian Date: Sat, 25 Jan 2020 19:37:14 +0100 Subject: [PATCH 1/5] Wechsel Rechner --- src/IntelliPhoto.pro | 2 + src/Layer/PaintingArea.cpp | 4 +- src/Tool/IntelliToolGradient.cpp | 61 ++++++++++++++++++++++++++++++ src/Tool/IntelliToolGradient.h | 64 ++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 src/Tool/IntelliToolGradient.cpp create mode 100644 src/Tool/IntelliToolGradient.h diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index 2b1d4d5..a0adaac 100755 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -30,6 +30,7 @@ SOURCES += \ Tool/IntelliTool.cpp \ Tool/IntelliToolCircle.cpp \ Tool/IntelliToolFloodFill.cpp \ + Tool/IntelliToolGradient.cpp \ Tool/IntelliToolLine.cpp \ Tool/IntelliToolPen.cpp \ Tool/IntelliToolPlain.cpp \ @@ -52,6 +53,7 @@ HEADERS += \ Tool/IntelliTool.h \ Tool/IntelliToolCircle.h \ Tool/IntelliToolFloodFill.h \ + Tool/IntelliToolGradient.h \ Tool/IntelliToolLine.h \ Tool/IntelliToolPen.h \ Tool/IntelliToolPlain.h \ diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 6534aab..8df8ffe 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -17,6 +17,7 @@ #include "Tool/IntelliToolRectangle.h" #include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolPolygon.h" +#include "Tool/IntelliToolGradient.h" #include "GUI/IntelliPhotoGui.h" LayerObject::LayerObject(){ @@ -38,9 +39,8 @@ LayerObject::LayerObject(const LayerObject& layer){ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QLabel(parent){ - this->Tool = nullptr; + this->Tool = new IntelliToolGradient(this,&colorPicker,&Toolsettings); this->setLayerDimensions(maxWidth, maxHeight); - activeLayer = -1; } diff --git a/src/Tool/IntelliToolGradient.cpp b/src/Tool/IntelliToolGradient.cpp new file mode 100644 index 0000000..4ab3699 --- /dev/null +++ b/src/Tool/IntelliToolGradient.cpp @@ -0,0 +1,61 @@ +#include "IntelliToolGradient.h" +#include + +IntelliToolGradient::IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->LineColor = QColor(0,0,0,255); + this->hasMoved = false; + + A = QPoint(0,0); + B = QPoint(0,3); + VectorAB = QPoint(0,3); + computePixelColor(QPoint(2,1)); +} + +IntelliToolGradient::~IntelliToolGradient(){ + IntelliTool::onMouseRightPressed(0,0); +} + +void IntelliToolGradient::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + A = QPoint(x,y); + B = QPoint(x,y); + VectorAB = QPoint(0,0); + //Canvas->image->drawPlain(colorPicker->getFirstColor); + //Canvas->image->drawPixel(A,LineColor); +} + +void IntelliToolGradient::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolGradient::onMouseLeftReleased(int x, int y){ + if(!hasMoved && A != B){ + //Canvas->image->drawPlain(colorPicker->getFirstColor); + } + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolGradient::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolGradient::onMouseMoved(int x, int y){ + hasMoved = true; + B = QPoint(x,y); + IntelliTool::onMouseMoved(x,y); +} + +void IntelliToolGradient::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); +} + +void IntelliToolGradient::computePixelColor(QPoint Point){ + QPoint NormalVector = QPoint(VectorAB.y(),(-1*VectorAB.x())); + Point = Point - (dotProduct((Point - A),NormalVector) / dotProduct(NormalVector,NormalVector)) * NormalVector; + qDebug() << Point.y(); +} + +float IntelliToolGradient::dotProduct(QPoint Vector1, QPoint Vector2){ + return static_cast(Vector1.x()*Vector2.x()+Vector1.y()*Vector2.y()); +} diff --git a/src/Tool/IntelliToolGradient.h b/src/Tool/IntelliToolGradient.h new file mode 100644 index 0000000..80424a1 --- /dev/null +++ b/src/Tool/IntelliToolGradient.h @@ -0,0 +1,64 @@ +#ifndef INTELLITOOLGRADIENT_H +#define INTELLITOOLGRADIENT_H +#include "IntelliTool.h" + +class IntelliToolGradient : public IntelliTool{ +private: + QPoint A; + QPoint B; + QPoint VectorAB; + QColor LineColor; + bool hasMoved; + +public: + IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); + + ~IntelliToolGradient(); + + /*! + * \brief A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseRightPressed(int x, int y); + + /*! + * \brief A function managing the right click Released of a Mouse. Merging the Canvas to Active. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseRightReleased(int x, int y); + + /*! + * \brief A function managing the left click Pressed of a Mouse. Resetting the current draw. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseLeftPressed(int x, int y); + + /*! + * \brief A function managing the left click Released of a Mouse. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseLeftReleased(int x, int y); + + /*! + * \brief A function managing the scroll event. A positive value means scrolling outwards. Call this in child classes! + * \param value - The absolute the scroll has changed. + */ + virtual void onWheelScrolled(int value); + + /*! + * \brief A function managing the mouse moved event. Call this in child classes! + * \param x - The x coordinate of the new mouse position. + * \param y - The y coordinate of the new mouse position. + */ + virtual void onMouseMoved(int x, int y); + + void computePixelColor(QPoint Point); + + float dotProduct(QPoint Vector1, QPoint Vector2); +}; + +#endif // INTELLITOOLGRADIENT_H From 9f6fe965ec9baf4f9dd80476a83010094252b765 Mon Sep 17 00:00:00 2001 From: AshBastian Date: Sat, 25 Jan 2020 21:54:25 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Vollst=C3=A4ndiger=20Gradient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Achtung!!! Sehr Rechenaufwendig und im Fastrenderer noch nicht ordentlich nutzbar --- src/GUI/IntelliPhotoGui.cpp | 31 ++++++++++- src/GUI/IntelliPhotoGui.h | 4 ++ src/Layer/PaintingArea.cpp | 7 ++- src/Layer/PaintingArea.h | 1 + src/Tool/IntelliToolGradient.cpp | 91 ++++++++++++++++++++++++++------ src/Tool/IntelliToolGradient.h | 7 ++- 6 files changed, 122 insertions(+), 19 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index d76722a..d3ab832 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -20,6 +20,7 @@ IntelliPhotoGui::IntelliPhotoGui(){ setIntelliStyle(); // Size the app resize(600,600); + showMaximized(); setDefaultValues(); } @@ -241,11 +242,13 @@ void IntelliPhotoGui::slotSetActiveLayer(){ void IntelliPhotoGui::slotUpdateRenderSettingsOn(){ paintingArea->setRenderSettings(true); + FastRendererLabel->setText("Fast Render: On"); UpdateGui(); } void IntelliPhotoGui::slotUpdateRenderSettingsOff(){ paintingArea->setRenderSettings(false); + FastRendererLabel->setText("Fast Render: Off"); UpdateGui(); } @@ -299,6 +302,11 @@ void IntelliPhotoGui::slotCreateFloodFillTool(){ paintingArea->createFloodFillTool(); } +void IntelliPhotoGui::slotCreateGradientTool(){ + GradientButton->setChecked(true); + paintingArea->createGradientTool(); +} + // Open an about dialog void IntelliPhotoGui::slotAboutDialog(){ // Window title and text to display @@ -520,6 +528,10 @@ void IntelliPhotoGui::createActions(){ connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool())); + actionCreateGradientTool = new QAction(tr("&Gradient"),this); + connect(actionCreateGradientTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); + connect(actionCreateGradientTool, SIGNAL(triggered()), this, SLOT(slotCreateGradientTool())); + // Create about action and tie to IntelliPhotoGui::about() actionAboutDialog = new QAction(tr("&About"), this); actionAboutDialog->setShortcut(Qt::Key_F2); @@ -539,6 +551,9 @@ void IntelliPhotoGui::createActions(){ connect(FloodFillButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); connect(FloodFillButton, SIGNAL(clicked()), this, SLOT(slotCreateFloodFillTool())); + connect(GradientButton, SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(GradientButton, SIGNAL(clicked()), this, SLOT(slotCreateGradientTool())); + connect(LineButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); connect(LineButton, SIGNAL(clicked()), this, SLOT(slotCreateLineTool())); @@ -621,7 +636,8 @@ void IntelliPhotoGui::createMenus(){ //Attach all Tool Creation Actions toolCreationMenu = new QMenu(tr("&Drawingtools"), this); toolCreationMenu->addAction(actionCreateCircleTool); - toolCreationMenu->addAction(actionCreateFloodFillTool); + toolCreationMenu->addAction(actionCreateFloodFillTool); + toolCreationMenu->addAction(actionCreateGradientTool); toolCreationMenu->addAction(actionCreateLineTool); toolCreationMenu->addAction(actionCreatePenTool); toolCreationMenu->addAction(actionCreatePlainTool); @@ -689,6 +705,13 @@ void IntelliPhotoGui::createGui(){ FloodFillButton->setIconSize(Buttonsize); FloodFillButton->setCheckable(true); + preview = QPixmap(":/Icons/Buttons/icons/icon.png"); + GradientButton = new QPushButton(); + GradientButton->setFixedSize(Buttonsize); + GradientButton->setIcon(preview); + GradientButton->setIconSize(Buttonsize); + GradientButton->setCheckable(true); + preview = QPixmap(":/Icons/Buttons/icons/line-tool.svg"); LineButton = new QPushButton(); LineButton->setFixedSize(Buttonsize); @@ -787,6 +810,10 @@ void IntelliPhotoGui::createGui(){ QString String = QString("%1x%2").arg(paintingArea->Canvas->width()).arg(paintingArea->Canvas->height()); dimCanvas->setText(String); + FastRendererLabel = new QLabel(); + FastRendererLabel->setFixedSize(Buttonsize.width() * 2 + 15,(Buttonsize.height() * 2) / 3); + FastRendererLabel->setText("Fast Render: On"); + ScrollArea = new QScrollArea(this); ScrollArea->setBackgroundRole(QPalette::Dark); ScrollArea->setWidget(paintingArea); @@ -802,6 +829,7 @@ void IntelliPhotoGui::createGui(){ mainLayout->addWidget(PlainButton,3,2,1,1); mainLayout->addWidget(PolygonButton,3,3,1,1); mainLayout->addWidget(RectangleButton,4,2,1,1); + mainLayout->addWidget(GradientButton,4,3,1,1); mainLayout->addWidget(WidthLine,5,2,1,2); mainLayout->addWidget(EditLineWidth,6,2,1,2); mainLayout->addWidget(innerAlphaLine,7,2,1,2); @@ -813,6 +841,7 @@ void IntelliPhotoGui::createGui(){ mainLayout->addWidget(ActiveLayerImageLabel,12,2,1,2); mainLayout->addWidget(dimActive,13,2,1,2); mainLayout->addWidget(dimCanvas,14,2,1,2); + mainLayout->addWidget(FastRendererLabel,15,2,1,2); mainLayout->setHorizontalSpacing(0); } diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 0ea5bc3..25f6145 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -85,6 +85,7 @@ void slotCreateRectangleTool(); void slotCreateCircleTool(); void slotCreatePolygonTool(); void slotCreateFloodFillTool(); +void slotCreateGradientTool(); void slotAboutDialog(); @@ -128,6 +129,7 @@ const QSize Buttonsize = QSize(35,35); //buttons used for gui QPushButton* CircleButton; QPushButton* FloodFillButton; +QPushButton* GradientButton; QPushButton* LineButton; QPushButton* PenButton; QPushButton* PlainButton; @@ -144,6 +146,7 @@ QLabel* WidthLine; QLabel* innerAlphaLine; QLabel* ActiveLayerLine; QLabel* ActiveLayerImageLabel; +QLabel* FastRendererLabel; //scroll area to display canvas QScrollArea* ScrollArea; @@ -192,6 +195,7 @@ QAction* actionCreateRectangleTool; QAction* actionCreateCircleTool; QAction* actionCreatePolygonTool; QAction* actionCreateFloodFillTool; +QAction* actionCreateGradientTool; // dimension actions QAction* actionChangeDim; diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 8df8ffe..1b4236b 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -39,7 +39,7 @@ LayerObject::LayerObject(const LayerObject& layer){ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QLabel(parent){ - this->Tool = new IntelliToolGradient(this,&colorPicker,&Toolsettings); + this->Tool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); activeLayer = -1; } @@ -275,6 +275,11 @@ void PaintingArea::createFloodFillTool(){ Tool = new IntelliToolFloodFill(this, &colorPicker, &Toolsettings); } +void PaintingArea::createGradientTool(){ + delete this->Tool; + Tool = new IntelliToolGradient(this, &colorPicker, &Toolsettings); +} + int PaintingArea::getWidthOfActive(){ return this->layerBundle[static_cast(activeLayer)].width; } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 9b81cb2..6aafff1 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -183,6 +183,7 @@ void createRectangleTool(); void createCircleTool(); void createPolygonTool(); void createFloodFillTool(); +void createGradientTool(); /*! * \brief The getWidthOfActive gets the horizontal dimensions of the active layer diff --git a/src/Tool/IntelliToolGradient.cpp b/src/Tool/IntelliToolGradient.cpp index 4ab3699..40cc8bb 100644 --- a/src/Tool/IntelliToolGradient.cpp +++ b/src/Tool/IntelliToolGradient.cpp @@ -1,15 +1,12 @@ #include "IntelliToolGradient.h" +#include "Layer/PaintingArea.h" +#include "math.h" #include IntelliToolGradient::IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ this->LineColor = QColor(0,0,0,255); this->hasMoved = false; - - A = QPoint(0,0); - B = QPoint(0,3); - VectorAB = QPoint(0,3); - computePixelColor(QPoint(2,1)); } IntelliToolGradient::~IntelliToolGradient(){ @@ -18,11 +15,14 @@ IntelliToolGradient::~IntelliToolGradient(){ void IntelliToolGradient::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); + doubleA[0] = static_cast(x); + doubleA[1] = static_cast(y); A = QPoint(x,y); B = QPoint(x,y); - VectorAB = QPoint(0,0); - //Canvas->image->drawPlain(colorPicker->getFirstColor); - //Canvas->image->drawPixel(A,LineColor); + VectorAB[0] = 0; + VectorAB[1] = 0; + Canvas->image->drawPlain(colorPicker->getFirstColor()); + Canvas->image->drawPixel(A,LineColor); } void IntelliToolGradient::onMouseRightPressed(int x, int y){ @@ -30,8 +30,12 @@ void IntelliToolGradient::onMouseRightPressed(int x, int y){ } void IntelliToolGradient::onMouseLeftReleased(int x, int y){ - if(!hasMoved && A != B){ - //Canvas->image->drawPlain(colorPicker->getFirstColor); + if(hasMoved && A != B){ + for(int i = 0; i < activeLayer->height; i++){ + for(int j = 0; j < activeLayer->width; j++){ + computePixelColor(QPoint(i,j)); + } + } } IntelliTool::onMouseLeftReleased(x,y); } @@ -43,6 +47,15 @@ void IntelliToolGradient::onMouseRightReleased(int x, int y){ void IntelliToolGradient::onMouseMoved(int x, int y){ hasMoved = true; B = QPoint(x,y); + VectorAB[0] = static_cast(B.x() - A.x()); + VectorAB[1] = static_cast(B.y() - A.y()); + this->Canvas->image->drawPlain(Qt::transparent); + for(int i = 0; i < activeLayer->height; i++){ + for(int j = 0; j < activeLayer->width; j++){ + computePixelColor(QPoint(i,j)); + } + } + Canvas->image->drawLine(A,B,LineColor,1); IntelliTool::onMouseMoved(x,y); } @@ -51,11 +64,59 @@ void IntelliToolGradient::onWheelScrolled(int value){ } void IntelliToolGradient::computePixelColor(QPoint Point){ - QPoint NormalVector = QPoint(VectorAB.y(),(-1*VectorAB.x())); - Point = Point - (dotProduct((Point - A),NormalVector) / dotProduct(NormalVector,NormalVector)) * NormalVector; - qDebug() << Point.y(); + double NormalVector[2]; + NormalVector[0] = VectorAB[1]; + NormalVector[1] = (-1*VectorAB[0]); + double doublePoint[2]; + doublePoint[0] = static_cast(Point.x()); + doublePoint[1] = static_cast(Point.y()); + double doublePointSubA[2]; + doublePointSubA[0] = doublePoint[0] - doubleA[0]; + doublePointSubA[1] = doublePoint[1] - doubleA[1]; + double Perpendicular[2]; + double PointSubADotNormal = dotProduct(doublePointSubA,NormalVector); + double NormalDotNormal = dotProduct(NormalVector,NormalVector); + Perpendicular[0] = doublePoint[0] - (PointSubADotNormal / NormalDotNormal) * NormalVector[0]; + Perpendicular[1] = doublePoint[1] - (PointSubADotNormal / NormalDotNormal) * NormalVector[1]; + double VectorAPoint[2]; + VectorAPoint[0] = static_cast(Perpendicular[0] - doubleA[0]); + VectorAPoint[1] = static_cast(Perpendicular[1] - doubleA[1]); + double ratio; + if(((VectorAPoint[0] < 0 && VectorAB[0] < 0) || (VectorAPoint[0] > 0 && VectorAB[0] > 0)) && ((VectorAPoint[1] < 0 && VectorAB[1] < 0) || (VectorAPoint[1] > 0 && VectorAB[1] > 0))) + ratio = lenghtVector(VectorAPoint)/lenghtVector(VectorAB); + else{ + ratio = -1; + } + QColor computedColor; + if(ratio < 0){ + computedColor = colorPicker->getFirstColor(); + } + else if(ratio > 1){ + computedColor = colorPicker->getSecondColor(); + } + else{ + int red; + int green; + int blue; + int alpha; + int red2; + int green2; + int blue2; + int alpha2; + colorPicker->getFirstColor().getRgb(&red,&green,&blue,&alpha); + colorPicker->getSecondColor().getRgb(&red2,&green2,&blue2,&alpha2); + computedColor.setRed(static_cast(ratio * red2 + (1 - ratio) * red)); + computedColor.setGreen(static_cast(ratio * green2 + (1 - ratio) * green)); + computedColor.setBlue(static_cast(ratio * blue2 + (1 - ratio) * blue)); + computedColor.setAlpha(static_cast(ratio * alpha2 + (1 - ratio) * alpha)); + } + Canvas->image->drawPixel(Point,computedColor); } -float IntelliToolGradient::dotProduct(QPoint Vector1, QPoint Vector2){ - return static_cast(Vector1.x()*Vector2.x()+Vector1.y()*Vector2.y()); +double IntelliToolGradient::dotProduct(double Vector1[2], double Vector2[2]){ + return static_cast(Vector1[0]*Vector2[0]+Vector1[1]*Vector2[1]); +} + +double IntelliToolGradient::lenghtVector(double Vector[2]){ + return static_cast((std::sqrt(Vector[0] * Vector[0] + Vector[1] * Vector[1]))); } diff --git a/src/Tool/IntelliToolGradient.h b/src/Tool/IntelliToolGradient.h index 80424a1..2e3f0ad 100644 --- a/src/Tool/IntelliToolGradient.h +++ b/src/Tool/IntelliToolGradient.h @@ -6,7 +6,8 @@ class IntelliToolGradient : public IntelliTool{ private: QPoint A; QPoint B; - QPoint VectorAB; + double VectorAB[2]; + double doubleA[2]; QColor LineColor; bool hasMoved; @@ -58,7 +59,9 @@ public: void computePixelColor(QPoint Point); - float dotProduct(QPoint Vector1, QPoint Vector2); + double dotProduct(double Vector1[2], double Vector2[2]); + + double lenghtVector(double Vector[2]); }; #endif // INTELLITOOLGRADIENT_H From 710848307fce6c16deade5564bdf6b0393c10bee Mon Sep 17 00:00:00 2001 From: AshBastian Date: Sun, 26 Jan 2020 18:43:14 +0100 Subject: [PATCH 3/5] Gradient Fertig --- knownBugs.txt | 4 ++- src/Tool/IntelliToolGradient.cpp | 44 ++++++++++++++++++++------------ src/Tool/IntelliToolGradient.h | 6 ++++- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/knownBugs.txt b/knownBugs.txt index 8314056..54b8e59 100644 --- a/knownBugs.txt +++ b/knownBugs.txt @@ -1 +1,3 @@ -history tool doesnt load polygon data on undo iff project was loaded \ No newline at end of file +history tool doesnt load polygon data on undo iff project was loaded +history tool doesnt save delete Layer +Gradient breaks Heap Size, when big Witdh and Height (appeared on 1280x720) \ No newline at end of file diff --git a/src/Tool/IntelliToolGradient.cpp b/src/Tool/IntelliToolGradient.cpp index 40cc8bb..6a52a5f 100644 --- a/src/Tool/IntelliToolGradient.cpp +++ b/src/Tool/IntelliToolGradient.cpp @@ -21,7 +21,6 @@ void IntelliToolGradient::onMouseLeftPressed(int x, int y){ B = QPoint(x,y); VectorAB[0] = 0; VectorAB[1] = 0; - Canvas->image->drawPlain(colorPicker->getFirstColor()); Canvas->image->drawPixel(A,LineColor); } @@ -30,14 +29,13 @@ void IntelliToolGradient::onMouseRightPressed(int x, int y){ } void IntelliToolGradient::onMouseLeftReleased(int x, int y){ - if(hasMoved && A != B){ - for(int i = 0; i < activeLayer->height; i++){ - for(int j = 0; j < activeLayer->width; j++){ - computePixelColor(QPoint(i,j)); - } - } + if(hasMoved){ + computeGradientLayer(); + IntelliTool::onMouseLeftReleased(x,y); + } + else{ + IntelliTool::onMouseRightPressed(x,y); } - IntelliTool::onMouseLeftReleased(x,y); } void IntelliToolGradient::onMouseRightReleased(int x, int y){ @@ -49,12 +47,11 @@ void IntelliToolGradient::onMouseMoved(int x, int y){ B = QPoint(x,y); VectorAB[0] = static_cast(B.x() - A.x()); VectorAB[1] = static_cast(B.y() - A.y()); + NormalVector[0] = VectorAB[1]; + NormalVector[1] = (-1*VectorAB[0]); + NormalDotNormal = dotProduct(NormalVector,NormalVector); this->Canvas->image->drawPlain(Qt::transparent); - for(int i = 0; i < activeLayer->height; i++){ - for(int j = 0; j < activeLayer->width; j++){ - computePixelColor(QPoint(i,j)); - } - } + computeGradientLayer(); Canvas->image->drawLine(A,B,LineColor,1); IntelliTool::onMouseMoved(x,y); } @@ -64,9 +61,6 @@ void IntelliToolGradient::onWheelScrolled(int value){ } void IntelliToolGradient::computePixelColor(QPoint Point){ - double NormalVector[2]; - NormalVector[0] = VectorAB[1]; - NormalVector[1] = (-1*VectorAB[0]); double doublePoint[2]; doublePoint[0] = static_cast(Point.x()); doublePoint[1] = static_cast(Point.y()); @@ -75,7 +69,6 @@ void IntelliToolGradient::computePixelColor(QPoint Point){ doublePointSubA[1] = doublePoint[1] - doubleA[1]; double Perpendicular[2]; double PointSubADotNormal = dotProduct(doublePointSubA,NormalVector); - double NormalDotNormal = dotProduct(NormalVector,NormalVector); Perpendicular[0] = doublePoint[0] - (PointSubADotNormal / NormalDotNormal) * NormalVector[0]; Perpendicular[1] = doublePoint[1] - (PointSubADotNormal / NormalDotNormal) * NormalVector[1]; double VectorAPoint[2]; @@ -120,3 +113,20 @@ double IntelliToolGradient::dotProduct(double Vector1[2], double Vector2[2]){ double IntelliToolGradient::lenghtVector(double Vector[2]){ return static_cast((std::sqrt(Vector[0] * Vector[0] + Vector[1] * Vector[1]))); } + +void IntelliToolGradient::computeGradientLayer(){ + bool switched = false; + if(Canvas->image->isFastRendering()){ + switched = true; + Canvas->image->updateRendererSetting(false); + } + qDebug() << activeLayer->width << activeLayer->height; + for(int i = 0; i < activeLayer->height; i++){ + for(int j = 0; j < activeLayer->width; j++){ + computePixelColor(QPoint(i,j)); + } + } + if(switched){ + Canvas->image->updateRendererSetting(true); + } +} diff --git a/src/Tool/IntelliToolGradient.h b/src/Tool/IntelliToolGradient.h index 2e3f0ad..50ee96b 100644 --- a/src/Tool/IntelliToolGradient.h +++ b/src/Tool/IntelliToolGradient.h @@ -6,8 +6,10 @@ class IntelliToolGradient : public IntelliTool{ private: QPoint A; QPoint B; - double VectorAB[2]; double doubleA[2]; + double VectorAB[2]; + double NormalVector[2]; + double NormalDotNormal; QColor LineColor; bool hasMoved; @@ -62,6 +64,8 @@ public: double dotProduct(double Vector1[2], double Vector2[2]); double lenghtVector(double Vector[2]); + + void computeGradientLayer(); }; #endif // INTELLITOOLGRADIENT_H From 657eba80f2131e408f1ff748108f2c4b6332565b Mon Sep 17 00:00:00 2001 From: AshBastian Date: Sun, 26 Jan 2020 18:57:30 +0100 Subject: [PATCH 4/5] Update Bug --- knownBugs.txt | 3 ++- src/Tool/IntelliToolGradient.cpp | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/knownBugs.txt b/knownBugs.txt index 54b8e59..824bf08 100644 --- a/knownBugs.txt +++ b/knownBugs.txt @@ -1,3 +1,4 @@ history tool doesnt load polygon data on undo iff project was loaded history tool doesnt save delete Layer -Gradient breaks Heap Size, when big Witdh and Height (appeared on 1280x720) \ No newline at end of file +Gradient breaks Heap Size, when big Witdh and Height (appeared on 1280x720) +Heap block at 0000000025422990 modified at 0000000025422A28 past requested size of 88 \ No newline at end of file diff --git a/src/Tool/IntelliToolGradient.cpp b/src/Tool/IntelliToolGradient.cpp index 6a52a5f..2b36494 100644 --- a/src/Tool/IntelliToolGradient.cpp +++ b/src/Tool/IntelliToolGradient.cpp @@ -120,10 +120,9 @@ void IntelliToolGradient::computeGradientLayer(){ switched = true; Canvas->image->updateRendererSetting(false); } - qDebug() << activeLayer->width << activeLayer->height; for(int i = 0; i < activeLayer->height; i++){ for(int j = 0; j < activeLayer->width; j++){ - computePixelColor(QPoint(i,j)); + computePixelColor(QPoint(j,i)); } } if(switched){ From eeceedab8ce5357bf9d5743c4f0e9beb0e05465e Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Sun, 26 Jan 2020 19:10:45 +0100 Subject: [PATCH 5/5] =?UTF-8?q?hotfix,=20rechtsklick=20bringte=20das=20pro?= =?UTF-8?q?gramm=20zum=20abst=C3=BCrzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tool/IntelliToolGradient.cpp | 27 +++++----- src/Tool/IntelliToolGradient.h | 93 ++++++++++++++++---------------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/Tool/IntelliToolGradient.cpp b/src/Tool/IntelliToolGradient.cpp index 2b36494..216e5f2 100644 --- a/src/Tool/IntelliToolGradient.cpp +++ b/src/Tool/IntelliToolGradient.cpp @@ -29,13 +29,10 @@ void IntelliToolGradient::onMouseRightPressed(int x, int y){ } void IntelliToolGradient::onMouseLeftReleased(int x, int y){ - if(hasMoved){ + if(hasMoved && this->isDrawing){ computeGradientLayer(); IntelliTool::onMouseLeftReleased(x,y); } - else{ - IntelliTool::onMouseRightPressed(x,y); - } } void IntelliToolGradient::onMouseRightReleased(int x, int y){ @@ -43,16 +40,18 @@ void IntelliToolGradient::onMouseRightReleased(int x, int y){ } void IntelliToolGradient::onMouseMoved(int x, int y){ - hasMoved = true; - B = QPoint(x,y); - VectorAB[0] = static_cast(B.x() - A.x()); - VectorAB[1] = static_cast(B.y() - A.y()); - NormalVector[0] = VectorAB[1]; - NormalVector[1] = (-1*VectorAB[0]); - NormalDotNormal = dotProduct(NormalVector,NormalVector); - this->Canvas->image->drawPlain(Qt::transparent); - computeGradientLayer(); - Canvas->image->drawLine(A,B,LineColor,1); + if(this->isDrawing){ + hasMoved = true; + B = QPoint(x,y); + VectorAB[0] = static_cast(B.x() - A.x()); + VectorAB[1] = static_cast(B.y() - A.y()); + NormalVector[0] = VectorAB[1]; + NormalVector[1] = (-1*VectorAB[0]); + NormalDotNormal = dotProduct(NormalVector,NormalVector); + this->Canvas->image->drawPlain(Qt::transparent); + computeGradientLayer(); + Canvas->image->drawLine(A,B,LineColor,1); + } IntelliTool::onMouseMoved(x,y); } diff --git a/src/Tool/IntelliToolGradient.h b/src/Tool/IntelliToolGradient.h index 50ee96b..01b0159 100644 --- a/src/Tool/IntelliToolGradient.h +++ b/src/Tool/IntelliToolGradient.h @@ -3,6 +3,53 @@ #include "IntelliTool.h" class IntelliToolGradient : public IntelliTool{ + +public: + IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); + + virtual ~IntelliToolGradient() override; + + /*! + * \brief A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseRightPressed(int x, int y) override; + + /*! + * \brief A function managing the right click Released of a Mouse. Merging the Canvas to Active. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseRightReleased(int x, int y) override; + + /*! + * \brief A function managing the left click Pressed of a Mouse. Resetting the current draw. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseLeftPressed(int x, int y) override; + + /*! + * \brief A function managing the left click Released of a Mouse. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseLeftReleased(int x, int y) override; + + /*! + * \brief A function managing the scroll event. A positive value means scrolling outwards. Call this in child classes! + * \param value - The absolute the scroll has changed. + */ + virtual void onWheelScrolled(int value) override; + + /*! + * \brief A function managing the mouse moved event. Call this in child classes! + * \param x - The x coordinate of the new mouse position. + * \param y - The y coordinate of the new mouse position. + */ + virtual void onMouseMoved(int x, int y) override; + private: QPoint A; QPoint B; @@ -13,52 +60,6 @@ private: QColor LineColor; bool hasMoved; -public: - IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); - - ~IntelliToolGradient(); - - /*! - * \brief A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on. Call this in child classes! - * \param x - The x coordinate relative to the active/canvas layer. - * \param y - The y coordinate relative to the active/canvas layer. - */ - virtual void onMouseRightPressed(int x, int y); - - /*! - * \brief A function managing the right click Released of a Mouse. Merging the Canvas to Active. Call this in child classes! - * \param x - The x coordinate relative to the active/canvas layer. - * \param y - The y coordinate relative to the active/canvas layer. - */ - virtual void onMouseRightReleased(int x, int y); - - /*! - * \brief A function managing the left click Pressed of a Mouse. Resetting the current draw. Call this in child classes! - * \param x - The x coordinate relative to the active/canvas layer. - * \param y - The y coordinate relative to the active/canvas layer. - */ - virtual void onMouseLeftPressed(int x, int y); - - /*! - * \brief A function managing the left click Released of a Mouse. Call this in child classes! - * \param x - The x coordinate relative to the active/canvas layer. - * \param y - The y coordinate relative to the active/canvas layer. - */ - virtual void onMouseLeftReleased(int x, int y); - - /*! - * \brief A function managing the scroll event. A positive value means scrolling outwards. Call this in child classes! - * \param value - The absolute the scroll has changed. - */ - virtual void onWheelScrolled(int value); - - /*! - * \brief A function managing the mouse moved event. Call this in child classes! - * \param x - The x coordinate of the new mouse position. - * \param y - The y coordinate of the new mouse position. - */ - virtual void onMouseMoved(int x, int y); - void computePixelColor(QPoint Point); double dotProduct(double Vector1[2], double Vector2[2]);