[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,21 +13,42 @@ Rectangle {
id: tileSheetEditor id: tileSheetEditor
color: '#717d7e' color: '#717d7e'
Grid { MouseArea {
id: tileGrid id: mouseArea
property int baseTileSize: Math.min(parent.width / tileGrid.columns, parent.height / tileGrid.rows) anchors.fill: parent
width: tileGrid.columns * tileGrid.baseTileSize * 0.90 acceptedButtons: Qt.LeftButton
height: tileGrid.rows * tileGrid.baseTileSize * 0.90 onPositionChanged: {
anchors.horizontalCenter: tileSheetEditor.horizontalCenter var gridX = mouseX - tileGrid.x;
anchors.verticalCenter: tileSheetEditor.verticalCenter var gridY = mouseY - tileGrid.y;
rows: sheetData.rows var tile = tileGrid.childAt(gridX, gridY);
columns: sheetData.columns if (tile === null) {
Repeater { return;
model: tileGrid.rows * tileGrid.columns }
Tile { var tileX = gridX - tile.x;
tileNumber: index var tileY = gridY - tile.y;
width: tileGrid.width / tileGrid.columns var pixel = tile.pixelAt(tileX, tileY);
height: tileGrid.height / tileGrid.rows if (pixel === null) {
return;
}
sheetData.updatePixels([pixel]);
}
Grid {
id: tileGrid
property int baseTileSize: Math.min(parent.width / tileGrid.columns, parent.height / tileGrid.rows)
width: tileGrid.columns * tileGrid.baseTileSize * 0.90
height: tileGrid.rows * tileGrid.baseTileSize * 0.90
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
rows: sheetData.rows
columns: sheetData.columns
Repeater {
model: tileGrid.rows * tileGrid.columns
Tile {
tileNumber: index
width: tileGrid.width / tileGrid.columns
height: tileGrid.height / tileGrid.rows
}
} }
} }
} }

View File

@ -61,11 +61,13 @@ 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*>());
pu.item = p; if (p) {
pu.oldColorId = m_palette.indexOf(p->property("color").toString()); PixelUpdate pu;
m_pixelUpdates.insert(pu); pu.item = p;
pu.oldColorId = m_palette.indexOf(p->property("color").toString());
m_pixelUpdates.insert(pu);
}
} }
} }