mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 04:10:31 +02:00
Merge branch 'dev' into UnitTesting
This commit is contained in:
@@ -24,10 +24,10 @@ void IntelliTool::onMouseRightReleased(int x, int y){
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseLeftPressed(int x, int y){
|
||||
this->isDrawing=this->createToolLayer();
|
||||
if(isDrawing){
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
this->isDrawing=this->createToolLayer();
|
||||
if(isDrawing) {
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseLeftReleased(int x, int y){
|
||||
@@ -36,6 +36,7 @@ void IntelliTool::onMouseLeftReleased(int x, int y){
|
||||
this->mergeToolLayer();
|
||||
this->deleteToolLayer();
|
||||
activeLayer->image->calculateVisiblity();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,22 +50,22 @@ void IntelliTool::onWheelScrolled(int value){
|
||||
}
|
||||
|
||||
bool IntelliTool::createToolLayer(){
|
||||
if(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)];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if(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)];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IntelliTool::mergeToolLayer(){
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
QImage updatedImage = activeLayer->image->getImageData();
|
||||
QImage updatedImage = activeLayer->image->getImageData();
|
||||
|
||||
for(int y=0; y<activeLayer->height; y++) {
|
||||
for(int x=0; x<activeLayer->width; x++) {
|
||||
clr_0=updatedImage.pixelColor(x,y);
|
||||
for(int x=0; x<activeLayer->width; x++) {
|
||||
clr_0=updatedImage.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);
|
||||
@@ -76,15 +77,18 @@ void IntelliTool::mergeToolLayer(){
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
|
||||
updatedImage.setPixelColor(x, y, clr_0);
|
||||
updatedImage.setPixelColor(x, y, clr_0);
|
||||
}
|
||||
}
|
||||
activeLayer->image->setImageData(updatedImage);
|
||||
Area->DummyGui->UpdateGui();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ void IntelliToolCircle::drawCircle(int radius){
|
||||
}
|
||||
|
||||
//TODO implement circle drawing algorithm bresenham
|
||||
radius = static_cast<int>(radius +(Toolsettings->getLineWidth()/2.));
|
||||
radius = static_cast<int>(radius +(Toolsettings->getLineWidth()/2.));
|
||||
yMin = (centerPoint.y()-radius);
|
||||
yMax = (centerPoint.y()+radius);
|
||||
for(int i=yMin; i<=yMax; i++) {
|
||||
@@ -56,12 +56,12 @@ void IntelliToolCircle::onMouseRightReleased(int x, int y){
|
||||
|
||||
void IntelliToolCircle::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
if(this->isDrawing){
|
||||
this->centerPoint=QPoint(x,y);
|
||||
int radius = 1;
|
||||
drawCircle(radius);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
if(this->isDrawing) {
|
||||
this->centerPoint=QPoint(x,y);
|
||||
int radius = 1;
|
||||
drawCircle(radius);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onMouseLeftReleased(int x, int y){
|
||||
|
||||
@@ -49,7 +49,7 @@ void IntelliToolLine::onMouseMoved(int x, int y){
|
||||
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;
|
||||
//TODO implement dotted algorithm
|
||||
//TODO implement dotted algorithm
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,60 +4,75 @@
|
||||
#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;
|
||||
drawingOfPolygon = false;
|
||||
drawingOfPolygon = false;
|
||||
isInside = false;
|
||||
this->isSettingPolygon = isSettingPolygon;
|
||||
this->ActiveType = Tooltype::POLYGON;
|
||||
}
|
||||
|
||||
IntelliToolPolygon::~IntelliToolPolygon(){
|
||||
if(drawingOfPolygon) {
|
||||
if(drawingOfPolygon) {
|
||||
IntelliTool::onMouseRightPressed(0,0);
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
if(!drawingOfPolygon && 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(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
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(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
isInside = true;
|
||||
}
|
||||
|
||||
if(isInside && !drawingOfPolygon) {
|
||||
if(isInside && !drawingOfPolygon) {
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
QPoint drawingPoint = QPoint(x,y);
|
||||
|
||||
drawingOfPolygon = true;
|
||||
drawingOfPolygon = true;
|
||||
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(drawingOfPolygon && isNearStart(x,y,QPointList.front())) {
|
||||
else if(drawingOfPolygon && 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;
|
||||
drawingOfPolygon = false;
|
||||
drawingOfPolygon = false;
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
}
|
||||
else if(drawingOfPolygon) {
|
||||
else if(drawingOfPolygon) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,25 +87,32 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||
if(isPointNearStart) {
|
||||
isInside = false;
|
||||
isPointNearStart = false;
|
||||
drawingOfPolygon = 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);
|
||||
isDrawing = false;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +122,7 @@ void IntelliToolPolygon::onMouseRightReleased(int x, int y){
|
||||
|
||||
void IntelliToolPolygon::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
if(!drawingOfPolygon) {
|
||||
if(!drawingOfPolygon) {
|
||||
Toolsettings->setLineWidth(Toolsettings->getLineWidth() + value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ bool drawingOfPolygon;
|
||||
*/
|
||||
bool isInside;
|
||||
|
||||
/*!
|
||||
* \brief isSettingPolygon is the flag for calling the setPolygon method.
|
||||
*/
|
||||
bool isSettingPolygon;
|
||||
|
||||
/*!
|
||||
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
||||
*/
|
||||
@@ -48,8 +53,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.
|
||||
*/
|
||||
@@ -96,7 +102,6 @@ virtual void onWheelScrolled(int value) override;
|
||||
*/
|
||||
virtual void onMouseMoved(int x, int y) override;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLPOLYGON_H
|
||||
|
||||
Reference in New Issue
Block a user