Skip to content

Commit

Permalink
Add a Wave
Browse files Browse the repository at this point in the history
The radius of the Wave can be easily computed with the Pythagorean
theorem.
  • Loading branch information
vimpostor committed Nov 6, 2023
1 parent 6e56cce commit ec6a42c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ ApplicationWindow {
onActivated: Qt.quit();
}
DropArea {
property int mouseX: 0
property int mouseY: 0
anchors.fill: parent
onDropped: (drop) => {
Stdout.print_urls(drop.urls);
}
Rectangle {
onPositionChanged: (drag) => {
mouseX = drag.x;
mouseY = drag.y;
}
Wave {
anchors.fill: parent
color: parent.containsDrag && parent.drag.source === null ? Material.primary : Material.background
Behavior on color { ColorAnimation { duration: 200; easing.type: Easing.InOutSine }}
size: parent.containsDrag && parent.drag.source === null ? 1.0 : 0.0
centreX: parent.mouseX
centreY: parent.mouseY
}
}
Welcome {
Expand Down
32 changes: 32 additions & 0 deletions src/qml/Wave.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import QtQuick
import QtQuick.Controls.Material
import QtQuick.Effects

Rectangle {
id: wave
property real size: 0.0
property int centreX: width / 2
property int centreY: height / 2
color: Material.primary
visible: size > 0.0
Behavior on size {
NumberAnimation { duration: 300; easing.type: Easing.InOutSine; }
}
layer.enabled: true
layer.effect: MultiEffect {
maskEnabled: true
maskSource: ShaderEffectSource {
sourceItem: Item {
width: wave.width
height: wave.height
Rectangle {
radius: Math.ceil(Math.sqrt(Math.pow(wave.width / 2 + Math.abs(wave.centreX - wave.width / 2), 2) + Math.pow(wave.height / 2 + Math.abs(wave.centreY - wave.height / 2), 2)))
width: wave.size * 2 * radius
height: width
x: wave.centreX - width / 2
y: wave.centreY - height / 2
}
}
}
}
}

0 comments on commit ec6a42c

Please sign in to comment.