mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-13 03:40:31 +02:00
FloodFill
ist fertig
This commit is contained in:
@@ -15,11 +15,12 @@
|
||||
#include "Tool/IntelliToolLine.h"
|
||||
#include "Tool/IntelliToolCircle.h"
|
||||
#include "Tool/IntelliToolRectangle.h"
|
||||
#include "Tool/IntelliToolFloodFill.h"
|
||||
|
||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||
:QWidget(parent){
|
||||
//test yout tool here and reset after accomplished test
|
||||
this->Tool = new IntelliToolRectangle(this, &colorPicker);
|
||||
this->Tool = new IntelliToolFloodFill(this, &colorPicker);
|
||||
this->setUp(maxWidth, maxHeight);
|
||||
//tetsing
|
||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include "QColorDialog"
|
||||
#include "QInputDialog"
|
||||
#include <functional>
|
||||
#include <queue>
|
||||
|
||||
IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
@@ -22,11 +24,55 @@ void IntelliToolFloodFill::onMouseRightReleased(int x, int y){
|
||||
|
||||
void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Canvas->image->get
|
||||
auto depthsearch = [](int x, int y, LayerObject* Canvas){
|
||||
QColor oldColor = this->Active->image->getPixelColor(x,y);
|
||||
std::queue<QPoint> Q;
|
||||
Q.push(QPoint(x,y));
|
||||
QColor newColor = this->colorPicker->getFirstColor();
|
||||
Canvas->image->drawPixel(QPoint(x,y),newColor);
|
||||
while(!Q.empty()){
|
||||
QPoint Front = Q.front();
|
||||
Q.pop();
|
||||
if((Front.x()+1 < Canvas->width)&&
|
||||
(Active->image->getPixelColor(Front.x()+1,Front.y()) == oldColor)&&
|
||||
(Canvas->image->getPixelColor(Front.x()+1,Front.y()) != newColor)){
|
||||
Canvas->image->drawPixel(QPoint(Front.x()+1, Front.y()),newColor);
|
||||
Q.push(QPoint(Front.x()+1,Front.y()));
|
||||
}
|
||||
if((Front.x()-1 >= 0)&&
|
||||
(Active->image->getPixelColor(Front.x()-1,Front.y()) == oldColor)&&
|
||||
(Canvas->image->getPixelColor(Front.x()-1,Front.y()) != newColor)){
|
||||
Canvas->image->drawPixel(QPoint(Front.x()-1, Front.y()),newColor);
|
||||
Q.push(QPoint(Front.x()-1,Front.y()));
|
||||
}
|
||||
if((Front.y()+1 < Canvas->hight)&&
|
||||
(Active->image->getPixelColor(Front.x(),Front.y()+1) == oldColor)&&
|
||||
(Canvas->image->getPixelColor(Front.x(),Front.y()+1) != newColor)){
|
||||
Canvas->image->drawPixel(QPoint(Front.x(), Front.y()+1),newColor);
|
||||
Q.push(QPoint(Front.x(),Front.y()+1));
|
||||
}
|
||||
if((Front.y()-1 >= 0)&&
|
||||
(Active->image->getPixelColor(Front.x(),Front.y()-1) == oldColor)&&
|
||||
(Canvas->image->getPixelColor(Front.x(),Front.y()-1) != newColor)){
|
||||
Canvas->image->drawPixel(QPoint(Front.x(), Front.y()-1),newColor);
|
||||
Q.push(QPoint(Front.x(),Front.y()-1));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* std::function<void(int,int, LayerObject*, LayerObject*, QColor, QColor)> depthsearch =
|
||||
[&depthsearch](int x, int y,LayerObject* Active, LayerObject* Canvas, QColor oldColor, QColor newColor){
|
||||
if((x >= 0) && (y >= 0) && (x < Canvas->width) && (y < Canvas->hight)){
|
||||
if(Active->image->getPixelColor(x,y) == oldColor){
|
||||
Canvas->image->drawPoint(QPoint(x,y),newColor,1);
|
||||
depthsearch(x-1,y,Active,Canvas,oldColor,newColor);
|
||||
depthsearch(x,y+1,Active,Canvas,oldColor,newColor);
|
||||
depthsearch(x+1,y,Active,Canvas,oldColor,newColor);
|
||||
depthsearch(x,y-1,Active,Canvas,oldColor,newColor);
|
||||
}
|
||||
}
|
||||
};
|
||||
depthsearch(x,y,Active,Canvas,oldColor,this->colorPicker->getFirstColor());
|
||||
*/
|
||||
Canvas->image->calculateVisiblity();
|
||||
|
||||
|
||||
@@ -38,29 +84,9 @@ void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){
|
||||
|
||||
void IntelliToolFloodFill::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->lineWidth+=value;
|
||||
if(this->lineWidth<=0){
|
||||
this->lineWidth=1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void IntelliToolFloodFill::onMouseMoved(int x, int y){
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
if(this->drawing){
|
||||
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);
|
||||
break;
|
||||
case LineStyle::DOTTED_LINE:
|
||||
QPoint p1 =start.x() <= next.x() ? start : next;
|
||||
QPoint p2 =start.x() < next.x() ? next : start;
|
||||
int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f;
|
||||
int c = start.y()-start.x()*m;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user