mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-16 13:20:33 +02:00
start of Tool Commentary
This commit is contained in:
@@ -5,21 +5,59 @@
|
|||||||
#include"QPoint"
|
#include"QPoint"
|
||||||
#include"QColorDialog"
|
#include"QColorDialog"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The IntelliColorPicker manages the selected colors for one whole project.
|
||||||
|
*/
|
||||||
class IntelliColorPicker{
|
class IntelliColorPicker{
|
||||||
public:
|
public:
|
||||||
|
/*!
|
||||||
|
* \brief IntelliColorPicker construktor, setting 2 preset colors, be careful, theese color may change in production.
|
||||||
|
*/
|
||||||
IntelliColorPicker();
|
IntelliColorPicker();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief IntelliColorPicker destructor clears up his used memory, if there is some.
|
||||||
|
*/
|
||||||
virtual ~IntelliColorPicker();
|
virtual ~IntelliColorPicker();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function switching primary and secondary color.
|
||||||
|
*/
|
||||||
void switchColors();
|
void switchColors();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function to read the primary selected color.
|
||||||
|
* \return Returns the primary color.
|
||||||
|
*/
|
||||||
QColor getFirstColor();
|
QColor getFirstColor();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function to read the secondary selected color.
|
||||||
|
* \return Returns the secondary color.
|
||||||
|
*/
|
||||||
QColor getSecondColor();
|
QColor getSecondColor();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function to set the primary color.
|
||||||
|
* \param Color - The color to be set as primary.
|
||||||
|
*/
|
||||||
void setFirstColor(QColor Color);
|
void setFirstColor(QColor Color);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function to set the secondary color.
|
||||||
|
* \param Color - The color to be set as secondary.
|
||||||
|
*/
|
||||||
void setSecondColor(QColor Color);
|
void setSecondColor(QColor Color);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/*!
|
||||||
|
* \brief The primary color.
|
||||||
|
*/
|
||||||
QColor firstColor;
|
QColor firstColor;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The secondary color.
|
||||||
|
*/
|
||||||
QColor secondColor;
|
QColor secondColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> poly
|
|||||||
|
|
||||||
bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
|
bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
|
||||||
for(auto triangle : triangles){
|
for(auto triangle : triangles){
|
||||||
if(IntelliHelper::isInTriangle(triangle.A ,triangle.B, triangle.C, point)){
|
if(IntelliHelper::isInTriangle(triangle, point)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,40 @@
|
|||||||
#include<QPoint>
|
#include<QPoint>
|
||||||
#include<vector>
|
#include<vector>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The Triangle struct holds the 3 vertices of a triangle.
|
||||||
|
*/
|
||||||
struct Triangle{
|
struct Triangle{
|
||||||
QPoint A,B,C;
|
QPoint A,B,C;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace IntelliHelper {
|
namespace IntelliHelper {
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function to get the 2*area of a traingle, using its determinat.
|
||||||
|
* \param p1 - The Point to check its side.
|
||||||
|
* \param p2 - The first Point of the spanning Line
|
||||||
|
* \param p3 - The second Point of the spanning line.
|
||||||
|
* \return Returns the area of the traingle*2
|
||||||
|
*/
|
||||||
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
|
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
|
||||||
return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
|
return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){
|
/*!
|
||||||
|
* \brief A function to check if a given point is in a triangle.
|
||||||
|
* \param tri - The triangle to check, if it contains the point.
|
||||||
|
* \param P - The point to check if it is in the triangle.
|
||||||
|
* \return Returns true if the point is in the triangle, false otheriwse
|
||||||
|
*/
|
||||||
|
inline bool isInTriangle(Triangle& tri, QPoint& P){
|
||||||
float val1, val2, val3;
|
float val1, val2, val3;
|
||||||
bool neg, pos;
|
bool neg, pos;
|
||||||
|
|
||||||
val1 = IntelliHelper::sign(P,A,B);
|
val1 = IntelliHelper::sign(P,tri.A,tri.B);
|
||||||
val2 = IntelliHelper::sign(P,B,C);
|
val2 = IntelliHelper::sign(P,tri.B,tri.C);
|
||||||
val3 = IntelliHelper::sign(P,C,A);
|
val3 = IntelliHelper::sign(P,tri.C,tri.A);
|
||||||
|
|
||||||
neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
|
neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
|
||||||
pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
|
pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
|
||||||
@@ -29,8 +45,19 @@ namespace IntelliHelper {
|
|||||||
return !(neg && pos);
|
return !(neg && pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by clipping ears of a planar graph.
|
||||||
|
* \param polyPoints - The Vertices of the polygon.
|
||||||
|
* \return Returns a Container of disjoint Triangles, which desribe the polygon area.
|
||||||
|
*/
|
||||||
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
|
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function to check if a point lies in a polygon by checking its spanning triangles.
|
||||||
|
* \param triangles - The spanning triangles of the planar polygon.
|
||||||
|
* \param point - The point to checl, if it lies in the polygon.
|
||||||
|
* \return Returns true if the point lies in the üpolygon, otherwise false.
|
||||||
|
*/
|
||||||
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
|
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,21 +37,73 @@ protected:
|
|||||||
*/
|
*/
|
||||||
IntelliColorPicker* colorPicker;
|
IntelliColorPicker* colorPicker;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
|
||||||
|
*/
|
||||||
LayerObject* Active;
|
LayerObject* Active;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A pointer to the drawing canvas of the tool, work on this.
|
||||||
|
*/
|
||||||
LayerObject* Canvas;
|
LayerObject* Canvas;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A flag checking if the user is currently drawing or not.
|
||||||
|
*/
|
||||||
bool drawing = false;
|
bool drawing = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/*!
|
||||||
|
* \brief A constructor setting the general Painting Area and colorPicker.
|
||||||
|
* \param Area - The general PaintingArea used by the project.
|
||||||
|
* \param colorPicker - The general colorPicker used by the project
|
||||||
|
*/
|
||||||
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief An abstract Destructor.
|
||||||
|
*/
|
||||||
virtual ~IntelliTool() = 0;
|
virtual ~IntelliTool() = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on. Call this in child classes!
|
||||||
|
* \param x - The x coordinate relative to the Active/Canvas Layer.
|
||||||
|
* \param y - The y coordinate relative to the Active/Canvas Layer.
|
||||||
|
*/
|
||||||
virtual void onMouseRightPressed(int x, int y);
|
virtual void onMouseRightPressed(int x, int y);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function managing the right click Released of a Mouse. Merging the Canvas to Active. Call this in child classes!
|
||||||
|
* \param x - The x coordinate relative to the Active/Canvas Layer.
|
||||||
|
* \param y - The y coordinate relative to the Active/Canvas Layer.
|
||||||
|
*/
|
||||||
virtual void onMouseRightReleased(int x, int y);
|
virtual void onMouseRightReleased(int x, int y);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function managing the left click Pressed of a Mouse. Resetting the current draw. Call this in child classes!
|
||||||
|
* \param x - The x coordinate relative to the Active/Canvas Layer.
|
||||||
|
* \param y - The y coordinate relative to the Active/Canvas Layer.
|
||||||
|
*/
|
||||||
virtual void onMouseLeftPressed(int x, int y);
|
virtual void onMouseLeftPressed(int x, int y);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function managing the left click Released of a Mouse. Call this in child classes!
|
||||||
|
* \param x - The x coordinate relative to the Active/Canvas Layer.
|
||||||
|
* \param y - The y coordinate relative to the Active/Canvas Layer.
|
||||||
|
*/
|
||||||
virtual void onMouseLeftReleased(int x, int y);
|
virtual void onMouseLeftReleased(int x, int y);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function managing the scroll event. A Positive Value means scrolling outwards. Call this in child classes!
|
||||||
|
* \param value - The absolute the scroll has changed.
|
||||||
|
*/
|
||||||
virtual void onWheelScrolled(int value);
|
virtual void onWheelScrolled(int value);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A function managing the mouse moved event. Call this in child classes!
|
||||||
|
* \param x - The x coordinate of the new Mouse Position.
|
||||||
|
* \param y - The y coordinate of the new Mouse Position.
|
||||||
|
*/
|
||||||
virtual void onMouseMoved(int x, int y);
|
virtual void onMouseMoved(int x, int y);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user