Add opacity to scripting overlay

This commit is contained in:
GriffinR 2021-12-31 16:12:04 -05:00 committed by huderlem
parent 98f4bae728
commit fd88184b47
6 changed files with 46 additions and 0 deletions

View file

@ -87,6 +87,9 @@ public:
Q_INVOKABLE void setOverlaysPosition(int x, int y);
Q_INVOKABLE void moveOverlay(int deltaX, int deltaY, int layer = 0);
Q_INVOKABLE void moveOverlays(int deltaX, int deltaY);
Q_INVOKABLE int getOverlayOpacity(int layer);
Q_INVOKABLE void setOverlayOpacity(int opacity, int layer = 0);
Q_INVOKABLE void setOverlaysOpacity(int opacity);
Q_INVOKABLE void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12, int layer = 0);
Q_INVOKABLE void addRect(int x, int y, int width, int height, QString color = "#000000", int layer = 0);
Q_INVOKABLE void addFilledRect(int x, int y, int width, int height, QString color = "#000000", int layer = 0);

View file

@ -16,6 +16,7 @@ public:
void setOverlaysY(int y);
void setOverlaysPosition(int x, int y);
void moveOverlays(int deltaX, int deltaY);
void setOverlaysOpacity(int opacity);
public:
QMap<int, Overlay*> overlayMap;

View file

@ -75,12 +75,15 @@ public:
this->x = 0;
this->y = 0;
this->hidden = false;
this->opacity = 1.0;
}
~Overlay() {
this->clearItems();
}
bool getHidden();
void setHidden(bool hidden);
int getOpacity();
void setOpacity(int opacity);
int getX();
int getY();
void setX(int x);
@ -99,6 +102,7 @@ private:
int x;
int y;
bool hidden;
qreal opacity;
};
#endif // OVERLAY_H

View file

@ -353,6 +353,26 @@ void MainWindow::moveOverlays(int deltaX, int deltaY) {
this->ui->graphicsView_Map->scene()->update();
}
int MainWindow::getOverlayOpacity(int layer) {
if (!this->ui || !this->ui->graphicsView_Map)
return 0;
return this->ui->graphicsView_Map->getOverlay(layer)->getOpacity();
}
void MainWindow::setOverlayOpacity(int opacity, int layer) {
if (!this->ui || !this->ui->graphicsView_Map)
return;
this->ui->graphicsView_Map->getOverlay(layer)->setOpacity(opacity);
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::setOverlaysOpacity(int opacity) {
if (!this->ui || !this->ui->graphicsView_Map)
return;
this->ui->graphicsView_Map->setOverlaysOpacity(opacity);
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::addText(QString text, int x, int y, QString color, int fontSize, int layer) {
if (!this->ui || !this->ui->graphicsView_Map)
return;

View file

@ -69,6 +69,11 @@ void MapView::setOverlaysPosition(int x, int y) {
overlay->setPosition(x, y);
}
void MapView::setOverlaysOpacity(int opacity) {
foreach (Overlay * overlay, this->overlayMap)
overlay->setOpacity(opacity);
}
void MapView::moveOverlays(int deltaX, int deltaY) {
foreach (Overlay * overlay, this->overlayMap)
overlay->move(deltaX, deltaY);

View file

@ -26,6 +26,7 @@ void OverlayImage::render(QPainter *painter, int x, int y) {
void Overlay::renderItems(QPainter *painter) {
if (this->hidden) return;
painter->setOpacity(this->opacity);
for (auto item : this->items)
item->render(painter, this->x, this->y);
}
@ -49,6 +50,18 @@ void Overlay::setHidden(bool hidden) {
this->hidden = hidden;
}
int Overlay::getOpacity() {
return this->opacity * 100;
}
void Overlay::setOpacity(int opacity) {
if (opacity < 0 || opacity > 100) {
logError(QString("Invalid overlay opacity '%1'").arg(opacity));
return;
}
this->opacity = static_cast<qreal>(opacity) / 100;
}
int Overlay::getX() {
return this->x;
}