[nostalgia/core/studio] Add support for dragging cursor around tile sheet editor
This commit is contained in:
parent
38ae116356
commit
1edd322352
@ -27,9 +27,4 @@ Rectangle {
|
||||
anchors.bottom: pixel.bottom
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: sheetData.updatePixels([pixel])
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,12 @@ Rectangle {
|
||||
y: parent.height / 2 - tile.height / 2
|
||||
color: '#000000'
|
||||
|
||||
function pixelAt(x, y) {
|
||||
return tileGrid.childAt(x, y);
|
||||
}
|
||||
|
||||
Grid {
|
||||
id: tileGrid
|
||||
width: tile.width
|
||||
height: tile.height
|
||||
rows: 8
|
||||
|
@ -13,21 +13,42 @@ Rectangle {
|
||||
id: tileSheetEditor
|
||||
color: '#717d7e'
|
||||
|
||||
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: tileSheetEditor.horizontalCenter
|
||||
anchors.verticalCenter: tileSheetEditor.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
|
||||
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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,11 +61,13 @@ class UpdatePixelsCommand: public QUndoCommand {
|
||||
m_newColorId = newColorId;
|
||||
cmdIdx = cmdIdx;
|
||||
for (auto &pi : pixelItems) {
|
||||
PixelUpdate pu;
|
||||
auto p = qobject_cast<QQuickItem*>(pi.value<QObject*>());
|
||||
pu.item = p;
|
||||
pu.oldColorId = m_palette.indexOf(p->property("color").toString());
|
||||
m_pixelUpdates.insert(pu);
|
||||
if (p) {
|
||||
PixelUpdate pu;
|
||||
pu.item = p;
|
||||
pu.oldColorId = m_palette.indexOf(p->property("color").toString());
|
||||
m_pixelUpdates.insert(pu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user