Commit 2cb19f4b authored by h2b's avatar h2b

Dimension class introduced for better expression.

parent daf38561
......@@ -48,15 +48,17 @@ object Font {
trait FontMetrics { font: Font
case class Dimension (width: Int, height: Int)
/**
* @return the (width, height) of this character in pixels
*/
def dimension (c: Char): (Int, Int)
def dimension (c: Char): Dimension
/**
* @return the (width, height) of this string in pixels
*/
def dimension (s: String): (Int, Int)
def dimension (s: String): Dimension
/**
* @return a new font metrics derived from this metrics using the specified
......
......@@ -75,8 +75,8 @@ trait AwtScreenDriver extends ScreenDriver {
val f = new Font(size, emphasis) with FontMetrics {
val metrics = graphics.getFontMetrics
val h = metrics.getHeight
def dimension (c: Char): (Int, Int) = (metrics.charWidth(c), h)
def dimension (s: String): (Int, Int) = (metrics.stringWidth(s), h)
def dimension (c: Char): Dimension = Dimension(metrics.charWidth(c), h)
def dimension (s: String): Dimension = Dimension(metrics.stringWidth(s), h)
def derived (font: Font): Font with FontMetrics = newFont(font.size, font.emphasis)
}
f
......
......@@ -48,7 +48,7 @@ object FontDemo extends App {
println(s + ": \tX→" + screen.activeFont.dimension(testChar) +
" \tabc→" + screen.activeFont.dimension(testString))
screen.drawText(p, testText)
p += Pixel(0, 10+screen.activeFont.dimension(testText)._2)
p += Pixel(0, 10+screen.activeFont.dimension(testText).height)
}
}
......@@ -62,7 +62,7 @@ object FontDemo extends App {
for (s Font.Size.values) {
screen.activeFont = f0.derived(Font(s, emph))
screen.drawText(p, testText)
p += Pixel(0, 10+screen.activeFont.dimension(testText)._2)
p += Pixel(0, 10+screen.activeFont.dimension(testText).height)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment