2018-12-28 18:26:18 +00:00
|
|
|
#include "regionmappixmapitem.h"
|
2022-04-26 22:02:03 +01:00
|
|
|
#include "regionmapeditcommands.h"
|
|
|
|
|
2018-12-28 18:26:18 +00:00
|
|
|
void RegionMapPixmapItem::draw() {
|
|
|
|
if (!region_map) return;
|
|
|
|
|
2022-03-01 20:32:44 +00:00
|
|
|
QImage image(region_map->pixelWidth(), region_map->pixelHeight(), QImage::Format_RGBA8888);
|
2018-12-28 18:26:18 +00:00
|
|
|
|
|
|
|
QPainter painter(&image);
|
2022-03-01 20:32:44 +00:00
|
|
|
for (int i = 0; i < region_map->tilemapSize(); i++) {
|
|
|
|
QImage img = this->tile_selector->tileImg(region_map->getTile(i));
|
|
|
|
int x = i % region_map->tilemapWidth();
|
|
|
|
int y = i / region_map->tilemapWidth();
|
2018-12-28 18:26:18 +00:00
|
|
|
QPoint pos = QPoint(x * 8, y * 8);
|
|
|
|
painter.drawImage(pos, img);
|
|
|
|
}
|
|
|
|
painter.end();
|
|
|
|
|
|
|
|
this->setPixmap(QPixmap::fromImage(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|
|
|
if (region_map) {
|
2022-04-28 18:21:36 +01:00
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 8;
|
|
|
|
int y = static_cast<int>(pos.y()) / 8;
|
|
|
|
int index = x + y * region_map->tilemapWidth();
|
|
|
|
this->region_map->setTileData(index,
|
|
|
|
this->tile_selector->selectedTile,
|
|
|
|
this->tile_selector->tile_hFlip,
|
|
|
|
this->tile_selector->tile_vFlip,
|
|
|
|
this->tile_selector->tile_palette
|
|
|
|
);
|
|
|
|
draw();
|
2018-12-28 18:26:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 8;
|
|
|
|
int y = static_cast<int>(pos.y()) / 8;
|
|
|
|
this->tile_selector->select(this->region_map->getTileId(x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
|
|
|
int x = static_cast<int>(event->pos().x()) / 8;
|
|
|
|
int y = static_cast<int>(event->pos().y()) / 8;
|
|
|
|
emit this->hoveredRegionMapTileChanged(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
|
|
|
emit this->hoveredRegionMapTileCleared();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
emit mouseEvent(event, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
2019-01-22 20:06:49 +00:00
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 8;
|
|
|
|
int y = static_cast<int>(pos.y()) / 8;
|
2022-03-01 20:32:44 +00:00
|
|
|
if (x < this->region_map->tilemapWidth() && x >= 0
|
|
|
|
&& y < this->region_map->tilemapHeight() && y >= 0) {
|
2019-01-22 20:06:49 +00:00
|
|
|
emit this->hoveredRegionMapTileChanged(x, y);
|
|
|
|
emit mouseEvent(event, this);
|
|
|
|
}
|
2018-12-28 18:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
emit mouseEvent(event, this);
|
|
|
|
}
|