diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/ControlManager.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/ControlManager.kt index 174545ae..883971c0 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/ControlManager.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/ControlManager.kt @@ -276,6 +276,8 @@ class ControlManager : Extension { val mouseInput = MouseInput() override fun setup(program: Program) { + + fontManager.program = program this.program = program contentScale = program.window.contentScale diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/FontManager.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/FontManager.kt index a750ccf7..43020928 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/FontManager.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/FontManager.kt @@ -1,12 +1,15 @@ package org.openrndr.panel +import org.openrndr.Program import org.openrndr.draw.FontImageMap +import org.openrndr.draw.loadFont import org.openrndr.panel.style.LinearDimension import org.openrndr.panel.style.StyleSheet import org.openrndr.panel.style.fontFamily import org.openrndr.panel.style.fontSize -class FontManager { +class FontManager() { + var program: Program? = null val registry: MutableMap = mutableMapOf() var contentScale: Double = 1.0 @@ -15,7 +18,7 @@ class FontManager { fun font(cs: StyleSheet): FontImageMap { val fontUrl = resolve(cs.fontFamily) ?: "cp:fonts/Roboto-Medium.ttf" val fontSize = (cs.fontSize as? LinearDimension.PX)?.value ?: 16.0 - return FontImageMap.fromUrl(fontUrl, fontSize, contentScale = contentScale) + return program?.loadFont(fontUrl, fontSize) ?: error("no program") } fun register(name: String, url: String) { diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Button.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Button.kt index 667dceb6..c0e3a5ff 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Button.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Button.kt @@ -2,9 +2,9 @@ package org.openrndr.panel.elements import org.openrndr.color.ColorRGBa import org.openrndr.draw.Drawer -import org.openrndr.draw.FontImageMap import org.openrndr.draw.isolated +import org.openrndr.draw.loadFont import org.openrndr.events.Event import org.openrndr.extra.textwriter.TextWriter import org.openrndr.panel.style.* @@ -52,7 +52,9 @@ class Button : Element(ElementType("button")) { computedStyle.let { style -> val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily) ?: "broken" val fontSize = (style.fontSize as? LinearDimension.PX)?.value ?: 14.0 - val fontMap = FontImageMap.fromUrl(fontUrl, fontSize) + + val program = (root() as? Body)?.controlManager?.program ?: error("no program") + val fontMap = program.loadFont(fontUrl, fontSize) val writer = TextWriter(null) diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/DropdownButton.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/DropdownButton.kt index d98d7f9e..faee2f10 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/DropdownButton.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/DropdownButton.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.yield import org.openrndr.KEY_ARROW_DOWN import org.openrndr.KEY_ARROW_UP import org.openrndr.KEY_ENTER +import org.openrndr.draw.loadFont import org.openrndr.events.Event import org.openrndr.launch @@ -79,7 +80,10 @@ class DropdownButton : Element(ElementType("dropdown-button")), DisposableElemen computedStyle.let { style -> val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily) ?: "broken" val fontSize = (style.fontSize as? LinearDimension.PX)?.value ?: 16.0 - val fontMap = FontImageMap.fromUrl(fontUrl, fontSize) + + val program = (root() as? Body)?.controlManager?.program ?: error("no program") + val fontMap = program.loadFont(fontUrl, fontSize) + val writer = TextWriter(null) writer.box = Rectangle(0.0, diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/TextElements.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/TextElements.kt index 52c38b1a..b398f7d0 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/TextElements.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/TextElements.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.yield import org.openrndr.color.ColorRGBa import org.openrndr.draw.Drawer import org.openrndr.draw.FontImageMap +import org.openrndr.draw.loadFont import org.openrndr.extra.textwriter.TextWriter import org.openrndr.launch @@ -34,7 +35,8 @@ class TextNode(var text: String) : Element(ElementType("text")) { computedStyle.let { style -> val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily)?:"broken" val fontSize = (style.fontSize as? LinearDimension.PX)?.value?: 14.0 - val fontMap = FontImageMap.fromUrl(fontUrl, fontSize) + val program = (root() as? Body)?.controlManager?.program ?: error("no program") + val fontMap = program.loadFont(fontUrl, fontSize) val writer = TextWriter(null) diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt index 0e7490de..4731d2a4 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Toggle.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.* import org.openrndr.draw.Drawer import org.openrndr.draw.FontImageMap import org.openrndr.draw.LineCap +import org.openrndr.draw.loadFont import org.openrndr.panel.style.* import org.openrndr.shape.Rectangle @@ -34,7 +35,8 @@ class Toggle : Element(ElementType("toggle")), DisposableElement { computedStyle.let { style -> val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily) ?: "broken" val fontSize = (style.fontSize as? LinearDimension.PX)?.value ?: 14.0 - val fontMap = FontImageMap.fromUrl(fontUrl, fontSize) + val program = (root() as? Body)?.controlManager?.program ?: error("no program") + val fontMap = program.loadFont(fontUrl, fontSize) val writer = TextWriter(null) diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/tools/Tooltip.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/tools/Tooltip.kt index 7f71cfce..0b744d7c 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/tools/Tooltip.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/tools/Tooltip.kt @@ -4,6 +4,7 @@ import org.openrndr.color.ColorRGBa import org.openrndr.draw.Drawer import org.openrndr.draw.FontImageMap import org.openrndr.draw.isolated +import org.openrndr.draw.loadFont import org.openrndr.extra.textwriter.writer import org.openrndr.math.Vector2 @@ -16,7 +17,9 @@ class Tooltip(val parent: Element, val position: Vector2, val message: String) { val fontUrl = (parent.root() as Body).controlManager.fontManager.resolve("default") ?: error("no font") val fontSize = 14.0 - val fontMap = FontImageMap.fromUrl(fontUrl, fontSize) + val program = (parent.root() as? Body)?.controlManager?.program ?: error("no program") + val fontMap = program.loadFont(fontUrl, fontSize) + val lines = message.split("\n") drawer.isolated {