Updated it works kinda

TOdo: fix BUGS
This commit is contained in:
Jan Schuffenhauer
2020-01-15 12:35:29 +01:00
parent 2a1561ecfb
commit f575da20d7
6 changed files with 86 additions and 31 deletions

View File

@@ -27,14 +27,17 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
} }
void IntelliShapedImage::calculateVisiblity(){ void IntelliShapedImage::calculateVisiblity(){
if(fastRenderering) { if(polygonData.size()<2){
return;
}
if(fastRenderering) {
this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); this->imageData = imageData.convertToFormat(QImage::Format_ARGB32);
} }
if(polygonData.size()<=2) { if(polygonData.size()<=2) {
QColor clr; QColor clr;
for(int y=0; y<imageData.height(); y++) { for(int y=0; y<imageData.height(); y++) {
for(int x=0; x<imageData.width(); x++) { for(int x=0; x<imageData.width(); x++) {
clr = imageData.pixel(x,y); clr = imageData.pixel(x,y);
clr.setAlpha(255); clr.setAlpha(255);
imageData.setPixelColor(x,y,clr); imageData.setPixelColor(x,y,clr);
@@ -52,7 +55,7 @@ void IntelliShapedImage::calculateVisiblity(){
clr = imageData.pixelColor(x,y); clr = imageData.pixelColor(x,y);
bool isInPolygon = IntelliTriangulation::isInPolygon(triangles, ptr); bool isInPolygon = IntelliTriangulation::isInPolygon(triangles, ptr);
if(isInPolygon) { if(isInPolygon) {
clr.setAlpha(std::min(255, clr.alpha())); clr.setAlpha(std::min(255, clr.alpha()));
}else{ }else{
clr.setAlpha(0); clr.setAlpha(0);
} }
@@ -91,6 +94,19 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
this->polygonData.push_back(QPoint(element.x(), element.y())); this->polygonData.push_back(QPoint(element.x(), element.y()));
} }
triangles = IntelliTriangulation::calculateTriangles(polygonData); triangles = IntelliTriangulation::calculateTriangles(polygonData);
if(fastRenderering){
imageData = imageData.convertToFormat(QImage::Format_ARGB32);
}
for(int y = 0; y<imageData.height(); y++) {
for(int x = 0; x<imageData.width(); x++) {
QColor clr = imageData.pixelColor(x,y);
clr.setAlpha(255);
imageData.setPixelColor(x,y,clr);
}
}
if(fastRenderering){
imageData = imageData.convertToFormat(QImage::Format_Indexed8);
}
} }
calculateVisiblity(); calculateVisiblity();
return; return;

View File

@@ -113,7 +113,8 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){
void PaintingArea::setPolygon(int idx){ void PaintingArea::setPolygon(int idx){
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) { if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){ if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){
qDebug() << "Todo Implement here set Polygon"; delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
} }
} }
} }
@@ -438,5 +439,20 @@ IntelliImage* PaintingArea::getImageOfActiveLayer(){
if(activeLayer<0) { if(activeLayer<0) {
return nullptr; return nullptr;
} }
return layerBundle[activeLayer].image; return layerBundle[static_cast<size_t>(activeLayer)].image;
}
QImage PaintingArea::getImageDataOfActiveLayer(){
QImage returnImage;
if(activeLayer<0) {
returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
returnImage.fill(QColor(255,255,255,255));
}
else{
returnImage = layerBundle[static_cast<size_t>(activeLayer)].image->getImageData();
if(renderSettings.isFastRenderering()){
returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
}
}
return returnImage;
} }

View File

@@ -182,6 +182,12 @@ int getNumberOfActiveLayer();
IntelliImage* getImageOfActiveLayer(); IntelliImage* getImageOfActiveLayer();
/*!
* \brief getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer it return a 10*10 white picture)
* \return return the image as an rgba32bit qImage
*/
QImage getImageDataOfActiveLayer();
IntelliToolsettings Toolsettings; IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker; IntelliColorPicker colorPicker;

View File

@@ -33,7 +33,7 @@ void IntelliTool::onMouseLeftPressed(int x, int y){
void IntelliTool::onMouseLeftReleased(int x, int y){ void IntelliTool::onMouseLeftReleased(int x, int y){
if(isDrawing) { if(isDrawing) {
isDrawing=false; isDrawing=false;
this->mergeToolLayer(); this->mergeToolLayer();
this->deleteToolLayer(); this->deleteToolLayer();
activeLayer->image->calculateVisiblity(); activeLayer->image->calculateVisiblity();
} }
@@ -62,25 +62,25 @@ void IntelliTool::mergeToolLayer(){
QColor clr_1; QColor clr_1;
QImage updatedImage = activeLayer->image->getImageData(); QImage updatedImage = activeLayer->image->getImageData();
for(int y=0; y<activeLayer->height; y++) { for(int y=0; y<activeLayer->height; y++) {
for(int x=0; x<activeLayer->width; x++) { for(int x=0; x<activeLayer->width; x++) {
clr_0=updatedImage.pixelColor(x,y); clr_0=updatedImage.pixelColor(x,y);
clr_1=Canvas->image->imageData.pixelColor(x,y); clr_1=Canvas->image->imageData.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f; 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); int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f); int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f); int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
clr_0.setRed(r); clr_0.setRed(r);
clr_0.setGreen(g); clr_0.setGreen(g);
clr_0.setBlue(b); clr_0.setBlue(b);
clr_0.setAlpha(a); clr_0.setAlpha(a);
updatedImage.setPixelColor(x, y, clr_0); updatedImage.setPixelColor(x, y, clr_0);
} }
} }
activeLayer->image->setImageData(updatedImage); activeLayer->image->setImageData(updatedImage);
if(Canvas->image->getPolygonData().size() != 0){ if(Canvas->image->getPolygonData().size() > 0){
activeLayer->image->setPolygon(Canvas->image->getPolygonData()); activeLayer->image->setPolygon(Canvas->image->getPolygonData());
} }
Area->DummyGui->UpdateGui(); Area->DummyGui->UpdateGui();

View File

@@ -4,11 +4,12 @@
#include <QInputDialog> #include <QInputDialog>
#include <QDebug> #include <QDebug>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon)
: IntelliTool(Area, colorPicker, Toolsettings){ : IntelliTool(Area, colorPicker, Toolsettings){
isPointNearStart = false; isPointNearStart = false;
isDrawing = false; isDrawing = false;
isInside = false; isInside = false;
this->isSettingPolygon = isSettingPolygon;
this->ActiveType = Tooltype::POLYGON; this->ActiveType = Tooltype::POLYGON;
} }
@@ -19,10 +20,13 @@ IntelliToolPolygon::~IntelliToolPolygon(){
} }
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) { 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()); std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y); QPoint Point(x,y);
isInside = IntelliTriangulation::isInPolygon(Triangles,Point); isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
if(isSettingPolygon){
isInside = true;
}
} }
else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) { else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
isInside = true; isInside = true;
@@ -36,14 +40,18 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
QPointList.push_back(drawingPoint); QPointList.push_back(drawingPoint);
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); 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())) { else if(isDrawing && isNearStart(x,y,QPointList.front())) {
if(QPointList.size() > 2) { if(QPointList.size() > 2) {
isPointNearStart = true; isPointNearStart = true;
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
this->Canvas->image->calculateVisiblity(); if(!isSettingPolygon){
} this->Canvas->image->calculateVisiblity();
}
}
else{ else{
isInside = false; isInside = false;
isDrawing = false; isDrawing = false;
@@ -56,7 +64,9 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
QPoint drawingPoint(x,y); QPoint drawingPoint(x,y);
QPointList.push_back(drawingPoint); QPointList.push_back(drawingPoint);
this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); 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,7 +83,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
isInside = false; isInside = false;
isPointNearStart = false; isPointNearStart = false;
isDrawing = false; isDrawing = false;
if(false){ if(!isSettingPolygon){
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList); std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
QPoint Point; QPoint Point;
QColor colorTwo(colorPicker->getSecondColor()); QColor colorTwo(colorPicker->getSecondColor());
@@ -94,6 +104,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
} }
else{ else{
Canvas->image->setPolygon(QPointList); Canvas->image->setPolygon(QPointList);
Canvas->image->setImageData(Area->getImageDataOfActiveLayer());
} }
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
QPointList.clear(); QPointList.clear();

View File

@@ -29,6 +29,11 @@ bool isDrawing;
*/ */
bool isInside; bool isInside;
/*!
* \brief isSettingPolygon is the flag for calling the setPolygon method.
*/
bool isSettingPolygon;
/*! /*!
* \brief PointIsNearStart true, when last click near startpoint, else false. * \brief PointIsNearStart true, when last click near startpoint, else false.
*/ */
@@ -43,8 +48,9 @@ public:
* \brief A constructor setting the general paintingArea and colorPicker. * \brief A constructor setting the general paintingArea and colorPicker.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker 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. * \brief A Destructor.
*/ */