from AbstractShape.hpp:39
class AbstractShape : public CanvasWidget
{
public:
template <typename T>
struct ShapePoint
{
T x;
T y;
};
AbstractShape();
virtual ~AbstractShape();
virtual int getNumPoints() const = 0;
virtual void setCorner(int i, CWRUtil::Q5 x, CWRUtil::Q5 y) = 0;
virtual CWRUtil::Q5 getCornerX(int i) const = 0;
virtual CWRUtil::Q5 getCornerY(int i) const = 0;
template <typename T>
void setShape(ShapePoint<T>* points)
{
int numPoints = getNumPoints();
for (int i = 0; i < numPoints; i++)
{
setCorner(i, CWRUtil::toQ5<T>(points[i].x), CWRUtil::toQ5<T>(points[i].y));
}
updateAbstractShapeCache();
}
template <typename T>
void setOrigin(T x, T y)
{
CWRUtil::Q5 dxNew = CWRUtil::toQ5<T>(x);
CWRUtil::Q5 dyNew = CWRUtil::toQ5<T>(y);
if (dx == dxNew && dy == dyNew)
{
return;
}
dx = dxNew;
dy = dyNew;
updateAbstractShapeCache();
}
template <typename T>
void moveOrigin(T x, T y)
{
CWRUtil::Q5 xNew = CWRUtil::toQ5<T>(x);
CWRUtil::Q5 yNew = CWRUtil::toQ5<T>(y);
if (dx == xNew && dy == yNew)
{
return;
}
Rect rect = getMinimalRect();
dx = xNew;
dy = yNew;
updateAbstractShapeCache();
rect.expandToFit(getMinimalRect());
invalidateRect(rect);
}
template <typename T>
void getOrigin(T& dx, T& dy) const
{
dx = this->dx.to<T>();
dy = this->dy.to<T>();
}
template <typename T>
void setAngle(T angle)
{
CWRUtil::Q5 angleQ5 = CWRUtil::toQ5<T>(angle);
if (shapeAngle != angleQ5)
{
shapeAngle = angleQ5;
updateAbstractShapeCache();
}
}
template <typename T>
void updateAngle(T angle)
{
CWRUtil::Q5 angleQ5 = CWRUtil::toQ5<T>(angle);
if (shapeAngle != angleQ5)
{
Rect rectBefore = getMinimalRect();
shapeAngle = angleQ5;
updateAbstractShapeCache();
Rect rectAfter = getMinimalRect();
rectBefore.expandToFit(rectAfter);
invalidateRect(rectBefore);
}
}
int getAngle() const
{
return shapeAngle.to<int>();
}
template <typename T>
void setScale(T newXScale, T newYScale)
{
xScale = CWRUtil::toQ5<T>(newXScale);
yScale = CWRUtil::toQ5<T>(newYScale);
updateAbstractShapeCache();
}
template <typename T>
void setScale(T scale)
{
setScale(scale, scale);
}
template <typename T>
void getScale(T& x, T& y) const
{
x = xScale.to<T>();
y = yScale.to<T>();
}
virtual bool drawCanvasWidget(const Rect& invalidatedArea) const;
void updateAbstractShapeCache();
protected:
virtual void setCache(int i, CWRUtil::Q5 x, CWRUtil::Q5 y) = 0;
virtual CWRUtil::Q5 getCacheX(int i) const = 0;
virtual CWRUtil::Q5 getCacheY(int i) const = 0;
virtual Rect getMinimalRect() const;
private:
CWRUtil::Q5 dx, dy;
CWRUtil::Q5 shapeAngle;
CWRUtil::Q5 xScale, yScale;
Rect minimalRect;
};