2018-09-27 00:30:05 +01:00
|
|
|
#include "bordermetatilespixmapitem.h"
|
|
|
|
#include "imageproviders.h"
|
2020-10-02 20:32:22 +01:00
|
|
|
#include "metatile.h"
|
2020-07-29 20:51:04 +01:00
|
|
|
#include "editcommands.h"
|
2018-09-27 00:30:05 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
2022-09-05 17:35:17 +01:00
|
|
|
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
|
2020-10-02 20:32:22 +01:00
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
2020-03-14 07:44:55 +00:00
|
|
|
int width = map->getBorderWidth();
|
|
|
|
int height = map->getBorderHeight();
|
2018-09-27 00:30:05 +01:00
|
|
|
|
2021-02-14 21:34:17 +00:00
|
|
|
Blockdata oldBorder = map->layout->border;
|
2020-07-29 20:51:04 +01:00
|
|
|
|
2022-09-05 17:35:17 +01:00
|
|
|
for (int i = 0; i < selection.dimensions.x() && (i + pos.x()) < width; i++) {
|
|
|
|
for (int j = 0; j < selection.dimensions.y() && (j + pos.y()) < height; j++) {
|
|
|
|
MetatileSelectionItem item = selection.metatileItems.at(j * selection.dimensions.x() + i);
|
|
|
|
map->setBorderMetatileId(pos.x() + i, pos.y() + j, item.metatileId, true);
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 21:56:23 +00:00
|
|
|
if (map->layout->border != oldBorder) {
|
|
|
|
map->editHistory.push(new PaintBorder(map, oldBorder, map->layout->border, 0));
|
2020-08-04 05:32:50 +01:00
|
|
|
}
|
2020-07-29 20:51:04 +01:00
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
emit borderMetatilesChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BorderMetatilesPixmapItem::draw() {
|
2020-07-29 20:51:04 +01:00
|
|
|
map->setBorderItem(this);
|
|
|
|
|
2020-03-14 07:44:55 +00:00
|
|
|
int width = map->getBorderWidth();
|
|
|
|
int height = map->getBorderHeight();
|
|
|
|
QImage image(16 * width, 16 * height, QImage::Format_RGBA8888);
|
2018-09-27 00:30:05 +01:00
|
|
|
QPainter painter(&image);
|
|
|
|
|
2020-03-14 07:44:55 +00:00
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
for (int j = 0; j < height; j++) {
|
2018-09-27 00:30:05 +01:00
|
|
|
int x = i * 16;
|
|
|
|
int y = j * 16;
|
2020-07-02 02:43:19 +01:00
|
|
|
QImage metatile_image = getMetatileImage(
|
2022-08-29 17:44:17 +01:00
|
|
|
map->getBorderMetatileId(i, j),
|
2020-07-02 02:43:19 +01:00
|
|
|
map->layout->tileset_primary,
|
|
|
|
map->layout->tileset_secondary,
|
|
|
|
map->metatileLayerOrder,
|
|
|
|
map->metatileLayerOpacity);
|
2018-09-27 00:30:05 +01:00
|
|
|
QPoint metatile_origin = QPoint(x, y);
|
|
|
|
painter.drawImage(metatile_origin, metatile_image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
painter.end();
|
|
|
|
this->setPixmap(QPixmap::fromImage(image));
|
2020-07-29 20:51:04 +01:00
|
|
|
|
|
|
|
emit borderMetatilesChanged();
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
2022-11-28 21:01:29 +00:00
|
|
|
|
|
|
|
void BorderMetatilesPixmapItem::hoverUpdate(const QPointF &pixmapPos) {
|
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(pixmapPos);
|
|
|
|
uint16_t metatileId = this->map->getBorderMetatileId(pos.x(), pos.y());
|
|
|
|
emit this->hoveredBorderMetatileSelectionChanged(metatileId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BorderMetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
this->hoverUpdate(event->pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BorderMetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
|
|
|
this->hoverUpdate(event->pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BorderMetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
|
|
|
|
emit this->hoveredBorderMetatileSelectionCleared();
|
|
|
|
}
|