porymap/include/ui/overlay.h

126 lines
3.1 KiB
C
Raw Normal View History

#ifndef OVERLAY_H
#define OVERLAY_H
#include <QList>
#include <QString>
#include <QColor>
#include <QPainter>
2022-10-11 04:47:42 +01:00
#include <QStaticText>
#include <QPainterPath>
class OverlayItem {
public:
OverlayItem() {}
virtual ~OverlayItem() {};
2022-10-11 22:21:44 +01:00
virtual void render(QPainter *) {};
};
class OverlayText : public OverlayItem {
public:
2022-10-11 04:47:42 +01:00
OverlayText(const QString inputText, int x, int y, QColor color, int fontSize) :
text(QStaticText(inputText))
{
this->x = x;
this->y = y;
this->color = color;
this->fontSize = fontSize;
}
~OverlayText() {}
2022-10-11 22:21:44 +01:00
virtual void render(QPainter *painter);
private:
2022-10-11 04:47:42 +01:00
const QStaticText text;
int x;
int y;
QColor color;
int fontSize;
};
class OverlayPath : public OverlayItem {
public:
OverlayPath(QPainterPath path, QColor borderColor, QColor fillColor) {
this->path = path;
this->borderColor = borderColor;
this->fillColor = fillColor;
}
~OverlayPath() {}
2022-10-11 22:21:44 +01:00
virtual void render(QPainter *painter);
private:
QPainterPath path;
QColor borderColor;
QColor fillColor;
};
class OverlayImage : public OverlayItem {
public:
OverlayImage(int x, int y, QImage image) {
this->x = x;
this->y = y;
this->image = image;
}
~OverlayImage() {}
2022-10-11 22:21:44 +01:00
virtual void render(QPainter *painter);
private:
int x;
int y;
QImage image;
};
class Overlay
{
public:
Overlay() {
this->x = 0;
this->y = 0;
2022-10-13 20:14:53 +01:00
this->angle = 0;
2022-10-11 22:21:44 +01:00
this->hScale = 1.0;
this->vScale = 1.0;
this->hidden = false;
2021-12-31 21:12:04 +00:00
this->opacity = 1.0;
this->clippingRect = nullptr;
}
~Overlay() {
this->clearItems();
}
bool getHidden();
2021-11-30 18:38:06 +00:00
void setHidden(bool hidden);
2021-12-31 21:12:04 +00:00
int getOpacity();
void setOpacity(int opacity);
int getX();
int getY();
void setX(int x);
void setY(int y);
qreal getHScale();
qreal getVScale();
void setHScale(qreal scale);
void setVScale(qreal scale);
2022-10-13 20:14:53 +01:00
int getAngle();
void setAngle(int angle);
2022-10-11 22:21:44 +01:00
void rotate(int degrees);
void setClippingRect(QRectF rect);
void clearClippingRect();
void setPosition(int x, int y);
void move(int deltaX, int deltaY);
2021-11-30 17:58:39 +00:00
void renderItems(QPainter *painter);
QList<OverlayItem*> getItems();
void clearItems();
void addText(const QString text, int x, int y, QString colorStr, int fontSize);
bool addRect(int x, int y, int width, int height, QString borderColorStr, QString fillColorStr, int rounding);
bool addImage(int x, int y, QString filepath, bool useCache = true, int width = -1, int height = -1, int xOffset = 0, int yOffset = 0, qreal hScale = 1, qreal vScale = 1, QList<QRgb> palette = QList<QRgb>(), bool setTransparency = false);
bool addImage(int x, int y, QImage image);
2022-10-11 22:21:44 +01:00
bool addPath(QList<int> xCoords, QList<int> yCoords, QString borderColorStr, QString fillColorStr);
private:
2022-10-13 20:14:53 +01:00
void clampAngle();
QColor getColor(QString colorStr);
QList<OverlayItem*> items;
int x;
int y;
2022-10-13 20:14:53 +01:00
int angle;
2022-10-11 22:21:44 +01:00
qreal hScale;
qreal vScale;
2021-11-30 18:38:06 +00:00
bool hidden;
2021-12-31 21:12:04 +00:00
qreal opacity;
QRectF *clippingRect;
};
#endif // OVERLAY_H