Add clipping capabilities to overlay scripting api
This commit is contained in:
parent
fc2f91023f
commit
47b6669feb
4 changed files with 54 additions and 0 deletions
|
@ -32,6 +32,10 @@ public:
|
|||
Q_INVOKABLE void setX(int x);
|
||||
Q_INVOKABLE void setY(int y, int layer);
|
||||
Q_INVOKABLE void setY(int y);
|
||||
Q_INVOKABLE void setClippingRect(int x, int y, int width, int height, int layer);
|
||||
Q_INVOKABLE void setClippingRect(int x, int y, int width, int height);
|
||||
Q_INVOKABLE void clearClippingRect(int layer);
|
||||
Q_INVOKABLE void clearClippingRect();
|
||||
Q_INVOKABLE QJSValue getPosition(int layer = 0);
|
||||
Q_INVOKABLE void setPosition(int x, int y, int layer);
|
||||
Q_INVOKABLE void setPosition(int x, int y);
|
||||
|
|
|
@ -76,6 +76,7 @@ public:
|
|||
this->y = 0;
|
||||
this->hidden = false;
|
||||
this->opacity = 1.0;
|
||||
this->clippingRect = nullptr;
|
||||
}
|
||||
~Overlay() {
|
||||
this->clearItems();
|
||||
|
@ -88,6 +89,8 @@ public:
|
|||
int getY();
|
||||
void setX(int x);
|
||||
void setY(int y);
|
||||
void setClippingRect(QRectF rect);
|
||||
void clearClippingRect();
|
||||
void setPosition(int x, int y);
|
||||
void move(int deltaX, int deltaY);
|
||||
void renderItems(QPainter *painter);
|
||||
|
@ -103,6 +106,7 @@ private:
|
|||
int y;
|
||||
bool hidden;
|
||||
qreal opacity;
|
||||
QRectF *clippingRect;
|
||||
};
|
||||
|
||||
#endif // OVERLAY_H
|
||||
|
|
|
@ -79,6 +79,29 @@ void MapView::setY(int y) {
|
|||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MapView::setClippingRect(int x, int y, int width, int height, int layer) {
|
||||
this->getOverlay(layer)->setClippingRect(QRectF(x, y, width, height));
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MapView::setClippingRect(int x, int y, int width, int height) {
|
||||
QRectF rect = QRectF(x, y, width, height);
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->setClippingRect(rect);
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MapView::clearClippingRect(int layer) {
|
||||
this->getOverlay(layer)->clearClippingRect();
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
void MapView::clearClippingRect() {
|
||||
foreach (Overlay * layer, this->overlayMap)
|
||||
layer->clearClippingRect();
|
||||
this->scene()->update();
|
||||
}
|
||||
|
||||
QJSValue MapView::getPosition(int layer) {
|
||||
Overlay * overlay = this->getOverlay(layer);
|
||||
return Scripting::position(overlay->getX(), overlay->getY());
|
||||
|
|
|
@ -26,11 +26,20 @@ void OverlayImage::render(QPainter *painter, int x, int y) {
|
|||
void Overlay::renderItems(QPainter *painter) {
|
||||
if (this->hidden) return;
|
||||
|
||||
if (this->clippingRect) {
|
||||
painter->setClipping(true);
|
||||
painter->setClipRect(*this->clippingRect);
|
||||
}
|
||||
|
||||
qreal oldOpacity = painter->opacity();
|
||||
painter->setOpacity(this->opacity);
|
||||
for (auto item : this->items)
|
||||
item->render(painter, this->x, this->y);
|
||||
painter->setOpacity(oldOpacity);
|
||||
|
||||
if (this->clippingRect) {
|
||||
painter->setClipping(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Overlay::clearItems() {
|
||||
|
@ -80,6 +89,20 @@ void Overlay::setY(int y) {
|
|||
this->y = y;
|
||||
}
|
||||
|
||||
void Overlay::setClippingRect(QRectF rect) {
|
||||
if (this->clippingRect) {
|
||||
delete this->clippingRect;
|
||||
}
|
||||
this->clippingRect = new QRectF(rect);
|
||||
}
|
||||
|
||||
void Overlay::clearClippingRect() {
|
||||
if (this->clippingRect) {
|
||||
delete this->clippingRect;
|
||||
}
|
||||
this->clippingRect = nullptr;
|
||||
}
|
||||
|
||||
void Overlay::setPosition(int x, int y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
|
|
Loading…
Reference in a new issue