annotate src/samer/mds/MatrixBall.java.not @ 8:5e3cbbf173aa tip

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