[nostalgia/core/studio] Add support for dragging cursor around tile sheet editor

This commit is contained in:
Gary Talent 2019-12-05 23:38:51 -06:00
parent 38ae116356
commit 1edd322352
4 changed files with 47 additions and 24 deletions

View File

@ -27,9 +27,4 @@ Rectangle {
anchors.bottom: pixel.bottom anchors.bottom: pixel.bottom
} }
MouseArea {
anchors.fill: parent
onClicked: sheetData.updatePixels([pixel])
}
} }

View File

@ -17,7 +17,12 @@ Rectangle {
y: parent.height / 2 - tile.height / 2 y: parent.height / 2 - tile.height / 2
color: '#000000' color: '#000000'
function pixelAt(x, y) {
return tileGrid.childAt(x, y);
}
Grid { Grid {
id: tileGrid
width: tile.width width: tile.width
height: tile.height height: tile.height
rows: 8 rows: 8

View File

@ -13,13 +13,33 @@ Rectangle {
id: tileSheetEditor id: tileSheetEditor
color: '#717d7e' color: '#717d7e'
MouseArea {
id: mouseArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onPositionChanged: {
var gridX = mouseX - tileGrid.x;
var gridY = mouseY - tileGrid.y;
var tile = tileGrid.childAt(gridX, gridY);
if (tile === null) {
return;
}
var tileX = gridX - tile.x;
var tileY = gridY - tile.y;
var pixel = tile.pixelAt(tileX, tileY);
if (pixel === null) {
return;
}
sheetData.updatePixels([pixel]);
}
Grid { Grid {
id: tileGrid id: tileGrid
property int baseTileSize: Math.min(parent.width / tileGrid.columns, parent.height / tileGrid.rows) property int baseTileSize: Math.min(parent.width / tileGrid.columns, parent.height / tileGrid.rows)
width: tileGrid.columns * tileGrid.baseTileSize * 0.90 width: tileGrid.columns * tileGrid.baseTileSize * 0.90
height: tileGrid.rows * tileGrid.baseTileSize * 0.90 height: tileGrid.rows * tileGrid.baseTileSize * 0.90
anchors.horizontalCenter: tileSheetEditor.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: tileSheetEditor.verticalCenter anchors.verticalCenter: parent.verticalCenter
rows: sheetData.rows rows: sheetData.rows
columns: sheetData.columns columns: sheetData.columns
Repeater { Repeater {
@ -31,5 +51,6 @@ Rectangle {
} }
} }
} }
}
} }

View File

@ -61,13 +61,15 @@ class UpdatePixelsCommand: public QUndoCommand {
m_newColorId = newColorId; m_newColorId = newColorId;
cmdIdx = cmdIdx; cmdIdx = cmdIdx;
for (auto &pi : pixelItems) { for (auto &pi : pixelItems) {
PixelUpdate pu;
auto p = qobject_cast<QQuickItem*>(pi.value<QObject*>()); auto p = qobject_cast<QQuickItem*>(pi.value<QObject*>());
if (p) {
PixelUpdate pu;
pu.item = p; pu.item = p;
pu.oldColorId = m_palette.indexOf(p->property("color").toString()); pu.oldColorId = m_palette.indexOf(p->property("color").toString());
m_pixelUpdates.insert(pu); m_pixelUpdates.insert(pu);
} }
} }
}
virtual ~UpdatePixelsCommand() = default; virtual ~UpdatePixelsCommand() = default;