Tool anpassungen

This commit is contained in:
Sonaion
2019-12-19 13:54:17 +01:00
parent a3c19e9851
commit ec37be62fc
6 changed files with 74 additions and 87 deletions

View File

@@ -2,7 +2,7 @@
IntelliColorPicker::IntelliColorPicker(){ IntelliColorPicker::IntelliColorPicker(){
firstColor = {255,0,0,255}; firstColor = {255,0,0,255};
secondColor = {0,0,255,255}; secondColor = {0,255,255,255};
} }
IntelliColorPicker::~IntelliColorPicker(){ IntelliColorPicker::~IntelliColorPicker(){

View File

@@ -20,9 +20,7 @@
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
:QWidget(parent){ :QWidget(parent){
// Testing Area this->Tool = new IntelliToolPolygon(this, &colorPicker);
// test yout tool here and reset after accomplished test
this->Tool = new IntelliToolFloodFill(this, &colorPicker);
this->setUp(maxWidth, maxHeight); this->setUp(maxWidth, maxHeight);
this->addLayer(200,200,0,0,ImageType::Shaped_Image); this->addLayer(200,200,0,0,ImageType::Shaped_Image);
layerBundle[0].image->drawPlain(QColor(0,0,255,255)); layerBundle[0].image->drawPlain(QColor(0,0,255,255));
@@ -194,12 +192,12 @@ void PaintingArea::createLineTool(){
Tool = new IntelliToolLine(this, &colorPicker); Tool = new IntelliToolLine(this, &colorPicker);
} }
int PaintingArea::getWidthActiveLayer(){ int PaintingArea::getWidthOfActive(){
return layerBundle.operator[](activeLayer).width; return this->layerBundle[activeLayer].width;
} }
int PaintingArea::getHeightActiveLayer(){ int PaintingArea::getHeightOfActive(){
return layerBundle.operator[](activeLayer).hight; return this->layerBundle[activeLayer].hight;
} }
// If a mouse button is pressed check if it was the // If a mouse button is pressed check if it was the

View File

@@ -56,9 +56,8 @@ public:
void createPlainTool(); void createPlainTool();
void createLineTool(); void createLineTool();
//get Width and Height of active Layer int getWidthOfActive();
int getWidthActiveLayer(); int getHeightOfActive();
int getHeightActiveLayer();
public slots: public slots:
// Events to handle // Events to handle

View File

@@ -23,6 +23,9 @@ void IntelliToolFloodFill::onMouseRightReleased(int x, int y){
} }
void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())){
return;
}
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
QPoint start(x,y); QPoint start(x,y);
@@ -50,11 +53,11 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
Canvas->image->drawPixel(left,newColor); Canvas->image->drawPixel(left,newColor);
Q.push(left); 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); Canvas->image->drawPixel(top,newColor);
Q.push(top); 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); Canvas->image->drawPixel(down,newColor);
Q.push(down); Q.push(down);
} }

View File

@@ -2,43 +2,36 @@
#include "Layer/PaintingArea.h" #include "Layer/PaintingArea.h"
#include <QDebug> #include <QDebug>
#include <QCursor> #include <QCursor>
#include <QInputDialog>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ :IntelliTool(Area, colorPicker){
lineWidth = 5; this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
isDrawing = false; lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);;
PointIsNearStart = false; PointIsNearStart = false;
drawingPoint.setX(0); isDrawing = false;
drawingPoint.setY(0);
Point.setX(0);
Point.setY(0);
} }
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing){ if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
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);
IntelliTool::onMouseLeftPressed(x,y); 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->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
else if(isDrawing && isNearStart(x,y,QPointList.front())){ 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->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
else if(isDrawing){ else if(isDrawing){
drawingPoint.setX(x); QPoint drawingPoint(x,y);
drawingPoint.setY(y);
QPointList.push_back(drawingPoint); 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(); this->Canvas->image->calculateVisiblity();
} }
} }
@@ -52,29 +45,35 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(PointIsNearStart && QPointList.size() > 1){ if(PointIsNearStart && QPointList.size() > 1){
this->Canvas->image->calculateVisiblity();
PointIsNearStart = false; PointIsNearStart = false;
isDrawing = false; isDrawing = false;
Triangles = IntelliHelper::calculateTriangles(QPointList); std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
for(int i = 0; i < width; i++){ QPoint Point;
for(int j = 0; j < height; j++){ QColor colorTwo(colorPicker->getSecondColor());
Point.setX(i); colorTwo.setAlpha(alphaInner);
Point.setY(j); 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)){ if(IntelliHelper::isInPolygon(Triangles,Point)){
this->Canvas->image->drawPixel(QPoint(i,j), colorPicker->getFirstColor()); this->Canvas->image->drawPixel(Point, colorTwo);
} }
} }
} }
for(int i=0; i<QPointList.size(); i++){
int next = (i+1)%QPointList.size();
this->Canvas->image->drawLine(QPointList[i], QPointList[next], colorPicker->getFirstColor(), lineWidth);
}
QPointList.clear(); QPointList.clear();
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
} }
void IntelliToolPolygon::onMouseRightReleased(int x, int y){ void IntelliToolPolygon::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y);
} }
void IntelliToolPolygon::onWheelScrolled(int value){ void IntelliToolPolygon::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value);
if(!isDrawing){ if(!isDrawing){
if(lineWidth + value < 10){ if(lineWidth + value < 10){
lineWidth += value; lineWidth += value;
@@ -86,7 +85,7 @@ void IntelliToolPolygon::onWheelScrolled(int value){
} }
void IntelliToolPolygon::onMouseMoved(int x, int y){ void IntelliToolPolygon::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y);
} }
bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){

View File

@@ -10,6 +10,39 @@
*/ */
class IntelliToolPolygon : public IntelliTool 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<QPoint> QPointList;
public: public:
/*! /*!
* \brief IntelliToolPolygon Constructor Define the Tool-intern Parameters * \brief IntelliToolPolygon Constructor Define the Tool-intern Parameters
@@ -27,52 +60,7 @@ public:
virtual void onMouseMoved(int x, int y) override; 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<QPoint> QPointList;
/*!
* \brief Triangles Transformed QPointList into triangulated Form of the Polygon
*/
std::vector<Triangle> Triangles;
}; };