Mercurial > hg > ristipolku
changeset 50:496e616ff09d
More work on IDMgui.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Feb 2011 11:45:40 +0200 |
parents | e6da5c71be28 |
children | f81f76458b92 |
files | game/Engine.java game/IDMButton.java game/IDMContainer.java game/IDMWidget.java |
diffstat | 4 files changed, 64 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/game/Engine.java Tue Feb 22 10:52:08 2011 +0200 +++ b/game/Engine.java Tue Feb 22 11:45:40 2011 +0200 @@ -88,7 +88,7 @@ score = 0; soundManager = smgr; - sndPlaced = soundManager.getSound("sounds/placed.wav"); +// sndPlaced = soundManager.getSound("sounds/placed.wav"); } public void paint(Graphics2D g, int sx, int sy, float scale) @@ -253,6 +253,7 @@ IDMContainer widgets; BtnNewGame btnNewGame; + BtnSwapPiece btnSwapPiece; public Engine() { @@ -296,6 +297,9 @@ btnNewGame = new BtnNewGame(); widgets.add(btnNewGame); + btnSwapPiece = new BtnSwapPiece(); + widgets.add(btnSwapPiece); + // Game startNewGame(); @@ -347,21 +351,19 @@ System.out.print("scale changed\n"); - btnNewGame.move(dim.width - 200, dim.height - 100); + btnNewGame.move(dim.width - 200, dim.height - 150); + btnSwapPiece.move(dim.width - 200, dim.height - 400); } // Background, pieces g2.drawImage(lautaBGScaled, 0, 0, null); lauta.paint(g2, 100, 150, 60); - - btnNewGame.paint(g2); + widgets.paint(g2); // Scores g2.setFont(font1); g2.setPaint(Color.white); - - - // Other elements + long currTime = new Date().getTime(); g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20); } @@ -471,4 +473,16 @@ startNewGame(); } } + + class BtnSwapPiece extends IDMButton + { + public BtnSwapPiece() + { + super(0, 0, KeyEvent.VK_SPACE, font1, "Swap Piece"); + } + + public void clicked() + { + } + } }
--- a/game/IDMButton.java Tue Feb 22 10:52:08 2011 +0200 +++ b/game/IDMButton.java Tue Feb 22 11:45:40 2011 +0200 @@ -21,6 +21,7 @@ Font font; FontMetrics metrics; String text; + boolean active; public IDMButton(Point pos, int keyCode, Font font, String text) { @@ -30,6 +31,7 @@ this.keyCode = keyCode; this.text = text; state = State.NORMAL; + active = false; } public IDMButton(int x, int y, int keyCode, Font font, String text) @@ -71,7 +73,7 @@ if (state == State.PRESSED) { img = imgPressed; - xoffs = yoffs = 15; + xoffs = yoffs = 5; } else { @@ -88,8 +90,8 @@ g.setFont(font); g.setPaint(Color.black); g.drawString(text, - pos.x + xoffs + (img.getWidth() - textWidth) / 2, - pos.y + yoffs + (img.getHeight() - metrics.getHeight() / 2) / 2); + pos.x + xoffs * 2 + (img.getWidth() - textWidth) / 2, + pos.y + yoffs * 2 + (img.getHeight() / 2)); } public boolean contains(Point where) @@ -102,15 +104,26 @@ public void mousePressed(MouseEvent e) { state = State.PRESSED; + active = true; } public void mouseReleased(MouseEvent e) { super.mouseReleased(e); state = State.NORMAL; + active = false; } - public void clicked() + public void mouseEntered(MouseEvent e) { + if (active) + { + state = State.PRESSED; + } + } + + public void mouseExited(MouseEvent e) + { + state = State.NORMAL; } }
--- a/game/IDMContainer.java Tue Feb 22 10:52:08 2011 +0200 +++ b/game/IDMContainer.java Tue Feb 22 11:45:40 2011 +0200 @@ -42,7 +42,24 @@ { for (IDMWidget widget : widgets) { - widget.mousePressed(e); + widget.mouseReleased(e); + } + } + + public void mouseExited(MouseEvent e) + { + for (IDMWidget widget : widgets) + { + widget.mouseExited(e); + } + } + + public void mouseEntered(MouseEvent e) + { + for (IDMWidget widget : widgets) + { + if (widget.contains(e.getPoint())) + widget.mouseEntered(e); } }
--- a/game/IDMWidget.java Tue Feb 22 10:52:08 2011 +0200 +++ b/game/IDMWidget.java Tue Feb 22 11:45:40 2011 +0200 @@ -33,9 +33,15 @@ public void mouseReleased(MouseEvent e) { if (contains(e.getPoint())) - { clicked(); - } + } + + public void mouseEntered(MouseEvent e) + { + } + + public void mouseExited(MouseEvent e) + { } // Generic key handler