home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / PFRONT98 / DATA.Z / fphoverx.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-26  |  2.0 KB  |  98 lines

  1. import java.awt.Color;
  2. import java.awt.image.RGBImageFilter;
  3.  
  4. class fphoverx extends RGBImageFilter {
  5.    private int m_w;
  6.    private int m_h;
  7.    private int m_xc;
  8.    private int m_yc;
  9.    private int m_dmax;
  10.    private int m_r;
  11.    private int m_g;
  12.    private int m_b;
  13.    private int m_effect;
  14.    private int m_bevelSize;
  15.  
  16.    public fphoverx(int w, int h, Color color, int effect) {
  17.       super.canFilterIndexColorModel = false;
  18.       this.m_w = w;
  19.       this.m_h = h;
  20.       this.m_xc = w / 2;
  21.       this.m_yc = h / 2;
  22.       this.m_dmax = this.m_xc * this.m_xc + this.m_yc * this.m_yc;
  23.       this.m_r = color.getRed();
  24.       this.m_g = color.getGreen();
  25.       this.m_b = color.getBlue();
  26.       this.m_effect = effect;
  27.       this.m_bevelSize = w < h ? w / 12 : h / 12;
  28.       if (this.m_bevelSize < 2) {
  29.          this.m_bevelSize = 2;
  30.       }
  31.  
  32.    }
  33.  
  34.    public int filterRGB(int x, int y, int rgb) {
  35.       int d = (x - this.m_xc) * (x - this.m_xc) + (y - this.m_yc) * (y - this.m_yc);
  36.       int r = (rgb & 16711680) >> 16;
  37.       int g = (rgb & '\uff00') >> 8;
  38.       int b = rgb & 255;
  39.       switch (this.m_effect) {
  40.          case 0:
  41.             r = this.m_r;
  42.             g = this.m_g;
  43.             b = this.m_b;
  44.             break;
  45.          case 1:
  46.             r = r + this.m_r >> 1;
  47.             g = g + this.m_g >> 1;
  48.             b = b + this.m_b >> 1;
  49.             break;
  50.          case 2:
  51.             r = this.m_r + (r - this.m_r) * d / this.m_dmax;
  52.             g = this.m_g + (g - this.m_g) * d / this.m_dmax;
  53.             b = this.m_b + (b - this.m_b) * d / this.m_dmax;
  54.             break;
  55.          case 3:
  56.             r += (this.m_r - r) * d / this.m_dmax;
  57.             g += (this.m_g - g) * d / this.m_dmax;
  58.             b += (this.m_b - b) * d / this.m_dmax;
  59.             break;
  60.          case 4:
  61.             r = r + 255 - (255 - r) * d / this.m_dmax >> 1;
  62.             g = g + 255 - (255 - g) * d / this.m_dmax >> 1;
  63.             b = b + 255 - (255 - b) * d / this.m_dmax >> 1;
  64.             break;
  65.          case 5:
  66.          case 6:
  67.             if (x < this.m_bevelSize || this.m_w - 1 - x < this.m_bevelSize || y < this.m_bevelSize || this.m_h - 1 - y < this.m_bevelSize) {
  68.                Color color = new Color(r, g, b);
  69.                boolean topLeft = false;
  70.                if (x < this.m_bevelSize && x + y <= this.m_h) {
  71.                   topLeft = true;
  72.                } else if (y < this.m_bevelSize && x + y <= this.m_w) {
  73.                   topLeft = true;
  74.                }
  75.  
  76.                if ((!topLeft || this.m_effect != 5) && (topLeft || this.m_effect != 6)) {
  77.                   color = color.darker();
  78.                } else {
  79.                   color = color.brighter();
  80.                }
  81.  
  82.                r = color.getRed();
  83.                g = color.getGreen();
  84.                b = color.getBlue();
  85.             }
  86.             break;
  87.          case 7:
  88.             if (r == 0 && g == 0 && b == 0) {
  89.                r = this.m_r;
  90.                g = this.m_g;
  91.                b = this.m_b;
  92.             }
  93.       }
  94.  
  95.       return rgb & -16777216 | r << 16 | g << 8 | b;
  96.    }
  97. }
  98.