Mercurial > hg > charamega
changeset 9:2efb0973ab83
Cleaned up the rendering code.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Tue, 17 Jul 2012 05:08:17 +0400 |
parents | cf757c4466b8 |
children | 6e6b00d95d0b |
files | src/net/kryshen/charamega/field.mirah |
diffstat | 1 files changed, 13 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/net/kryshen/charamega/field.mirah Mon Jul 16 07:50:02 2012 +0400 +++ b/src/net/kryshen/charamega/field.mirah Tue Jul 17 05:08:17 2012 +0400 @@ -103,10 +103,10 @@ g = Graphics2D(g1) g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON) + RenderingHints.VALUE_ANTIALIAS_ON) g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON) - + w = getWidth h = getHeight @@ -129,9 +129,7 @@ rm_scale = 2.0 - outer = Rectangle2D.Double.new - inner = Rectangle2D.Double.new - border = Path2D.Double.new(Path2D.WIND_EVEN_ODD) + card_bounds = Rectangle2D.Double.new save_t = g.getTransform @@ -173,13 +171,8 @@ g.rotate card.angle * v - outer.setRect(-card_size / 2, -card_size / 2, - card_size, card_size) - inner.setRect(1 - card_size / 2, 1 - card_size / 2, - card_size - 2, card_size - 2) - border.reset - border.append outer, false - border.append inner, false + card_bounds.setRect(-card_size / 2, -card_size / 2, + card_size, card_size) if f > 0 g.setColor with_alpha(@face_color, v) @@ -187,24 +180,24 @@ g.setColor with_alpha(@back_color, v) end - g.fill inner + g.fill card_bounds if f > 0 g.setColor with_alpha(@symbol_color, Math.sqrt(v)) gv = font.createGlyphVector(frc, String.valueOf(card.symbol)) - sb = gv.getVisualBounds + gb = gv.getVisualBounds # Scale down if the glyph does not fit. - tolerance = 0.95 - scale = Math.min(inner.getWidth * tolerance / sb.getWidth, - inner.getHeight * tolerance / sb.getHeight) + k = 0.9 + scale = Math.min(card_bounds.width * k / gb.getWidth, + card_bounds.height * k / gb.getHeight) save_t_2 = g.getTransform g.scale scale, scale if scale < 1.0 g.drawGlyphVector(gv, - -float(sb.getX + sb.getWidth / 2), - -float(sb.getY + sb.getHeight / 2)) + -float(gb.getX + gb.getWidth / 2), + -float(gb.getY + gb.getHeight / 2)) g.setTransform save_t_2 end @@ -215,7 +208,7 @@ g.setColor with_alpha(@border_color, v) end - g.fill border + g.draw card_bounds g.setTransform save_t end