author | unC0Rr |
Mon, 17 Feb 2025 16:37:59 +0100 | |
branch | qmlrenderer |
changeset 16089 | 02304ad06381 |
permissions | -rw-r--r-- |
16089
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
1 |
import QtQuick 2.15 |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
2 |
import Hedgewars 1.0 |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
3 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
4 |
Item { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
5 |
id: control |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
6 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
7 |
property string dataPrefix: "share/hedgewars/Data/" |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
8 |
property url themePath: "file://%1Themes/Stage/".arg(dataPrefix) |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
9 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
10 |
Flickable { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
11 |
id: backgroundContainer |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
12 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
13 |
anchors.fill: parent |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
14 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
15 |
contentWidth: map.implicitWidth |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
16 |
contentHeight: map.implicitHeight |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
17 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
18 |
interactive: false |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
19 |
contentX: mapContainer.contentX * 0.7 + (contentWidth - width) * 0.15 |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
20 |
contentY: mapContainer.contentY * 0.7 + (contentHeight - height) * 0.3 |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
21 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
22 |
Rectangle { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
23 |
anchors.fill: parent |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
24 |
color: "black" |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
25 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
26 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
27 |
Item { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
28 |
width: parent.width |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
29 |
height: parent.height |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
30 |
anchors.horizontalCenter: parent.horizontalCenter |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
31 |
anchors.bottom: parent.bottom |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
32 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
33 |
Image { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
34 |
id: skyLeft |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
35 |
anchors.left: parent.left |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
36 |
anchors.right: skyCenter.left |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
37 |
anchors.bottom: parent.bottom |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
38 |
fillMode: Image.TileHorizontally |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
39 |
horizontalAlignment: Image.AlignRight |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
40 |
source: control.themePath + "SkyL.png" |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
41 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
42 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
43 |
Image { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
44 |
id: skyCenter |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
45 |
anchors.horizontalCenter: parent.horizontalCenter |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
46 |
anchors.bottom: parent.bottom |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
47 |
fillMode: Image.Pad |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
48 |
source: control.themePath + "Sky.png" |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
49 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
50 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
51 |
Image { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
52 |
id: skyRight |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
53 |
anchors.left: skyCenter.right |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
54 |
anchors.right: parent.right |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
55 |
anchors.bottom: parent.bottom |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
56 |
fillMode: Image.TileHorizontally |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
57 |
horizontalAlignment: Image.AlignLeft |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
58 |
source: control.themePath + "SkyL.png" |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
59 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
60 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
61 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
62 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
63 |
Flickable { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
64 |
id: mapContainer |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
65 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
66 |
anchors.fill: parent |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
67 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
68 |
boundsMovement: Flickable.StopAtBounds |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
69 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
70 |
contentWidth: map.implicitWidth |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
71 |
contentHeight: map.implicitHeight |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
72 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
73 |
onContentXChanged: map.update() |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
74 |
onContentYChanged: map.update() |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
75 |
onWidthChanged: map.update() |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
76 |
onHeightChanged: map.update() |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
77 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
78 |
pixelAligned: true |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
79 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
80 |
TiledImageItem { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
81 |
id: map |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
82 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
83 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
84 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
85 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
86 |
MouseArea { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
87 |
anchors.fill: mapContainer |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
88 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
89 |
property double zoom: 1.0 |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
90 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
91 |
acceptedButtons: Qt.NoButton |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
92 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
93 |
enabled: false |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
94 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
95 |
onWheel: wheel => { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
96 |
zoom = zoom * Math.exp(wheel.angleDelta.y * 0.001) |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
97 |
var zoomPoint = Qt.point(wheel.x + mapContainer.contentX, |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
98 |
wheel.y + mapContainer.contentY); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
99 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
100 |
map.scale = zoom |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
101 |
mapContainer.resizeContent(map.implicitWidth * zoom, map.implicitHeight * zoom, zoomPoint); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
102 |
mapContainer.returnToBounds(); |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
103 |
console.log(mapContainer.scale) |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
104 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
105 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
106 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
107 |
|
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
108 |
Component.onCompleted: { |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
109 |
map.test(dataPrefix + "Maps/Ropes/map.png") |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
110 |
console.log(Screen.devicePixelRatio) |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
111 |
} |
02304ad06381
Add TiledImageItem and a scene that represents hedgewars map
unC0Rr
parents:
diff
changeset
|
112 |
} |