comparison src/samer/mds/MatrixBall.java.not @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 package samer.mds;
2 import java.awt.*;
3 import java.awt.image.*;
4 import java.awt.event.*;
5 import samer.core.types.*;
6 import samer.core.*;
7 import art.oz.*;
8
9 public class MatrixBall implements Drawable, Updatable
10 {
11 // instance data .....................................
12
13 int x, y, ox, oy;
14 double rx, ry;
15 boolean changed=true;
16
17 protected Rectangle dirty=new Rectangle();
18
19 public MatrixBall() {
20 ox = x = 0; oy = y = 0;
21 rx = 0; ry = 0;
22 }
23
24
25 // static data ........................................
26
27 static Image defaultBlob;
28 static int IW=4, IH=4;
29
30 public void draw( Graphics2D g) { g.drawImage( defaultBlob, ox=x, oy=y, null); }
31 public void undraw( Graphics2D g) { g.clearRect( ox, oy, IW, IH); }
32
33
34 public void moveTo(int x, int y) { this.x=x; this.y=y; }
35
36 Rectangle tmp=new Rectangle();
37
38 public void update( Oz oz) {
39 dirty.setBounds(x,y,IW,IH);
40 Oz.union(dirty,ox,oy,IW,IH);
41 oz.invalidateRect(dirty);
42 }
43
44 public static Image getImage() { return defaultBlob; }
45 public static void setImage(Image normal) {
46 defaultBlob = normal;
47 }
48
49 public static void setBallSize(int w, int h)
50 {
51 IW=w; IH=h;
52 defaultBlob = new BufferedImage(IW,IH,BufferedImage.TYPE_4BYTE_ABGR_PRE);
53 }
54
55 public static void drawBall( Image img, Color c, float alpha)
56 {
57 Graphics2D g=(Graphics2D)img.getGraphics();
58 AlphaComposite comp;
59
60 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
61 g.setBackground(new Color(0,0,0,0));
62 g.clearRect(0,0,IW,IH);
63 g.setComposite( AlphaComposite.SrcOver);
64 drawBall(g,c,alpha);
65 g.dispose();
66 }
67
68 public static void drawMarker( Image img, Color c, float alpha)
69 {
70 Graphics2D g=(Graphics2D)img.getGraphics();
71 AlphaComposite comp;
72
73 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
74 g.setBackground(new Color(0,0,0,0));
75 g.clearRect(0,0,IW,IH);
76 g.setComposite( AlphaComposite.SrcOver);
77 float [] rgba=c.getRGBComponents(null);
78
79 // ball image has transparent background
80 g.setColor(new Color(0,0,0,80));
81 g.fillRect(0,0,IW,IH);
82 g.setColor(new Color(rgba[0],rgba[1],rgba[2],alpha));
83 g.fillRect(1,1,IW-2,IH-2);
84 g.dispose();
85 }
86
87 public static void drawBall( Graphics2D g, Color c, float alpha)
88 {
89 int cx = IW/2;
90 int cy = IH/2;
91
92 float [] rgba=c.getRGBComponents(null);
93 // float [] rgba2=c.brighter().getRGBComponents(null);
94
95 // ball image has transparent background
96 g.setColor(new Color(0,0,0,80));
97 oval(g,cx+1,cy+1,IW/2-2,IH/2-2);
98 g.setColor(new Color(rgba[0],rgba[1],rgba[2],alpha));
99 oval(g,cx,cy,IW/2-3,IH/2-3);
100 // g.setColor(new Color(rgba2[0],rgba2[1],rgba2[2],alpha));
101 // oval(g,4*cx/5,4*cy/5,IH/6,IW/6);
102 }
103
104 static void oval(Graphics2D g, int x, int y, int rx, int ry) {
105 g.fillOval(x-rx,y-ry,2*rx,2*ry);
106 }
107 }