samer@0: package samer.mds; samer@0: import java.awt.*; samer@0: import java.awt.image.*; samer@0: import java.awt.event.*; samer@0: import samer.core.types.*; samer@0: import samer.core.*; samer@0: import art.oz.*; samer@0: samer@0: public class MatrixBall implements Drawable, Updatable samer@0: { samer@0: // instance data ..................................... samer@0: samer@0: int x, y, ox, oy; samer@0: double rx, ry; samer@0: boolean changed=true; samer@0: samer@0: protected Rectangle dirty=new Rectangle(); samer@0: samer@0: public MatrixBall() { samer@0: ox = x = 0; oy = y = 0; samer@0: rx = 0; ry = 0; samer@0: } samer@0: samer@0: samer@0: // static data ........................................ samer@0: samer@0: static Image defaultBlob; samer@0: static int IW=4, IH=4; samer@0: samer@0: public void draw( Graphics2D g) { g.drawImage( defaultBlob, ox=x, oy=y, null); } samer@0: public void undraw( Graphics2D g) { g.clearRect( ox, oy, IW, IH); } samer@0: samer@0: samer@0: public void moveTo(int x, int y) { this.x=x; this.y=y; } samer@0: samer@0: Rectangle tmp=new Rectangle(); samer@0: samer@0: public void update( Oz oz) { samer@0: dirty.setBounds(x,y,IW,IH); samer@0: Oz.union(dirty,ox,oy,IW,IH); samer@0: oz.invalidateRect(dirty); samer@0: } samer@0: samer@0: public static Image getImage() { return defaultBlob; } samer@0: public static void setImage(Image normal) { samer@0: defaultBlob = normal; samer@0: } samer@0: samer@0: public static void setBallSize(int w, int h) samer@0: { samer@0: IW=w; IH=h; samer@0: defaultBlob = new BufferedImage(IW,IH,BufferedImage.TYPE_4BYTE_ABGR_PRE); samer@0: } samer@0: samer@0: public static void drawBall( Image img, Color c, float alpha) samer@0: { samer@0: Graphics2D g=(Graphics2D)img.getGraphics(); samer@0: AlphaComposite comp; samer@0: samer@0: g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); samer@0: g.setBackground(new Color(0,0,0,0)); samer@0: g.clearRect(0,0,IW,IH); samer@0: g.setComposite( AlphaComposite.SrcOver); samer@0: drawBall(g,c,alpha); samer@0: g.dispose(); samer@0: } samer@0: samer@0: public static void drawMarker( Image img, Color c, float alpha) samer@0: { samer@0: Graphics2D g=(Graphics2D)img.getGraphics(); samer@0: AlphaComposite comp; samer@0: samer@0: g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); samer@0: g.setBackground(new Color(0,0,0,0)); samer@0: g.clearRect(0,0,IW,IH); samer@0: g.setComposite( AlphaComposite.SrcOver); samer@0: float [] rgba=c.getRGBComponents(null); samer@0: samer@0: // ball image has transparent background samer@0: g.setColor(new Color(0,0,0,80)); samer@0: g.fillRect(0,0,IW,IH); samer@0: g.setColor(new Color(rgba[0],rgba[1],rgba[2],alpha)); samer@0: g.fillRect(1,1,IW-2,IH-2); samer@0: g.dispose(); samer@0: } samer@0: samer@0: public static void drawBall( Graphics2D g, Color c, float alpha) samer@0: { samer@0: int cx = IW/2; samer@0: int cy = IH/2; samer@0: samer@0: float [] rgba=c.getRGBComponents(null); samer@0: // float [] rgba2=c.brighter().getRGBComponents(null); samer@0: samer@0: // ball image has transparent background samer@0: g.setColor(new Color(0,0,0,80)); samer@0: oval(g,cx+1,cy+1,IW/2-2,IH/2-2); samer@0: g.setColor(new Color(rgba[0],rgba[1],rgba[2],alpha)); samer@0: oval(g,cx,cy,IW/2-3,IH/2-3); samer@0: // g.setColor(new Color(rgba2[0],rgba2[1],rgba2[2],alpha)); samer@0: // oval(g,4*cx/5,4*cy/5,IH/6,IW/6); samer@0: } samer@0: samer@0: static void oval(Graphics2D g, int x, int y, int rx, int ry) { samer@0: g.fillOval(x-rx,y-ry,2*rx,2*ry); samer@0: } samer@0: }