blob: 90e6e64211489c37f986fd81a6aee4eb8ea3ecb1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
<Item id="Switch" width="{Groove.width}" height="{Groove.height}">
<properties><Property name="on"/></properties>
<Script>
function toggle() {
if(Switch.state == "On")
Switch.state = "Off";
else
Switch.state = "On";
}
function dorelease() {
print(Knob.x);
if(Knob.x == 1) {
if(Switch.state == "Off")
return;
}
if(Knob.x == 78) {
if(Switch.state == "On")
return;
}
toggle();
}
</Script>
<Image id="Groove" src="background.svg"/>
<MouseRegion anchors.fill="{Groove}" onClicked="toggle()"/>
<Image id="Knob" src="knob.svg" x="1" y="2"/>
<MouseRegion anchors.fill="{Knob}"
onClicked="toggle()"
onReleased="if (!isClick) dorelease()"
drag.target="{Knob}"
drag.axis="x"
drag.xmin="1"
drag.xmax="78"/>
<states>
<State name="On">
<SetProperty target="{Knob}" property="x" value="78" />
<SetProperty target="{Switch}" property="on" value="true" />
</State>
<State name="Off">
<SetProperty target="{Knob}" property="x" value="1" />
<SetProperty target="{Switch}" property="on" value="false" />
</State>
</states>
<transitions>
<Transition>
<NumericAnimation properties="x" easing="easeInOutQuad" duration="200"/>
</Transition>
</transitions>
</Item>
|