Mercurial > hg > ristipolku
diff game/Engine.java @ 171:5070e57ebbfc
Move text drawing stuff to IDMWidget class.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Mar 2017 10:19:04 +0200 |
parents | b9bc493ae53c |
children | 8995a0363e0a |
line wrap: on
line diff
--- a/game/Engine.java Thu Mar 02 15:57:15 2017 +0200 +++ b/game/Engine.java Mon Mar 06 10:19:04 2017 +0200 @@ -25,12 +25,6 @@ BufferedImage aboutImg; boolean aboutSecret; - IDMPoint currPos, currOffs; - Paint textPaint; - Font textFont; - FontMetrics textMetrics; - - public AboutBox() { try { @@ -47,74 +41,6 @@ setSize(720f, 420f); } - public void setTextFont(Font font, FontMetrics metrics) - { - textFont = font; - textMetrics = metrics; - } - - public void setTextPaint(Paint paint) - { - textPaint = paint; - } - - public void setCurrPos(IDMPoint npos) - { - currPos = npos; - currOffs = new IDMPoint(0, 0); - } - - public void setCurrPos(float x, float y) - { - setCurrPos(new IDMPoint(x, y)); - } - - public void setCurrPosScaledRel(float x, float y) - { - setCurrPos(new IDMPoint(getScaledRelX(x), getScaledRelY(y))); - } - - public void drawString(Graphics2D g, String text) - { - Paint savePaint = g.getPaint(); - g.setPaint(textPaint); - g.setFont(textFont); - - int i = 0; - while (i < text.length()) - { - int p = text.indexOf("\n", i); - boolean linefeed; - String str; - if (p >= i) - { - str = text.substring(i, p); - i = p + 1; - linefeed = true; - } - else - { - str = text.substring(i); - i += str.length(); - linefeed = false; - } - - g.drawString(str, currPos.x + currOffs.x, currPos.y + currOffs.y); - - if (linefeed) - { - currOffs.x = 0; - currOffs.y += textMetrics.getHeight(); - } - else - { - currOffs.x += textMetrics.stringWidth(str); - } - } - - g.setPaint(savePaint); - } - public void paint(Graphics2D g) { g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.7f)); @@ -154,7 +80,7 @@ setTextPaint(Color.red); drawString(g, "Controls:\n"); - IDMPoint old = currOffs.copy(); + IDMPoint old = textCurrOffs.copy(); setTextPaint(Color.white); drawString(g, @@ -162,14 +88,14 @@ "Enter / mouse click\n"+ "Space bar\n"); - currPos.x += getScaledX(330); - currOffs.y = old.y; + textCurrPos.x += getScaledX(330); + textCurrOffs.y = old.y; drawString(g, "- Rotate piece\n" + "- Place/lock piece\n" + "- Swap piece\n"); - currPos.x -= getScaledX(330); + textCurrPos.x -= getScaledX(330); setTextPaint(Color.green); drawString(g, "\nObjective: Create a path long as possible by rotating\n"+