|
@@ -271,11 +271,6 @@ void MetatilesPixmapItem::draw() {
|
271
|
271
|
setPixmap(map->renderMetatiles());
|
272
|
272
|
}
|
273
|
273
|
|
274
|
|
-void MetatilesPixmapItem::pick(uint tile) {
|
275
|
|
- map->paint_tile = tile;
|
276
|
|
- emit map->paintTileChanged(map);
|
277
|
|
-}
|
278
|
|
-
|
279
|
274
|
void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
280
|
275
|
int x = ((int)pos.x()) / 16;
|
281
|
276
|
int y = ((int)pos.y()) / 16;
|
|
@@ -299,19 +294,30 @@ void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
299
|
294
|
QPointF pos = event->pos();
|
300
|
295
|
int x = ((int)pos.x()) / 16;
|
301
|
296
|
int y = ((int)pos.y()) / 16;
|
302
|
|
- //qDebug() << QString("(%1, %2)").arg(x).arg(y);
|
303
|
|
- int width = pixmap().width() / 16;
|
304
|
|
- int height = pixmap().height() / 16;
|
305
|
|
- if ((x >= 0 && x < width) && (y >=0 && y < height)) {
|
306
|
|
- pick(y * width + x);
|
307
|
|
- }
|
|
297
|
+ map->paint_metatile_initial_x = x;
|
|
298
|
+ map->paint_metatile_initial_y = y;
|
|
299
|
+ updateSelection(event->pos());
|
308
|
300
|
}
|
309
|
301
|
void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
310
|
302
|
updateCurHoveredMetatile(event->pos());
|
311
|
|
- mousePressEvent(event);
|
|
303
|
+ updateSelection(event->pos());
|
312
|
304
|
}
|
313
|
305
|
void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
314
|
|
- mousePressEvent(event);
|
|
306
|
+ updateSelection(event->pos());
|
|
307
|
+}
|
|
308
|
+void MetatilesPixmapItem::updateSelection(QPointF pos) {
|
|
309
|
+ int x = ((int)pos.x()) / 16;
|
|
310
|
+ int y = ((int)pos.y()) / 16;
|
|
311
|
+ int width = pixmap().width() / 16;
|
|
312
|
+ int height = pixmap().height() / 16;
|
|
313
|
+ if ((x >= 0 && x < width) && (y >=0 && y < height)) {
|
|
314
|
+ int baseTileX = x < map->paint_metatile_initial_x ? x : map->paint_metatile_initial_x;
|
|
315
|
+ int baseTileY = y < map->paint_metatile_initial_y ? y : map->paint_metatile_initial_y;
|
|
316
|
+ map->paint_tile = baseTileY * 8 + baseTileX;
|
|
317
|
+ map->paint_tile_width = abs(map->paint_metatile_initial_x - x) + 1;
|
|
318
|
+ map->paint_tile_height = abs(map->paint_metatile_initial_y - y) + 1;
|
|
319
|
+ emit map->paintTileChanged(map);
|
|
320
|
+ }
|
315
|
321
|
}
|
316
|
322
|
|
317
|
323
|
void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
|
@@ -345,10 +351,24 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
345
|
351
|
QPointF pos = event->pos();
|
346
|
352
|
int x = (int)(pos.x()) / 16;
|
347
|
353
|
int y = (int)(pos.y()) / 16;
|
348
|
|
- Block *block = map->getBlock(x, y);
|
349
|
|
- if (block) {
|
350
|
|
- block->tile = map->paint_tile;
|
351
|
|
- map->_setBlock(x, y, *block);
|
|
354
|
+ // Snap the selected position to the top-left of the block boundary.
|
|
355
|
+ // This allows painting via dragging the mouse to tile the painted region.
|
|
356
|
+ int xDiff = x - map->paint_tile_initial_x;
|
|
357
|
+ int yDiff = y - map->paint_tile_initial_y;
|
|
358
|
+ if (xDiff < 0 && xDiff % map->paint_tile_width != 0) xDiff -= map->paint_tile_width;
|
|
359
|
+ if (yDiff < 0 && yDiff % map->paint_tile_height != 0) yDiff -= map->paint_tile_height;
|
|
360
|
+
|
|
361
|
+ x = map->paint_tile_initial_x + (xDiff / map->paint_tile_width) * map->paint_tile_width;
|
|
362
|
+ y = map->paint_tile_initial_y + (yDiff / map->paint_tile_height) * map->paint_tile_height;
|
|
363
|
+ for (int i = 0; i < map->paint_tile_width && i + x < map->getWidth(); i++)
|
|
364
|
+ for (int j = 0; j < map->paint_tile_height && j + y < map->getHeight(); j++) {
|
|
365
|
+ int actualX = i + x;
|
|
366
|
+ int actualY = j + y;
|
|
367
|
+ Block *block = map->getBlock(actualX, actualY);
|
|
368
|
+ if (block) {
|
|
369
|
+ block->tile = map->paint_tile + i + (j * 8);
|
|
370
|
+ map->_setBlock(actualX, actualY, *block);
|
|
371
|
+ }
|
352
|
372
|
}
|
353
|
373
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
354
|
374
|
map->commit();
|
|
@@ -374,6 +394,8 @@ void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
374
|
394
|
Block *block = map->getBlock(x, y);
|
375
|
395
|
if (block) {
|
376
|
396
|
map->paint_tile = block->tile;
|
|
397
|
+ map->paint_tile_width = 1;
|
|
398
|
+ map->paint_tile_height = 1;
|
377
|
399
|
emit map->paintTileChanged(map);
|
378
|
400
|
}
|
379
|
401
|
}
|
|
@@ -451,6 +473,11 @@ void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
|
451
|
473
|
map->clearHoveredTile();
|
452
|
474
|
}
|
453
|
475
|
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
|
476
|
+ QPointF pos = event->pos();
|
|
477
|
+ int x = ((int)pos.x()) / 16;
|
|
478
|
+ int y = ((int)pos.y()) / 16;
|
|
479
|
+ map->paint_tile_initial_x = x;
|
|
480
|
+ map->paint_tile_initial_y = y;
|
454
|
481
|
emit mouseEvent(event, this);
|
455
|
482
|
}
|
456
|
483
|
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|