Skip to content

Commit

Permalink
Camera: add parameter to allow text centering
Browse files Browse the repository at this point in the history
  • Loading branch information
smlpt committed Aug 27, 2024
1 parent 2374c1a commit 404031b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/kotlin/graphics/scenery/Camera.kt
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,30 @@ open class Camera : DefaultNode("Camera"), HasRenderable, HasMaterial, HasCustom
*
* It will be shown for [duration] milliseconds, with a default of 3000.
*/
@JvmOverloads fun showMessage(message: String, distance: Float = 0.75f, size: Float = 0.05f, messageColor: Vector4f = Vector4f(1.0f), backgroundColor: Vector4f = Vector4f(0.0f), duration: Int = 3000) {
@JvmOverloads
fun showMessage(

Check warning on line 340 in src/main/kotlin/graphics/scenery/Camera.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/kotlin/graphics/scenery/Camera.kt#L340

The function showMessage(message: String, distance: Float, size: Float, messageColor: Vector4f, backgroundColor: Vector4f, duration: Int, centered: Boolean) has too many parameters. The current threshold is set to 6.
message: String,
distance: Float = 0.75f,
size: Float = 0.05f,
messageColor: Vector4f = Vector4f(1.0f),
backgroundColor: Vector4f = Vector4f(0.0f),
duration: Int = 3000,
centered: Boolean = false
) {
val tb = TextBoard()
tb.fontColor = messageColor
tb.backgroundColor = backgroundColor
tb.text = message
// Calculate the offset for text centering based on message length.
// The second divisor was eyeballed and might need adjustment.
val offset = if (centered) {
size * message.length.toFloat() / 2f / 5f
} else {
0f
}
tb.spatial {
scale = Vector3f(size, size, size)
position = Vector3f(0.0f, 0.0f, -1.0f * distance)
position = Vector3f(0.0f - offset, 0.0f, -1.0f * distance)
}

@Suppress("UNCHECKED_CAST")
Expand Down

0 comments on commit 404031b

Please sign in to comment.