Merge branch 'dev-variable-refractor' into dev

This commit is contained in:
2019-12-20 10:13:59 +01:00
23 changed files with 154 additions and 153 deletions

View File

@@ -12,8 +12,8 @@ IntelliTool::~IntelliTool(){
}
void IntelliTool::onMouseRightPressed(int x, int y){
if(drawing) {
drawing=false;
if(isDrawing) {
isDrawing=false;
this->deleteToolLayer();
}
}
@@ -23,23 +23,23 @@ void IntelliTool::onMouseRightReleased(int x, int y){
}
void IntelliTool::onMouseLeftPressed(int x, int y){
this->drawing=true;
this->isDrawing=true;
//create drawing layer
this->createToolLayer();
Canvas->image->calculateVisiblity();
}
void IntelliTool::onMouseLeftReleased(int x, int y){
if(drawing) {
drawing=false;
if(isDrawing) {
isDrawing=false;
this->mergeToolLayer();
this->deleteToolLayer();
Active->image->calculateVisiblity();
activeLayer->image->calculateVisiblity();
}
}
void IntelliTool::onMouseMoved(int x, int y){
if(drawing)
if(isDrawing)
Canvas->image->calculateVisiblity();
}
@@ -48,17 +48,17 @@ void IntelliTool::onWheelScrolled(int value){
}
void IntelliTool::createToolLayer(){
Area->createTempLayerAfter(Area->activeLayer);
this->Active=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
Area->createTempTopLayer(Area->activeLayer);
this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
}
void IntelliTool::mergeToolLayer(){
QColor clr_0;
QColor clr_1;
for(int y=0; y<Active->height; y++) {
for(int x=0; x<Active->width; x++) {
clr_0=Active->image->imageData.pixelColor(x,y);
for(int y=0; y<activeLayer->height; y++) {
for(int x=0; x<activeLayer->width; x++) {
clr_0=activeLayer->image->imageData.pixelColor(x,y);
clr_1=Canvas->image->imageData.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f;
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
@@ -70,7 +70,7 @@ void IntelliTool::mergeToolLayer(){
clr_0.setBlue(b);
clr_0.setAlpha(a);
Active->image->imageData.setPixelColor(x, y, clr_0);
activeLayer->image->imageData.setPixelColor(x, y, clr_0);
}
}
}

View File

@@ -40,7 +40,7 @@ IntelliColorPicker* colorPicker;
/*!
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
*/
LayerObject* Active;
LayerObject* activeLayer;
/*!
* \brief A pointer to the drawing canvas of the tool, work on this.
@@ -50,7 +50,7 @@ LayerObject* Canvas;
/*!
* \brief A flag checking if the user is currently drawing or not.
*/
bool drawing = false;
bool isDrawing = false;
public:
/*!

View File

@@ -5,46 +5,46 @@
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
}
IntelliToolCircle::~IntelliToolCircle(){
}
void IntelliToolCircle::drawCyrcle(int radius){
void IntelliToolCircle::drawCircle(int radius){
int outer = radius+20;
QColor inner = this->colorPicker->getSecondColor();
inner.setAlpha(alphaInner);
inner.setAlpha(innerAlpha);
int yMin, yMax, xMin, xMax;
yMin = Middle.y()-radius;
yMax = Middle.y()+radius;
yMin = centerPoint.y()-radius;
yMax = centerPoint.y()+radius;
// x = x0+-sqrt(r2-(y-y0)2)
for(int i=yMin; i<=yMax; i++) {
xMin = static_cast<int>(Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
xMax = static_cast<int>(Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
xMin = static_cast<int>(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
xMax = static_cast<int>(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
}
//TODO implement circle drawing algorithm bresenham
radius = static_cast<int>(radius +(this->edgeWidth/2.)-1.);
yMin = (Middle.y()-radius);
yMax = (Middle.y()+radius);
radius = static_cast<int>(radius +(this->borderWidth/2.)-1.);
yMin = (centerPoint.y()-radius);
yMax = (centerPoint.y()+radius);
for(int i=yMin; i<=yMax; i++) {
xMin = static_cast<int>(Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
xMax = static_cast<int>(Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth);
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
xMin = static_cast<int>(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
xMax = static_cast<int>(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),borderWidth);
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),borderWidth);
}
xMin = (Middle.x()-radius);
xMax = (Middle.x()+radius);
xMin = (centerPoint.x()-radius);
xMax = (centerPoint.x()+radius);
for(int i=xMin; i<=xMax; i++) {
int yMin = static_cast<int>(Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2)));
int yMax = static_cast<int>(Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2)));
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth);
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
int yMin = static_cast<int>(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
int yMax = static_cast<int>(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),borderWidth);
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),borderWidth);
}
}
@@ -58,9 +58,9 @@ void IntelliToolCircle::onMouseRightReleased(int x, int y){
void IntelliToolCircle::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->Middle=QPoint(x,y);
this->centerPoint=QPoint(x,y);
int radius = 1;
drawCyrcle(radius);
drawCircle(radius);
Canvas->image->calculateVisiblity();
}
@@ -70,18 +70,18 @@ void IntelliToolCircle::onMouseLeftReleased(int x, int y){
void IntelliToolCircle::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value);
this->edgeWidth+=value;
if(this->edgeWidth<=0) {
this->edgeWidth=1;
this->borderWidth+=value;
if(this->borderWidth<=0) {
this->borderWidth=1;
}
}
void IntelliToolCircle::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y);
int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
drawCyrcle(radius);
int radius = static_cast<int>(sqrt(pow((centerPoint.x()-x),2)+pow((centerPoint.y()-y),2)));
drawCircle(radius);
}
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -12,22 +12,22 @@ class IntelliToolCircle : public IntelliTool {
* \brief A function that implements a circle drawing algorithm.
* \param radius - The radius of the circle.
*/
void drawCyrcle(int radius);
void drawCircle(int radius);
/*!
* \brief The center of the circle.
*/
QPoint Middle;
QPoint centerPoint;
/*!
* \brief The alpha value of the inner circle.
*/
int alphaInner;
int innerAlpha;
/*!
* \brief The width of the outer circle edge.
*/
int edgeWidth;
int borderWidth;
public:
/*!
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and edgeWidth.

View File

@@ -31,7 +31,7 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
std::queue<QPoint> Q;
Q.push(start);
QColor oldColor = this->Active->image->getPixelColor(start);
QColor oldColor = this->activeLayer->image->getPixelColor(start);
QColor newColor = this->colorPicker->getFirstColor();
Canvas->image->drawPixel(start,newColor);
@@ -44,19 +44,19 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
right = QPoint(Current.x()+1,Current.y() );
top = QPoint(Current.x(),Current.y()-1);
down = QPoint(Current.x(),Current.y()+1);
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)) {
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (activeLayer->image->getPixelColor(right) == oldColor)) {
Canvas->image->drawPixel(right,newColor);
Q.push(right);
}
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)) {
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (activeLayer->image->getPixelColor(left) == oldColor)) {
Canvas->image->drawPixel(left,newColor);
Q.push(left);
}
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)) {
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (activeLayer->image->getPixelColor(top) == oldColor)) {
Canvas->image->drawPixel(top,newColor);
Q.push(top);
}
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)) {
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (activeLayer->image->getPixelColor(down) == oldColor)) {
Canvas->image->drawPixel(down,newColor);
Q.push(down);
}

View File

@@ -24,8 +24,8 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){
void IntelliToolLine::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->start=QPoint(x,y);
this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
this->lineStartingPoint=QPoint(x,y);
this->Canvas->image->drawPoint(lineStartingPoint, colorPicker->getFirstColor(),lineWidth);
Canvas->image->calculateVisiblity();
}
@@ -42,18 +42,18 @@ void IntelliToolLine::onWheelScrolled(int value){
}
void IntelliToolLine::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y);
switch(lineStyle) {
case LineStyle::SOLID_LINE:
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),lineWidth);
break;
case LineStyle::DOTTED_LINE:
QPoint p1 =start.x() <= next.x() ? start : next;
QPoint p2 =start.x() < next.x() ? next : start;
int m = static_cast<int>((p2.y()-p1.y())/(p2.x()-p1.x())+0.5f);
int c = start.y()-start.x()*m;
QPoint p1 =lineStartingPoint.x() <= next.x() ? lineStartingPoint : next;
QPoint p2 =lineStartingPoint.x() < next.x() ? next : lineStartingPoint;
int m = static_cast<int>(static_cast<float>(p2.y()-p1.y())/static_cast<float>(p2.x()-p1.x())+0.5f);
int c = lineStartingPoint.y()-lineStartingPoint.x()*m;
break;
}

View File

@@ -19,7 +19,7 @@ class IntelliToolLine : public IntelliTool {
/*!
* \brief The starting point of the line.
*/
QPoint start;
QPoint lineStartingPoint;
/*!
* \brief The width of the line to draw.

View File

@@ -23,8 +23,8 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){
void IntelliToolPen::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->point=QPoint(x,y);
this->Canvas->image->drawPixel(point, colorPicker->getFirstColor());
this->previousPoint=QPoint(x,y);
this->Canvas->image->drawPixel(previousPoint, colorPicker->getFirstColor());
Canvas->image->calculateVisiblity();
}
@@ -33,10 +33,10 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){
}
void IntelliToolPen::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
QPoint newPoint(x,y);
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
this->point=newPoint;
this->Canvas->image->drawLine(this->previousPoint, newPoint, colorPicker->getFirstColor(), penWidth);
this->previousPoint=newPoint;
}
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -15,7 +15,7 @@ int penWidth;
/*!
* \brief point - Represents the previous point to help drawing a line.
*/
QPoint point;
QPoint previousPoint;
public:
/*!
* \brief A constructor setting the general paintingArea and colorPicker. Reading the penWidth.

View File

@@ -6,9 +6,9 @@
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
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;
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
isPointNearStart = false;
isDrawing = false;
}
@@ -28,7 +28,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
this->Canvas->image->calculateVisiblity();
}
else if(isDrawing && isNearStart(x,y,QPointList.front())) {
PointIsNearStart = true;
isPointNearStart = true;
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity();
}
@@ -42,21 +42,21 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
isDrawing = false;
PointIsNearStart = false;
isPointNearStart = false;
QPointList.clear();
IntelliTool::onMouseRightPressed(x,y);
}
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(PointIsNearStart && QPointList.size() > 1) {
PointIsNearStart = false;
if(isPointNearStart && QPointList.size() > 1) {
isPointNearStart = false;
isDrawing = false;
std::vector<Triangle> 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->height; j++) {
colorTwo.setAlpha(innerAlpha);
for(int i = 0; i < activeLayer->width; i++) {
for(int j = 0; j < activeLayer->height; j++) {
Point = QPoint(i,j);
if(IntelliHelper::isInPolygon(Triangles,Point)) {
this->Canvas->image->drawPixel(Point, colorTwo);

View File

@@ -32,12 +32,12 @@ bool isDrawing;
/*!
* \brief PointIsNearStart true, when last click near startpoint, else false.
*/
bool PointIsNearStart;
bool isPointNearStart;
/*!
* \brief The alpha value of the inner circle.
*/
int alphaInner;
int innerAlpha;
/*!
* \brief QPointList list of all points of the polygon.

View File

@@ -4,30 +4,30 @@
IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
}
IntelliToolRectangle::~IntelliToolRectangle(){
}
void IntelliToolRectangle::drawRectangle(QPoint otherCornor){
int xMin = std::min(originCornor.x(), otherCornor.x());
int xMax = std::max(originCornor.x(), otherCornor.x());
void IntelliToolRectangle::drawRectangle(QPoint otherCorner){
int xMin = std::min(originCorner.x(), otherCorner.x());
int xMax = std::max(originCorner.x(), otherCorner.x());
int yMin = std::min(originCornor.y(), otherCornor.y());
int yMax = std::max(originCornor.y(), otherCornor.y());
int yMin = std::min(originCorner.y(), otherCorner.y());
int yMax = std::max(originCorner.y(), otherCorner.y());
QColor clr = colorPicker->getSecondColor();
clr.setAlpha(alphaInner);
clr.setAlpha(innerAlpha);
for(int y=yMin; y<=yMax; y++) {
this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1);
}
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth);
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth);
}
void IntelliToolRectangle::onMouseRightPressed(int x, int y){
@@ -40,8 +40,8 @@ void IntelliToolRectangle::onMouseRightReleased(int x, int y){
void IntelliToolRectangle::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->originCornor=QPoint(x,y);
drawRectangle(originCornor);
this->originCorner=QPoint(x,y);
drawRectangle(originCorner);
Canvas->image->calculateVisiblity();
}
@@ -50,7 +50,7 @@ void IntelliToolRectangle::onMouseLeftReleased(int x, int y){
}
void IntelliToolRectangle::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y);
drawRectangle(next);
@@ -60,8 +60,8 @@ void IntelliToolRectangle::onMouseMoved(int x, int y){
void IntelliToolRectangle::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value);
this->edgeWidth+=value;
if(this->edgeWidth<=0) {
this->edgeWidth=1;
this->borderWidth+=value;
if(this->borderWidth<=0) {
this->borderWidth=1;
}
}

View File

@@ -11,22 +11,22 @@
class IntelliToolRectangle : public IntelliTool {
/*!
* \brief A function that implements a rectagle drawing algorithm.
* \param otherCornor - The second corner point of the rectangle.
* \param othercorner - The second corner point of the rectangle.
*/
void drawRectangle(QPoint otherCornor);
void drawRectangle(QPoint otherCorner);
/*!
* \brief originCornor - The first corner point of the rectangle.
* \brief origincorner - The first corner point of the rectangle.
*/
QPoint originCornor;
QPoint originCorner;
/*!
* \brief alphaInner- Represents the alpha value of the inside.
*/
int alphaInner;
int innerAlpha;
/*!
* \brief edgeWidth - The width of the rectangle edges.
*/
int edgeWidth;
int borderWidth;
public:
/*!
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the alphaInner and edgeWidth.