changeset 133:881deac2daf8

Some more work on scaling widgets, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Nov 2011 21:50:41 +0200
parents 333df3e1155b
children 4c0dec72e2f0
files Makefile game/Engine.java game/IDMButton.java
diffstat 3 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Nov 24 21:34:33 2011 +0200
+++ b/Makefile	Thu Nov 24 21:50:41 2011 +0200
@@ -13,8 +13,8 @@
 	game/AnimatedPointElement.class
 
 # Utils
-JAVAC=javac -g
-APPLETVIEWER=appletviewer
+JAVAC=javac -g -Xlint:unchecked
+APPLETVIEWER=aoss appletviewer
 
 ###
 ### Targets
--- a/game/Engine.java	Thu Nov 24 21:34:33 2011 +0200
+++ b/game/Engine.java	Thu Nov 24 21:50:41 2011 +0200
@@ -204,7 +204,7 @@
     static final int boardMiddle = 4;
     Piece[][] board;
     float pscale, ptime;
-
+    
     public boolean flagGameOver;
     int gameScore;
 
@@ -230,6 +230,7 @@
     
     public void startNewGame()
     {
+    
         board = new Piece[boardSize][boardSize];
         board[boardMiddle][boardMiddle] = new Piece(PieceType.START);
 
@@ -567,14 +568,14 @@
         System.out.print("Engine() constructor\n");
         
         // Sound system
-        G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 16);
+        G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 1);
 
         // Load resources
         try
         {
             ResourceLoader res = new ResourceLoader("graphics/board.jpg");
             G.lautaBG = ImageIO.read(res.getStream());
-
+            
             try {
                 res = new ResourceLoader("graphics/font.ttf");
                 
@@ -583,7 +584,6 @@
                 G.fonts[1] = G.fonts[0].deriveFont(24f);
                 G.fonts[2] = G.fonts[0].deriveFont(64f);
                 G.fonts[3] = G.fonts[0].deriveFont(32f);
-                
             }
             catch (FontFormatException e)
             {
@@ -646,13 +646,17 @@
     public void paintComponent(Graphics g)
     {
         Graphics2D g2 = (Graphics2D) g;
+        boolean scaleChanged = false;
         
         // Rescale if parent component size has changed
         Dimension dim = getSize();
         if (G.screenDim == null || !dim.equals(G.screenDim))
         {
+            float dw = dim.width / 1024.0f,
+                  dh = dim.height / 768.0f;
+            
             // Rescale IDM GUI widgets
-            widgets.setScale(dim.width / 1024.0f, dim.height / 768.0f);
+            widgets.setScale(dw, dh);
             G.screenDim = dim;
 
             // Rescale background image
@@ -664,11 +668,17 @@
             gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null); 
             lauta.paintBackPlate(gimg);
 
+            // Rescale fonts
+            G.fonts[1] = G.fonts[0].deriveFont(24f * dw);
+            G.fonts[2] = G.fonts[0].deriveFont(64f * dw);
+            G.fonts[3] = G.fonts[0].deriveFont(32f * dw);
+            
             System.out.print("scale changed\n");
+            scaleChanged = true;
         }
         
         // Get font metrics against current Graphics2D context
-        if (G.metrics == null)
+        if (G.metrics == null || scaleChanged)
         {
             G.metrics = new FontMetrics[G.numFonts];
             for (int i = 0; i < G.numFonts; i++)
--- a/game/IDMButton.java	Thu Nov 24 21:34:33 2011 +0200
+++ b/game/IDMButton.java	Thu Nov 24 21:50:41 2011 +0200
@@ -59,6 +59,10 @@
             System.out.print(e.getMessage());
         }
     }
+
+    public void scale()
+    {
+    }
     
     public void paint(Graphics2D g)
     {