forked from processing/processing4
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStart.kt
More file actions
97 lines (92 loc) · 3.88 KB
/
Start.kt
File metadata and controls
97 lines (92 loc) · 3.88 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package processing.app.ui
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import processing.app.Base
import java.awt.AWTEvent
import java.awt.event.WindowEvent
/**
* Show a splash screen window. A rewrite of Splash.java
*/
class Start {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val duration = 200
application {
var starting by remember { mutableStateOf(true) }
Window(
visible = starting,
onCloseRequest = { },
undecorated = true,
transparent = true,
resizable = false,
state = rememberWindowState(
position = WindowPosition(Alignment.Center),
width = 578.dp,
height = 665.dp
)
) {
var visible by remember { mutableStateOf(false) }
var launched by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
Toolkit.setIcon(window)
visible = true
}
AnimatedVisibility(
visible = visible,
enter = fadeIn(
animationSpec = tween(
durationMillis = duration,
easing = LinearEasing
)
),
exit = fadeOut(
animationSpec = tween(
durationMillis = duration,
easing = LinearEasing
)
),
) {
LaunchedEffect(visible, transition.currentState) {
if (launched) return@LaunchedEffect
if (!visible) return@LaunchedEffect
// Wait until the view is no longer transitioning
if (transition.targetState != transition.currentState) return@LaunchedEffect
launched = true
Base.main(args)
// List for any new windows opening, and close the splash when one does
java.awt.Toolkit.getDefaultToolkit()
.addAWTEventListener({ event ->
if (event.id != WindowEvent.WINDOW_OPENED) return@addAWTEventListener
starting = false
}, AWTEvent.WINDOW_EVENT_MASK);
}
Image(
painter = painterResource("about-processing.svg"),
contentDescription = "About",
modifier = Modifier
.fillMaxSize()
.clip(RoundedCornerShape(16.dp))
)
}
}
}
}
}
}