mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
javafx: improve some text component performance
This commit is contained in:
parent
4a546ff349
commit
6de93b3acb
@ -30,6 +30,7 @@ import javafx.scene.Node
|
|||||||
import javafx.scene.paint.Color
|
import javafx.scene.paint.Color
|
||||||
import javafx.scene.text.Text
|
import javafx.scene.text.Text
|
||||||
import javafx.util.Duration
|
import javafx.util.Duration
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
|
|
||||||
open class TextComponent(
|
open class TextComponent(
|
||||||
@ -117,21 +118,23 @@ open class TextComponent(
|
|||||||
|
|
||||||
override fun getJavaFXText(nodes: ObservableList<Node>): ObservableList<Node> {
|
override fun getJavaFXText(nodes: ObservableList<Node>): ObservableList<Node> {
|
||||||
val text = Text(this.message)
|
val text = Text(this.message)
|
||||||
this.color?.let {
|
val color = this.color
|
||||||
if (ErosProfileManager.selected.text.colored) {
|
if (color == null) {
|
||||||
text.fill = Color.rgb(it.red, it.green, it.blue)
|
|
||||||
}
|
|
||||||
} ?: let {
|
|
||||||
text.styleClass += "text-default-color"
|
text.styleClass += "text-default-color"
|
||||||
|
} else {
|
||||||
|
if (ErosProfileManager.selected.text.colored) {
|
||||||
|
text.fill = Color.rgb(color.red, color.green, color.blue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (FormattingCodes.OBFUSCATED in formatting) {
|
if (FormattingCodes.OBFUSCATED in formatting) {
|
||||||
// ToDo: This is just slow
|
// ToDo: This is just slow
|
||||||
val obfuscatedTimeline = if (ErosProfileManager.selected.text.obfuscated) {
|
val obfuscatedTimeline = if (ErosProfileManager.selected.text.obfuscated) {
|
||||||
|
val index = AtomicInteger()
|
||||||
Timeline(
|
Timeline(
|
||||||
KeyFrame(Duration.millis(50.0), {
|
KeyFrame(Duration.millis(50.0), {
|
||||||
val chars = text.text.toCharArray()
|
val chars = text.text.toCharArray()
|
||||||
for (i in chars.indices) {
|
for (i in chars.indices) {
|
||||||
chars[i] = ProtocolDefinition.OBFUSCATED_CHARS.random()
|
chars[i] = ProtocolDefinition.OBFUSCATED_CHARS[index.getAndIncrement() % ProtocolDefinition.OBFUSCATED_CHARS.size]
|
||||||
}
|
}
|
||||||
text.text = String(chars)
|
text.text = String(chars)
|
||||||
}),
|
}),
|
||||||
|
@ -28,7 +28,6 @@ import kotlin.test.assertSame
|
|||||||
|
|
||||||
internal class ChatComponentTest {
|
internal class ChatComponentTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testEmpty() {
|
fun testEmpty() {
|
||||||
assertSame(ChatComponent.EMPTY, "".chat())
|
assertSame(ChatComponent.EMPTY, "".chat())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user