[nostalgia/core/studio] Replace TileSheetEditor ScrollView scrolling with manual version

This commit is contained in:
2020-02-25 20:26:35 -06:00
parent f762e658de
commit 7ca34da417
3 changed files with 48 additions and 21 deletions
+38 -14
View File
@@ -10,18 +10,10 @@ import QtQuick 2.0
import QtQuick.Controls 2.14
import 'qrc:/qml/'
ScrollView {
Rectangle {
id: tileSheetEditor
ScrollBar.horizontal.policy: ScrollBar.AsNeeded
ScrollBar.vertical.policy: ScrollBar.AsNeeded
contentWidth: tileGrid.width
contentHeight: tileGrid.height
clip: true
focusPolicy: Qt.WheelFocus
background: Rectangle {
color: '#717d7e'
}
color: '#717d7e'
MouseArea {
id: mouseArea
@@ -45,10 +37,42 @@ ScrollView {
} else if (tileGrid.scaleFactor > 0.9) {
tileGrid.scaleFactor -= mod;
}
wheel.accepted = true;
if (tileGrid.width <= this.width) {
tileGrid.x = this.width / 2 - tileGrid.width / 2;
}
if (tileGrid.height <= this.height) {
tileGrid.y = this.height / 2 - tileGrid.height / 2;
}
} else {
wheel.accepted = false;
const mod = 15;
if (tileGrid.width > this.width) {
if (wheel.angleDelta.x > 0) {
if (tileGrid.x < tileGrid.width / 2) {
tileGrid.x += mod;
}
} else if (wheel.angleDelta.x < 0) {
let x2 = tileGrid.x + tileGrid.width;
if (x2 > this.width / 2) {
tileGrid.x -= mod;
}
}
}
if (tileGrid.height > this.height) {
if (wheel.angleDelta.y > 0) {
if (tileGrid.y < this.height / 2) {
tileGrid.y += mod;
}
} else if (wheel.angleDelta.y < 0) {
let y2 = tileGrid.y + tileGrid.height;
if (y2 > this.height / 2) {
tileGrid.y -= mod;
}
}
}
}
wheel.accepted = true;
}
onPositionChanged: sheetData.updatePixel(pixelAt(mouseX, mouseY))
@@ -74,10 +98,10 @@ ScrollView {
id: tileGrid
property double scaleFactor: 0.9
property int baseTileSize: Math.min(2000 / tileGrid.columns, 1000 / tileGrid.rows)
x: tileSheetEditor.width / 2 - this.width / 2
y: tileSheetEditor.height / 2 - this.height / 2
width: tileGrid.columns * tileGrid.baseTileSize * tileGrid.scaleFactor
height: tileGrid.rows * tileGrid.baseTileSize * tileGrid.scaleFactor
//anchors.horizontalCenter: parent.horizontalCenter
//anchors.verticalCenter: parent.verticalCenter
rows: sheetData ? sheetData.rows : 1
columns: sheetData ? sheetData.columns : 1
Repeater {