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