matrixion/resources/qml/ui/TimelineEffects.qml

143 lines
3.7 KiB
QML
Raw Permalink Normal View History

2023-03-24 16:36:42 +03:00
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.15
import QtQuick.Particles 2.15
Item {
2023-06-19 02:54:32 +03:00
id: effectRoot
2023-03-24 16:36:42 +03:00
readonly property int maxLifespan: Math.max(confettiEmitter.lifeSpan, rainfallEmitter.lifeSpan)
2023-06-19 02:54:32 +03:00
required property bool shouldEffectsRun
visible: effectRoot.shouldEffectsRun
2023-03-24 16:36:42 +03:00
function pulseConfetti()
{
2023-06-19 02:54:32 +03:00
confettiEmitter.pulse(effectRoot.height * 2)
2023-03-24 16:36:42 +03:00
}
function pulseRainfall()
{
2023-06-19 02:54:32 +03:00
rainfallEmitter.pulse(effectRoot.height * 3.3)
2023-03-24 16:36:42 +03:00
}
function removeParticles()
{
particleSystem.reset()
}
2023-03-24 16:36:42 +03:00
ParticleSystem {
id: particleSystem
2023-10-09 23:50:41 +03:00
Component.onCompleted: stop();
2023-06-19 02:54:32 +03:00
paused: !effectRoot.shouldEffectsRun
running: effectRoot.shouldEffectsRun
2023-03-24 16:36:42 +03:00
}
Emitter {
id: confettiEmitter
group: "confetti"
2023-06-19 02:54:32 +03:00
width: effectRoot.width * 3/4
2023-03-24 16:36:42 +03:00
enabled: false
2023-06-19 02:54:32 +03:00
anchors.horizontalCenter: effectRoot.horizontalCenter
y: effectRoot.height
emitRate: Math.min(400 * Math.sqrt(effectRoot.width * effectRoot.height) / 870, 1000)
2023-03-24 16:36:42 +03:00
lifeSpan: 15000
system: particleSystem
maximumEmitted: 500
velocityFromMovement: 8
size: 16
sizeVariation: 4
velocity: PointDirection {
x: 0
2023-06-19 02:54:32 +03:00
y: -Math.min(450 * effectRoot.height / 700, 1000)
xVariation: Math.min(4 * effectRoot.width / 7, 450)
2023-03-24 16:36:42 +03:00
yVariation: 250
}
}
ImageParticle {
system: particleSystem
groups: ["confetti"]
source: "qrc:/confettiparticle.svg"
rotationVelocity: 0
rotationVelocityVariation: 360
colorVariation: 1
color: "white"
entryEffect: ImageParticle.None
xVector: PointDirection {
x: 1
y: 0
xVariation: 0.2
yVariation: 0.2
}
yVector: PointDirection {
x: 0
y: 0.5
xVariation: 0.2
yVariation: 0.2
}
}
Gravity {
system: particleSystem
groups: ["confetti"]
2023-06-19 02:54:32 +03:00
anchors.fill: effectRoot
2023-03-24 16:36:42 +03:00
magnitude: 350
angle: 90
}
Emitter {
id: rainfallEmitter
group: "rain"
2023-06-19 02:54:32 +03:00
width: effectRoot.width
2023-03-24 16:36:42 +03:00
enabled: false
2023-06-19 02:54:32 +03:00
anchors.horizontalCenter: effectRoot.horizontalCenter
2023-03-24 16:36:42 +03:00
y: -60
emitRate: effectRoot.width / 30
2023-03-24 16:36:42 +03:00
lifeSpan: 10000
system: particleSystem
velocity: PointDirection {
x: 0
y: 400
2023-03-24 16:36:42 +03:00
xVariation: 0
yVariation: 75
}
// causes high CPU load, see: https://bugreports.qt.io/browse/QTBUG-117923
//ItemParticle {
// system: particleSystem
// groups: ["rain"]
// fade: false
// visible: effectRoot.shouldEffectsRun
// delegate: Rectangle {
// width: 2
// height: 30 + 30 * Math.random()
// radius: 2
// color: "#0099ff"
// }
//}
ImageParticle {
system: particleSystem
groups: ["rain"]
source: "qrc:/confettiparticle.svg"
rotationVelocity: 0
rotationVelocityVariation: 0
colorVariation: 0
2023-03-24 16:36:42 +03:00
color: "#0099ff"
entryEffect: ImageParticle.None
xVector: PointDirection {
x: 0.01
y: 0
}
yVector: PointDirection {
x: 0
y: 5
}
2023-03-24 16:36:42 +03:00
}
}
}