[Commit] RRClient RRBoardPanel.java,1.3,1.4 RRImages.java,1.3,1.4

Bart Massey commit at keithp.com
Sat Jun 7 01:45:05 PDT 2003


Committed by: bart

Update of /local/src/CVS/RRClient
In directory home.keithp.com:/tmp/cvs-serv14368

Modified Files:
	RRBoardPanel.java RRImages.java 
Log Message:
Renders non-primary targets as dimmed (alpha 0.25) images
now.



Index: RRBoardPanel.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRBoardPanel.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- RRBoardPanel.java	7 Jun 2003 07:03:10 -0000	1.3
+++ RRBoardPanel.java	7 Jun 2003 07:45:02 -0000	1.4
@@ -46,9 +46,8 @@
                 RRSquare s = board.getSquare(row, col);
 		if (s.getTarget() == RRSquare.NO_TARGET)
 		    continue;
-		if (!s.isPrimaryTarget())
-		    continue;
-		Image img = images.getTargetImage(s.getTarget(), true);
+		boolean primary = s.isPrimaryTarget();
+		Image img = images.getTargetImage(s.getTarget(), primary);
 		int xdcol = (int)Math.floor(col * dcol);
 		int ydrow = (int)Math.floor(row * drow);
 		g.drawImage(img, xdcol, ydrow, idcol, idrow, this);

Index: RRImages.java
===================================================================
RCS file: /local/src/CVS/RRClient/RRImages.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- RRImages.java	7 Jun 2003 07:03:10 -0000	1.3
+++ RRImages.java	7 Jun 2003 07:45:02 -0000	1.4
@@ -11,13 +11,14 @@
 
 import javax.swing.*;
 import java.awt.*;
+import java.awt.image.*;
 
-class GetImage {
+class ToolkitProxy {
     JApplet applet = null;
     Toolkit tk = null;
     
-    GetImage(JApplet applet) { this.applet = applet; }
-    GetImage(Toolkit tk) { this.tk = tk; }
+    ToolkitProxy(JApplet applet) { this.applet = applet; }
+    ToolkitProxy(Toolkit tk) { this.tk = tk; }
 
     Image getImage(String name) {
 	Image result;
@@ -31,6 +32,35 @@
 	    throw new Error("Can't load image " + name);
 	return result;
     }
+
+    Image createImage(ImageProducer src) {
+	Image result;
+        if (tk != null)
+            result = tk.createImage(src);
+        else if (applet != null)
+            result = applet.createImage(src);
+	else
+            throw new Error("No image creation");
+	if (result == null)
+	    throw new Error("Can't create image");
+	return result;
+    }
+}
+
+class DimFilter extends RGBImageFilter {
+    public DimFilter() {
+	// The filter's operation does not depend on the
+	// pixel's location, so IndexColorModels can be
+	// filtered directly.
+	canFilterIndexColorModel = true;
+    }
+
+    public int filterRGB(int x, int y, int rgb) {
+	int color = rgb & 0x00ffffff;
+	int alpha = (rgb >> 24) & 0xff;
+	alpha = alpha / 4;
+	return (alpha << 24) | color;
+    }
 }
 
 public class RRImages {
@@ -41,9 +71,10 @@
 
     Image blank_image;
     Image[] target_images = new Image[17];
+    Image[] dim_target_images = new Image[17];
     Image[] robot_images = new Image[4];
 
-    GetImage imgsrc;
+    ToolkitProxy tkproxy;
 
     int[] colors = {
       RRSquare.RED,
@@ -54,26 +85,37 @@
     String[] colornames = {"red", "yellow", "green", "blue"};
     String[] shapenames = {"circle", "square", "triangle", "star"};
 
-    private RRImages(GetImage imgsrc) {
-        this.imgsrc = imgsrc;
-        blank_image = imgsrc.getImage("blank.png");
+    private RRImages(ToolkitProxy tkproxy) {
+        this.tkproxy = tkproxy;
+	/* get the floor tile */
+        blank_image = tkproxy.getImage("blank.png");
+	/* get the target symbols */
         for (int i = 0; i < 16; i++)
             target_images[i] =
-                imgsrc.getImage("target-" +
+                tkproxy.getImage("target-" +
                            colornames[colors[i / 4]] + "-" +
                            shapenames[i % 4] + ".png");
-        target_images[16] = imgsrc.getImage("target-whirlpool.png");
+        target_images[16] = tkproxy.getImage("target-whirlpool.png");
+	/* make dimmed versions of the target symbols */
+	ImageFilter dim_filter = new DimFilter();
+	for (int i = 0; i < 17; i++) {
+	    ImageProducer img = target_images[i].getSource();
+	    FilteredImageSource src =
+		new FilteredImageSource(img, dim_filter);
+	    dim_target_images[i] = tkproxy.createImage(src);
+	}
+	/* get the robot symbols */
         for (int i = 0; i < 4; i++)
-            robot_images[i] = imgsrc.getImage("robot-" +
+            robot_images[i] = tkproxy.getImage("robot-" +
                                          colornames[colors[i]] + ".png");
     }
 
     public RRImages(Toolkit tk) {
-        this(new GetImage(tk));
+        this(new ToolkitProxy(tk));
     }
 
     public RRImages(JApplet applet) {
-        this(new GetImage(applet));
+        this(new ToolkitProxy(applet));
     }
 
     public Image getBlankImage() {
@@ -81,7 +123,9 @@
     }
 
     public Image getTargetImage(int index, boolean primary) {
-        return target_images[index];
+	if (primary)
+	    return target_images[index];
+	return dim_target_images[index];
     }
 
     public Image getRobotImage(int index) {




More information about the Commit mailing list