Merge branch 'dev' into dev-colorpalette

This commit is contained in:
Jan Schuffenhauer
2020-01-16 00:11:24 +01:00
9 changed files with 237 additions and 146 deletions

View File

@@ -36,6 +36,7 @@ void IntelliTool::onMouseLeftReleased(int x, int y){
this->mergeToolLayer();
this->deleteToolLayer();
activeLayer->image->calculateVisiblity();
}
}
@@ -81,11 +82,14 @@ void IntelliTool::mergeToolLayer(){
}
}
activeLayer->image->setImageData(updatedImage);
if(Canvas->image->getPolygonData().size() > 0) {
activeLayer->image->setPolygon(Canvas->image->getPolygonData());
}
Area->DummyGui->UpdateGui();
}
void IntelliTool::deleteToolLayer(){
Area->deleteLayer(Area->activeLayer+1);
Area->deleteLayer(Area->activeLayer+1, true);
this->Canvas=nullptr;
}

View File

@@ -4,11 +4,12 @@
#include <QInputDialog>
#include <QDebug>
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;
}
@@ -20,9 +21,17 @@ IntelliToolPolygon::~IntelliToolPolygon(){
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y);
isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
if(Area->getPolygonDataOfRealLayer().size()>2) {
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y);
isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
}
else{
isInside = true;
}
if(isSettingPolygon) {
isInside = true;
}
}
else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
isInside = true;
@@ -36,13 +45,17 @@ 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;
@@ -56,7 +69,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,24 +88,31 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
isInside = false;
isPointNearStart = false;
isDrawing = false;
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
QPoint Point;
QColor colorTwo(colorPicker->getSecondColor());
colorTwo.setAlpha(Toolsettings->getInnerAlpha());
for(int i = 0; i < activeLayer->width; i++) {
for(int j = 0; j < activeLayer->height; j++) {
Point = QPoint(i,j);
if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
this->Canvas->image->drawPixel(Point, colorTwo);
if(!isSettingPolygon) {
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
QPoint Point;
QColor colorTwo(colorPicker->getSecondColor());
colorTwo.setAlpha(Toolsettings->getInnerAlpha());
for(int i = 0; i < activeLayer->width; i++) {
for(int j = 0; j < activeLayer->height; j++) {
Point = QPoint(i,j);
if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
this->Canvas->image->drawPixel(Point, colorTwo);
}
}
}
for(int i=0; i<static_cast<int>(QPointList.size()); i++) {
int next = static_cast<int>((i+static_cast<int>(1))%static_cast<int>(QPointList.size()));
this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
}
}
for(int i=0; i<static_cast<int>(QPointList.size()); i++) {
int next = static_cast<int>((i+static_cast<int>(1))%static_cast<int>(QPointList.size()));
this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
else{
Canvas->image->setPolygon(QPointList);
Canvas->image->setImageData(Area->getImageDataOfActiveLayer());
}
QPointList.clear();
IntelliTool::onMouseLeftReleased(x,y);
QPointList.clear();
}
}

View File

@@ -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.
*/
@@ -91,7 +97,6 @@ virtual void onWheelScrolled(int value) override;
*/
virtual void onMouseMoved(int x, int y) override;
};
#endif // INTELLITOOLPOLYGON_H