Add layering to scripting overlay

This commit is contained in:
GriffinR
2021-11-30 12:58:39 -05:00
committed by huderlem
parent 630febff54
commit af4c99537f
7 changed files with 49 additions and 23 deletions

View File

@@ -605,7 +605,7 @@ void MainWindow::on_action_Open_Project_triggered()
if (!dir.isEmpty()) {
if (this->editor && this->editor->project) {
Scripting::cb_ProjectClosed(this->editor->project->root);
this->ui->graphicsView_Map->overlay.clearItems();
this->ui->graphicsView_Map->clearOverlays();
}
porymapConfig.setRecentProject(dir);
setWindowDisabled(!openProject(dir));

View File

@@ -227,38 +227,42 @@ void MainWindow::setHeight(int height) {
this->onMapNeedsRedrawing();
}
void MainWindow::clearOverlay() {
void MainWindow::clearOverlay(int layer) {
if (!this->ui || !this->ui->graphicsView_Map)
return;
this->ui->graphicsView_Map->overlay.clearItems();
// INT_MAX is used as an indicator value to refer to all overlays
if (layer == INT_MAX)
this->ui->graphicsView_Map->clearOverlays();
else
this->ui->graphicsView_Map->getOverlay(layer)->clearItems();
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::addText(QString text, int x, int y, QString color, int fontSize) {
if (!this->ui || !this->ui->graphicsView_Map)
void MainWindow::addText(QString text, int x, int y, QString color, int fontSize, int layer) {
if (!this->ui || !this->ui->graphicsView_Map || layer == INT_MAX)
return;
this->ui->graphicsView_Map->overlay.addText(text, x, y, color, fontSize);
this->ui->graphicsView_Map->getOverlay(layer)->addText(text, x, y, color, fontSize);
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::addRect(int x, int y, int width, int height, QString color) {
if (!this->ui || !this->ui->graphicsView_Map)
void MainWindow::addRect(int x, int y, int width, int height, QString color, int layer) {
if (!this->ui || !this->ui->graphicsView_Map || layer == INT_MAX)
return;
this->ui->graphicsView_Map->overlay.addRect(x, y, width, height, color, false);
this->ui->graphicsView_Map->getOverlay(layer)->addRect(x, y, width, height, color, false);
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::addFilledRect(int x, int y, int width, int height, QString color) {
if (!this->ui || !this->ui->graphicsView_Map)
void MainWindow::addFilledRect(int x, int y, int width, int height, QString color, int layer) {
if (!this->ui || !this->ui->graphicsView_Map || layer == INT_MAX)
return;
this->ui->graphicsView_Map->overlay.addRect(x, y, width, height, color, true);
this->ui->graphicsView_Map->getOverlay(layer)->addRect(x, y, width, height, color, true);
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::addImage(int x, int y, QString filepath, int width, int height, unsigned offset, bool hflip, bool vflip, bool setTransparency) {
if (!this->ui || !this->ui->graphicsView_Map)
void MainWindow::addImage(int x, int y, QString filepath, int width, int height, unsigned offset, bool hflip, bool vflip, bool setTransparency, int layer) {
if (!this->ui || !this->ui->graphicsView_Map || layer == INT_MAX)
return;
if (this->ui->graphicsView_Map->overlay.addImage(x, y, filepath, width, height, offset, hflip, vflip, setTransparency))
if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, width, height, offset, hflip, vflip, setTransparency))
this->ui->graphicsView_Map->scene()->update();
}

View File

@@ -17,9 +17,22 @@ void GraphicsView::mouseReleaseEvent(QMouseEvent *event) {
}
void GraphicsView::drawForeground(QPainter *painter, const QRectF&) {
for (auto item : this->overlay.getItems()) {
item->render(painter);
foreach (Overlay * overlay, this->overlayMap)
overlay->renderItems(painter);
}
void GraphicsView::clearOverlays() {
foreach (Overlay * overlay, this->overlayMap)
overlay->clearItems();
}
Overlay * GraphicsView::getOverlay(int layer) {
Overlay * overlay = this->overlayMap.value(layer, nullptr);
if (!overlay) {
overlay = new Overlay();
this->overlayMap.insert(layer, overlay);
}
return overlay;
}
void GraphicsView::moveEvent(QMoveEvent *event) {

View File

@@ -22,6 +22,12 @@ void OverlayImage::render(QPainter *painter) {
painter->drawImage(this->x, this->y, this->image);
}
void Overlay::renderItems(QPainter *painter) {
for (auto item : this->items) {
item->render(painter);
}
}
void Overlay::clearItems() {
for (auto item : this->items) {
delete item;