Skip to content

Commit b8e84da

Browse files
committed
New splash screen
1 parent 28859f1 commit b8e84da

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sourceSets{
4141

4242
compose.desktop {
4343
application {
44-
mainClass = "processing.app.ui.Splash"
44+
mainClass = "processing.app.ui.Start"
4545

4646
nativeDistributions{
4747
modules("jdk.jdi", "java.compiler")

app/src/processing/app/ui/Start.kt

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package processing.app.ui
2+
3+
import androidx.compose.animation.AnimatedVisibility
4+
import androidx.compose.animation.EnterExitState
5+
import androidx.compose.animation.core.LinearEasing
6+
import androidx.compose.animation.core.tween
7+
import androidx.compose.animation.fadeIn
8+
import androidx.compose.animation.fadeOut
9+
import androidx.compose.foundation.Image
10+
import androidx.compose.foundation.layout.fillMaxSize
11+
import androidx.compose.foundation.layout.padding
12+
import androidx.compose.foundation.shape.RoundedCornerShape
13+
import androidx.compose.material.Text
14+
import androidx.compose.runtime.*
15+
import androidx.compose.ui.Alignment
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.draw.clip
18+
import androidx.compose.ui.draw.shadow
19+
import androidx.compose.ui.graphics.toComposeImageBitmap
20+
import androidx.compose.ui.unit.DpSize
21+
import androidx.compose.ui.unit.dp
22+
import androidx.compose.ui.window.*
23+
import kotlinx.coroutines.Dispatchers
24+
import kotlinx.coroutines.delay
25+
import kotlinx.coroutines.launch
26+
import processing.app.Base
27+
import processing.app.Platform
28+
import javax.imageio.ImageIO
29+
import javax.swing.SwingUtilities
30+
31+
/**
32+
* Show a splash screen window. A rewrite of Splash.java
33+
*/
34+
class Start {
35+
companion object {
36+
@JvmStatic
37+
fun main(args: Array<String>) {
38+
val splash = Platform.getContentFile("lib/about-2x.png")
39+
val image = ImageIO.read(splash).toComposeImageBitmap()
40+
val duration = 200
41+
val timeMargin = 50
42+
43+
application {
44+
var starting by remember { mutableStateOf(true) }
45+
Window(
46+
visible = starting,
47+
onCloseRequest = { },
48+
undecorated = true,
49+
transparent = true,
50+
resizable = false,
51+
alwaysOnTop = true,
52+
state = rememberWindowState(
53+
position = WindowPosition(Alignment.Center),
54+
size = DpSize(image.width.dp / 2 , image.height.dp / 2)
55+
)
56+
) {
57+
var visible by remember { mutableStateOf(false) }
58+
val composition = rememberCoroutineScope()
59+
LaunchedEffect(Unit) {
60+
visible = true
61+
composition.launch {
62+
delay(duration.toLong() + timeMargin)
63+
try {
64+
Base.main(args)
65+
} catch (e: Exception) {
66+
throw InternalError("Failed to invoke main method", e)
67+
}
68+
composition.launch {
69+
visible = false
70+
delay(duration.toLong() + timeMargin)
71+
starting = false
72+
}
73+
}
74+
}
75+
AnimatedVisibility(
76+
visible = visible,
77+
enter = fadeIn(
78+
animationSpec = tween(
79+
durationMillis = duration,
80+
easing = LinearEasing
81+
)
82+
),
83+
exit = fadeOut(
84+
animationSpec = tween(
85+
durationMillis = duration,
86+
easing = LinearEasing
87+
)
88+
)
89+
) {
90+
Image(
91+
bitmap = image,
92+
contentDescription = "About",
93+
modifier = Modifier
94+
.fillMaxSize()
95+
.clip(RoundedCornerShape(16.dp))
96+
)
97+
}
98+
}
99+
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)