home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Hotdog / files / snagpack.exe / DRAWBUTT.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1996-09-09  |  4.5 KB  |  227 lines

  1. import java.awt.Canvas;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.awt.MediaTracker;
  8. import java.awt.image.ImageObserver;
  9.  
  10. class drawbutt extends Canvas implements ImageObserver {
  11.    MediaTracker tracker = new MediaTracker(this);
  12.    Image[] art = new Image[9];
  13.    Image defaultImage;
  14.    Image offImage;
  15.    Graphics offGraphics;
  16.    Image newImage;
  17.    Graphics newGraphics;
  18.    static Color bgcolor;
  19.    boolean enter = false;
  20.    boolean ready = false;
  21.    boolean paintReady = true;
  22.    boolean firstTime = true;
  23.    private boolean done = false;
  24.    private boolean buttonUp = true;
  25.    int tracked;
  26.    // $FF: renamed from: dw int
  27.    int field_0;
  28.    // $FF: renamed from: dh int
  29.    int field_1;
  30.    int x_coord = 30;
  31.    int y_coord = 30;
  32.    int imagePos = 4;
  33.    int joyPos = 4;
  34.  
  35.    public drawbutt(Image var1, Image var2) {
  36.       try {
  37.          this.offImage = var1;
  38.          this.offGraphics = this.offImage.getGraphics();
  39.          this.newImage = var2;
  40.          this.newGraphics = this.newImage.getGraphics();
  41.       } catch (Exception var3) {
  42.          this.offGraphics = null;
  43.          this.newGraphics = null;
  44.          System.out.println("GRaphics NULL");
  45.       }
  46.    }
  47.  
  48.    public void addDefaultImage(Image var1) {
  49.       this.defaultImage = var1;
  50.       this.tracker.addImage(this.defaultImage, 0);
  51.    }
  52.  
  53.    public void addImage(Image var1) {
  54.       this.art[this.tracked] = var1;
  55.       this.tracker.addImage(this.art[this.tracked], 1);
  56.       ++this.tracked;
  57.    }
  58.  
  59.    public static void setBgcolor(Color var0) {
  60.       bgcolor = var0;
  61.    }
  62.  
  63.    private void divider() {
  64.       this.field_0 = ((Component)this).size().width;
  65.       this.field_1 = ((Component)this).size().height;
  66.    }
  67.  
  68.    public void startTracker() {
  69.       this.startDefTracker();
  70.       this.startMainTracker();
  71.       this.ready = true;
  72.    }
  73.  
  74.    public void startDefTracker() {
  75.       try {
  76.          this.tracker.waitForID(0);
  77.       } catch (InterruptedException var1) {
  78.          System.out.println("Interrupted loading default joystick image");
  79.       }
  80.  
  81.       this.tracker.checkID(0);
  82.       this.done = true;
  83.       this.ready = true;
  84.       ((Component)this).repaint();
  85.    }
  86.  
  87.    public void startMainTracker() {
  88.       try {
  89.          this.tracker.waitForID(1);
  90.       } catch (InterruptedException var1) {
  91.          System.out.println("Interrupted loading joystick images");
  92.       }
  93.  
  94.       this.tracker.checkID(1);
  95.       this.ready = true;
  96.       ((Component)this).repaint();
  97.    }
  98.  
  99.    private void sector(int var1, int var2) {
  100.       if (var2 < this.field_0 * 2 / 5) {
  101.          this.imagePos = var1;
  102.          this.x_coord = 0;
  103.       } else if (var2 < this.field_0 * 3 / 5) {
  104.          this.imagePos = 1 + var1;
  105.          this.x_coord = 30;
  106.       } else {
  107.          this.imagePos = 2 + var1;
  108.          this.x_coord = 46;
  109.       }
  110.    }
  111.  
  112.    public boolean mouseDown(Event var1, int var2, int var3) {
  113.       if (var3 < this.field_1 * 2 / 5) {
  114.          this.sector(0, var2);
  115.          this.y_coord = 0;
  116.       } else if (var3 < this.field_1 * 3 / 5) {
  117.          this.sector(3, var2);
  118.          this.y_coord = 30;
  119.       } else {
  120.          this.sector(6, var2);
  121.          this.y_coord = 46;
  122.       }
  123.  
  124.       this.paintReady = true;
  125.       this.buttonUp = false;
  126.       ((egorctr)((Component)this).getParent()).egorDirection(this.imagePos);
  127.       ((Component)this).repaint();
  128.       return true;
  129.    }
  130.  
  131.    public boolean mouseUp(Event var1, int var2, int var3) {
  132.       this.buttonUp = true;
  133.       ((Component)this).repaint();
  134.       return true;
  135.    }
  136.  
  137.    public boolean mouseDrag(Event var1, int var2, int var3) {
  138.       if (var3 < this.field_1 * 2 / 5) {
  139.          this.sector(0, var2);
  140.          this.y_coord = 0;
  141.       } else if (var3 < this.field_1 * 3 / 5) {
  142.          this.sector(3, var2);
  143.          this.y_coord = 30;
  144.       } else {
  145.          this.sector(6, var2);
  146.          this.y_coord = 46;
  147.       }
  148.  
  149.       if (this.joyPos != this.imagePos) {
  150.          this.paintReady = true;
  151.          ((Component)this).repaint();
  152.          this.joyPos = this.imagePos;
  153.       }
  154.  
  155.       ((egorctr)((Component)this).getParent()).egorDirection(this.imagePos);
  156.       return true;
  157.    }
  158.  
  159.    public void defaultState(Graphics var1, int var2) {
  160.       var1.setColor(bgcolor);
  161.       var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  162.       var1.drawImage(this.defaultImage, 0, 0, this);
  163.       if (var2 < this.tracked) {
  164.          var1.drawImage(this.art[var2], 30, 30, this);
  165.       }
  166.  
  167.    }
  168.  
  169.    public void update(Graphics var1) {
  170.       if (this.imagesLoaded()) {
  171.          this.paint(var1);
  172.       }
  173.  
  174.    }
  175.  
  176.    public void paint(Graphics var1) {
  177.       if (this.ready) {
  178.          if (this.firstTime) {
  179.             if (this.done) {
  180.                this.divider();
  181.                var1.drawImage(this.defaultImage, 0, 0, this);
  182.                this.offGraphics.setColor(Color.black);
  183.                this.offGraphics.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  184.                this.newGraphics.setColor(Color.black);
  185.                this.newGraphics.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  186.                this.defaultState(this.offGraphics, 4);
  187.                this.defaultState(this.newGraphics, 100);
  188.                this.firstTime = false;
  189.                return;
  190.             }
  191.          } else {
  192.             if (!this.buttonUp) {
  193.                var1.drawImage(this.newImage, 0, 0, this);
  194.                var1.drawImage(this.art[this.imagePos], this.x_coord, this.y_coord, this);
  195.                return;
  196.             }
  197.  
  198.             try {
  199.                Thread.sleep(100L);
  200.             } catch (InterruptedException var2) {
  201.             }
  202.  
  203.             var1.drawImage(this.newImage, 0, 0, this);
  204.             var1.drawImage(this.offImage, 0, 0, this);
  205.             System.out.println("joystick back to center");
  206.          }
  207.       }
  208.  
  209.    }
  210.  
  211.    private boolean imagesLoaded() {
  212.       if (this.done) {
  213.          return this.done;
  214.       } else if (this.tracker.isErrorAny()) {
  215.          System.out.println("Tracker Error - drawbutt");
  216.          return false;
  217.       } else {
  218.          this.done = this.tracker.checkID(0);
  219.          if (this.done) {
  220.             this.divider();
  221.          }
  222.  
  223.          return this.done;
  224.       }
  225.    }
  226. }
  227.