mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 20:30:32 +02:00
Polygon Fixes
Polygon kann jetzt im Shaped-Image nicht außerhalb des Polygons gestartet werden
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
IntelliImage::IntelliImage(int weight, int height)
|
IntelliImage::IntelliImage(int weight, int height)
|
||||||
: imageData(QSize(weight, height), QImage::Format_ARGB32){
|
: imageData(QSize(weight, height), QImage::Format_ARGB32){
|
||||||
imageData.fill(QColor(255,255,255,255));
|
imageData.fill(QColor(255,255,255,255));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IntelliImage::~IntelliImage(){
|
IntelliImage::~IntelliImage(){
|
||||||
|
|||||||
@@ -8,13 +8,7 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/*!
|
#include "IntelliHelper/IntelliHelper.h"
|
||||||
* \brief The Types, which an Image can be.
|
|
||||||
*/
|
|
||||||
enum class ImageType {
|
|
||||||
Raster_Image,
|
|
||||||
Shaped_Image
|
|
||||||
};
|
|
||||||
|
|
||||||
class IntelliTool;
|
class IntelliTool;
|
||||||
|
|
||||||
@@ -23,6 +17,16 @@ class IntelliTool;
|
|||||||
*/
|
*/
|
||||||
class IntelliImage {
|
class IntelliImage {
|
||||||
friend IntelliTool;
|
friend IntelliTool;
|
||||||
|
public:
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The Types, which an Image can be.
|
||||||
|
*/
|
||||||
|
enum class ImageType {
|
||||||
|
Raster_Image,
|
||||||
|
Shaped_Image
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeImage(QImage*image, const QSize &newSize);
|
void resizeImage(QImage*image, const QSize &newSize);
|
||||||
|
|
||||||
@@ -30,6 +34,11 @@ void resizeImage(QImage*image, const QSize &newSize);
|
|||||||
* \brief The underlying image data.
|
* \brief The underlying image data.
|
||||||
*/
|
*/
|
||||||
QImage imageData;
|
QImage imageData;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The Type, an Image is.
|
||||||
|
*/
|
||||||
|
ImageType TypeOfImage;
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
|
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
|
||||||
@@ -114,6 +123,10 @@ virtual std::vector<QPoint> getPolygonData(){
|
|||||||
return std::vector<QPoint>();
|
return std::vector<QPoint>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ImageType getTypeOfImage(){
|
||||||
|
return TypeOfImage;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief A function that loads and sclaes an image to the fitting dimensions.
|
* \brief A function that loads and sclaes an image to the fitting dimensions.
|
||||||
* \param filePath - The path+name of the image which to loaded.
|
* \param filePath - The path+name of the image which to loaded.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
IntelliRasterImage::IntelliRasterImage(int weight, int height)
|
IntelliRasterImage::IntelliRasterImage(int weight, int height)
|
||||||
: IntelliImage(weight, height){
|
: IntelliImage(weight, height){
|
||||||
|
TypeOfImage = IntelliImage::ImageType::Raster_Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntelliRasterImage::~IntelliRasterImage(){
|
IntelliRasterImage::~IntelliRasterImage(){
|
||||||
@@ -15,6 +15,7 @@ IntelliRasterImage::~IntelliRasterImage(){
|
|||||||
IntelliImage* IntelliRasterImage::getDeepCopy(){
|
IntelliImage* IntelliRasterImage::getDeepCopy(){
|
||||||
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
||||||
raster->imageData.fill(Qt::transparent);
|
raster->imageData.fill(Qt::transparent);
|
||||||
|
raster->TypeOfImage = IntelliImage::ImageType::Raster_Image;
|
||||||
return raster;
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
IntelliShapedImage::IntelliShapedImage(int weight, int height)
|
IntelliShapedImage::IntelliShapedImage(int weight, int height)
|
||||||
: IntelliRasterImage(weight, height){
|
: IntelliRasterImage(weight, height){
|
||||||
|
TypeOfImage = IntelliImage::ImageType::Shaped_Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntelliShapedImage::~IntelliShapedImage(){
|
IntelliShapedImage::~IntelliShapedImage(){
|
||||||
@@ -20,6 +21,7 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
|
|||||||
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
||||||
shaped->setPolygon(this->polygonData);
|
shaped->setPolygon(this->polygonData);
|
||||||
shaped->imageData.fill(Qt::transparent);
|
shaped->imageData.fill(Qt::transparent);
|
||||||
|
shaped->TypeOfImage = IntelliImage::ImageType::Shaped_Image;
|
||||||
return shaped;
|
return shaped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "Image/IntelliRasterImage.h"
|
#include "Image/IntelliRasterImage.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "IntelliHelper/IntelliHelper.h"
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief The IntelliShapedImage manages a Shapedimage.
|
* \brief The IntelliShapedImage manages a Shapedimage.
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
|
|||||||
: QWidget(parent){
|
: QWidget(parent){
|
||||||
this->Tool = nullptr;
|
this->Tool = nullptr;
|
||||||
this->setLayerDimensions(maxWidth, maxHeight);
|
this->setLayerDimensions(maxWidth, maxHeight);
|
||||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
this->addLayer(200,200,0,0,IntelliImage::ImageType::Shaped_Image);
|
||||||
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
|
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
|
||||||
std::vector<QPoint> polygon;
|
std::vector<QPoint> polygon;
|
||||||
polygon.push_back(QPoint(100,000));
|
polygon.push_back(QPoint(100,000));
|
||||||
@@ -31,7 +31,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
|
|||||||
polygon.push_back(QPoint(000,100));
|
polygon.push_back(QPoint(000,100));
|
||||||
layerBundle[0].image->setPolygon(polygon);
|
layerBundle[0].image->setPolygon(polygon);
|
||||||
|
|
||||||
this->addLayer(200,200,150,150);
|
this->addLayer(200,200,150,150,IntelliImage::ImageType::Raster_Image);
|
||||||
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
||||||
layerBundle[1].alpha=200;
|
layerBundle[1].alpha=200;
|
||||||
|
|
||||||
@@ -53,15 +53,15 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){
|
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){
|
||||||
LayerObject newLayer;
|
LayerObject newLayer;
|
||||||
newLayer.width = width;
|
newLayer.width = width;
|
||||||
newLayer.height = height;
|
newLayer.height = height;
|
||||||
newLayer.widthOffset = widthOffset;
|
newLayer.widthOffset = widthOffset;
|
||||||
newLayer.heightOffset = heightOffset;
|
newLayer.heightOffset = heightOffset;
|
||||||
if(type==ImageType::Raster_Image) {
|
if(type==IntelliImage::ImageType::Raster_Image) {
|
||||||
newLayer.image = new IntelliRasterImage(width,height);
|
newLayer.image = new IntelliRasterImage(width,height);
|
||||||
}else if(type==ImageType::Shaped_Image) {
|
}else if(type==IntelliImage::ImageType::Shaped_Image) {
|
||||||
newLayer.image = new IntelliShapedImage(width, height);
|
newLayer.image = new IntelliShapedImage(width, height);
|
||||||
}
|
}
|
||||||
newLayer.alpha = 255;
|
newLayer.alpha = 255;
|
||||||
@@ -234,6 +234,14 @@ int PaintingArea::getHeightOfActive(){
|
|||||||
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].height;
|
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){
|
||||||
|
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getTypeOfImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<QPoint> PaintingArea::getPolygonDataOfRealLayer(){
|
||||||
|
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getPolygonData();
|
||||||
|
}
|
||||||
|
|
||||||
// If a mouse button is pressed check if it was the
|
// If a mouse button is pressed check if it was the
|
||||||
// left button and if so store the current position
|
// left button and if so store the current position
|
||||||
// Set that we are currently drawing
|
// Set that we are currently drawing
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
* \param type - Defining the ImageType of the new layer
|
* \param type - Defining the ImageType of the new layer
|
||||||
* \return Returns the number of layers in the project
|
* \return Returns the number of layers in the project
|
||||||
*/
|
*/
|
||||||
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
|
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::Raster_Image);
|
||||||
/*!
|
/*!
|
||||||
* \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack
|
* \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack
|
||||||
* \param idx - ID of the position the new layer should be added
|
* \param idx - ID of the position the new layer should be added
|
||||||
@@ -90,7 +90,7 @@ public:
|
|||||||
* \param type - Defining the ImageType of the new layer
|
* \param type - Defining the ImageType of the new layer
|
||||||
* \return Returns the id of the layer position
|
* \return Returns the id of the layer position
|
||||||
*/
|
*/
|
||||||
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
|
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::Raster_Image);
|
||||||
/*!
|
/*!
|
||||||
* \brief The deleteLayer method removes a layer at a given index
|
* \brief The deleteLayer method removes a layer at a given index
|
||||||
* \param index - The index of the layer to be removed
|
* \param index - The index of the layer to be removed
|
||||||
@@ -161,6 +161,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
int getHeightOfActive();
|
int getHeightOfActive();
|
||||||
|
|
||||||
|
IntelliImage::ImageType getTypeOfImageRealLayer();
|
||||||
|
|
||||||
|
std::vector<QPoint> getPolygonDataOfRealLayer();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Events to handle
|
// Events to handle
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ void IntelliTool::onWheelScrolled(int value){
|
|||||||
|
|
||||||
void IntelliTool::createToolLayer(){
|
void IntelliTool::createToolLayer(){
|
||||||
Area->createTempTopLayer(Area->activeLayer);
|
Area->createTempTopLayer(Area->activeLayer);
|
||||||
this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(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)];
|
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliTool::mergeToolLayer(){
|
void IntelliTool::mergeToolLayer(){
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){
|
|||||||
void IntelliToolPen::onMouseLeftPressed(int x, int y){
|
void IntelliToolPen::onMouseLeftPressed(int x, int y){
|
||||||
IntelliTool::onMouseLeftPressed(x,y);
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
this->previousPoint=QPoint(x,y);
|
this->previousPoint=QPoint(x,y);
|
||||||
this->Canvas->image->drawPixel(previousPoint, colorPicker->getFirstColor());
|
this->Canvas->image->drawPoint(previousPoint, colorPicker->getFirstColor(), penWidth);
|
||||||
Canvas->image->calculateVisiblity();
|
Canvas->image->calculateVisiblity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "IntelliToolPolygon.h"
|
#include "IntelliToolPolygon.h"
|
||||||
#include "Layer/PaintingArea.h"
|
#include "Layer/PaintingArea.h"
|
||||||
#include <QDebug>
|
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||||
: IntelliTool(Area, colorPicker){
|
: IntelliTool(Area, colorPicker){
|
||||||
@@ -10,6 +10,7 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* c
|
|||||||
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",5,1,10,1);
|
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",5,1,10,1);
|
||||||
isPointNearStart = false;
|
isPointNearStart = false;
|
||||||
isDrawing = false;
|
isDrawing = false;
|
||||||
|
isInside = false;
|
||||||
this->ActiveType = Tooltype::POLYGON;
|
this->ActiveType = Tooltype::POLYGON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +21,16 @@ IntelliToolPolygon::~IntelliToolPolygon(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||||
if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Shaped_Image && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
|
||||||
|
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(Area->getPolygonDataOfRealLayer());
|
||||||
|
QPoint Point(x,y);
|
||||||
|
isInside = IntelliHelper::isInPolygon(Triangles,Point);
|
||||||
|
}
|
||||||
|
else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Raster_Image && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
|
||||||
|
isInside = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isInside && !isDrawing) {
|
||||||
IntelliTool::onMouseLeftPressed(x,y);
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
QPoint drawingPoint = QPoint(x,y);
|
QPoint drawingPoint = QPoint(x,y);
|
||||||
|
|
||||||
@@ -37,6 +47,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
|||||||
this->Canvas->image->calculateVisiblity();
|
this->Canvas->image->calculateVisiblity();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
isInside = false;
|
||||||
isDrawing = false;
|
isDrawing = false;
|
||||||
QPointList.clear();
|
QPointList.clear();
|
||||||
IntelliTool::onMouseRightPressed(x,y);
|
IntelliTool::onMouseRightPressed(x,y);
|
||||||
@@ -52,6 +63,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
|
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
|
||||||
|
isInside = false;
|
||||||
isDrawing = false;
|
isDrawing = false;
|
||||||
isPointNearStart = false;
|
isPointNearStart = false;
|
||||||
QPointList.clear();
|
QPointList.clear();
|
||||||
@@ -60,6 +72,7 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){
|
|||||||
|
|
||||||
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||||
if(isPointNearStart) {
|
if(isPointNearStart) {
|
||||||
|
isInside = false;
|
||||||
isPointNearStart = false;
|
isPointNearStart = false;
|
||||||
isDrawing = false;
|
isDrawing = false;
|
||||||
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
|
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ int lineWidth;
|
|||||||
*/
|
*/
|
||||||
bool isDrawing;
|
bool isDrawing;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief isInside Checks if Point is inside Image
|
||||||
|
*/
|
||||||
|
bool isInside;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user