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(){
firstColor = {255,0,0,255};
secondColor = {0,0,255,255};
secondColor = {0,255,255,255};
}
IntelliColorPicker::~IntelliColorPicker(){

View File

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

View File

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

View File

@@ -23,6 +23,9 @@ void IntelliToolFloodFill::onMouseRightReleased(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);
QPoint start(x,y);
@@ -50,11 +53,11 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
Canvas->image->drawPixel(left,newColor);
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);
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);
Q.push(down);
}

View File

@@ -2,43 +2,36 @@
#include "Layer/PaintingArea.h"
#include <QDebug>
#include <QCursor>
#include <QInputDialog>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){
lineWidth = 5;
isDrawing = false;
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;
drawingPoint.setX(0);
drawingPoint.setY(0);
Point.setX(0);
Point.setY(0);
isDrawing = false;
}
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing){
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);
if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
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->calculateVisiblity();
}
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->calculateVisiblity();
}
else if(isDrawing){
drawingPoint.setX(x);
drawingPoint.setY(y);
QPoint drawingPoint(x,y);
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();
}
}
@@ -52,29 +45,35 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(PointIsNearStart && QPointList.size() > 1){
this->Canvas->image->calculateVisiblity();
PointIsNearStart = false;
isDrawing = false;
Triangles = IntelliHelper::calculateTriangles(QPointList);
for(int i = 0; i < width; i++){
for(int j = 0; j < height; j++){
Point.setX(i);
Point.setY(j);
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->hight; j++){
Point = QPoint(i,j);
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();
IntelliTool::onMouseLeftReleased(x,y);
}
}
void IntelliToolPolygon::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y);
}
void IntelliToolPolygon::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value);
if(!isDrawing){
if(lineWidth + value < 10){
lineWidth += value;
@@ -86,7 +85,7 @@ void IntelliToolPolygon::onWheelScrolled(int value){
}
void IntelliToolPolygon::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y);
}
bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){

View File

@@ -10,6 +10,39 @@
*/
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:
/*!
* \brief IntelliToolPolygon Constructor Define the Tool-intern Parameters
@@ -27,52 +60,7 @@ public:
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;
};