1
+ package com.icuxika.bittersweet.demo.controller
2
+
3
+ import com.icuxika.bittersweet.demo.annotation.AppFXML
4
+ import javafx.animation.PathTransition
5
+ import javafx.animation.PauseTransition
6
+ import javafx.fxml.FXML
7
+ import javafx.fxml.Initializable
8
+ import javafx.scene.layout.BorderPane
9
+ import javafx.scene.layout.Pane
10
+ import javafx.scene.layout.StackPane
11
+ import javafx.scene.paint.Color
12
+ import javafx.scene.shape.*
13
+ import javafx.util.Duration
14
+ import java.net.URL
15
+ import java.util.*
16
+
17
+ @AppFXML(fxml = " fxml/splash-screen.fxml" )
18
+ class SplashScreenController : Initializable {
19
+
20
+ @FXML
21
+ private lateinit var rootContainer: StackPane
22
+
23
+ @FXML
24
+ private lateinit var container: BorderPane
25
+
26
+ private val circle = Circle (8.0 , Color .DODGERBLUE )
27
+ private val path = Path ().apply {
28
+ stroke = Color .BLACK
29
+ strokeLineCap = StrokeLineCap .ROUND
30
+ strokeDashArray.addAll(4.0 , 4.0 )
31
+ strokeWidth = 2.0
32
+ fill = null
33
+ }
34
+
35
+ override fun initialize (location : URL ? , resources : ResourceBundle ? ) {
36
+ val pane = Pane ()
37
+ container.center = pane.apply {
38
+ children.addAll(circle, path)
39
+ }
40
+
41
+ val pathTransition = PathTransition ().apply {
42
+ node = circle
43
+ duration = Duration .seconds(3.0 )
44
+ cycleCount = PathTransition .INDEFINITE
45
+ isAutoReverse = false
46
+ orientation = PathTransition .OrientationType .ORTHOGONAL_TO_TANGENT
47
+ }
48
+
49
+ val pauseTransition = PauseTransition ()
50
+ pauseTransition.setOnFinished {
51
+ pathTransition.path = path
52
+ pathTransition.play()
53
+ }
54
+
55
+ pane.layoutBoundsProperty().addListener { _, _, newValue ->
56
+ if (newValue.width > 0 && newValue.height > 0 ) {
57
+ pathTransition.stop()
58
+ path.elements.clear()
59
+ path.elements.addAll(
60
+ MoveTo (newValue.width / 2 , newValue.height / 2 ),
61
+ CubicCurveTo (
62
+ 0.0 , 0.0 ,
63
+ 0.0 , newValue.height,
64
+ newValue.width / 2 , newValue.height / 2
65
+ ),
66
+ CubicCurveTo (
67
+ newValue.width, 0.0 ,
68
+ newValue.width, newValue.height,
69
+ newValue.width / 2 , newValue.height / 2
70
+ ),
71
+ )
72
+ pauseTransition.playFromStart()
73
+ }
74
+ }
75
+ }
76
+
77
+ }
0 commit comments