Skip to content

Commit

Permalink
[ #23 ] Refactored to save memory. Now it's perfectly implemented.
Browse files Browse the repository at this point in the history
Closes #23.
  • Loading branch information
ice1000 committed Dec 8, 2017
1 parent 633e3c2 commit 1429dfc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/org/frice/Game.kt
Expand Up @@ -133,9 +133,15 @@ open class Game @JvmOverloads constructor(layerCount: Int = 1) : JFrame(), Frice
}

override fun measureText(text: FText): FRectangle {
val font = text.`font tmp obj`
val g = drawer.g
return FRectangle(if (font is Font) font.getStringBounds(text.text, g.fontRenderContext) else g.fontMetrics.getStringBounds(text.text, g))
val font = text.`font tmp obj` as? Font ?: g.font
return FRectangle(font.getStringBounds(text.text, g.fontRenderContext))
}

override fun measureTextWidth(text: FText): Int {
val g = drawer.g
val font = text.`font tmp obj` as? Font ?: g.font
return g.getFontMetrics(font).stringWidth(text.text)
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/org/frice/platform/FriceGame.kt
Expand Up @@ -228,10 +228,18 @@ interface FriceGame : TitleOwner, Sized, Resizable {

/**
* measures the width and height of the text.
* @see measureTextWidth if you only care about the width
* @param text the text
* @return the width and height of the text, according to it's font
*/
fun measureText(text: FText): FRectangle
fun measureTextWidth(text: FText): Int = measureText(text).width

/**
* if you only care about width, choose this.
* @param text the text
* @return the width of the text, according to it's font
*/
fun measureTextWidth(text: FText): Int

fun measureTextHeight(text: FText): Int = measureText(text).height
}

0 comments on commit 1429dfc

Please sign in to comment.