home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.image.ImageObserver;
-
- class drawbutt extends Canvas implements ImageObserver {
- MediaTracker tracker = new MediaTracker(this);
- Image[] art = new Image[9];
- Image defaultImage;
- Image offImage;
- Graphics offGraphics;
- Image newImage;
- Graphics newGraphics;
- static Color bgcolor;
- boolean enter = false;
- boolean ready = false;
- boolean paintReady = true;
- boolean firstTime = true;
- private boolean done = false;
- private boolean buttonUp = true;
- int tracked;
- // $FF: renamed from: dw int
- int field_0;
- // $FF: renamed from: dh int
- int field_1;
- int x_coord = 30;
- int y_coord = 30;
- int imagePos = 4;
- int joyPos = 4;
-
- public drawbutt(Image var1, Image var2) {
- try {
- this.offImage = var1;
- this.offGraphics = this.offImage.getGraphics();
- this.newImage = var2;
- this.newGraphics = this.newImage.getGraphics();
- } catch (Exception var3) {
- this.offGraphics = null;
- this.newGraphics = null;
- System.out.println("GRaphics NULL");
- }
- }
-
- public void addDefaultImage(Image var1) {
- this.defaultImage = var1;
- this.tracker.addImage(this.defaultImage, 0);
- }
-
- public void addImage(Image var1) {
- this.art[this.tracked] = var1;
- this.tracker.addImage(this.art[this.tracked], 1);
- ++this.tracked;
- }
-
- public static void setBgcolor(Color var0) {
- bgcolor = var0;
- }
-
- private void divider() {
- this.field_0 = ((Component)this).size().width;
- this.field_1 = ((Component)this).size().height;
- }
-
- public void startTracker() {
- this.startDefTracker();
- this.startMainTracker();
- this.ready = true;
- }
-
- public void startDefTracker() {
- try {
- this.tracker.waitForID(0);
- } catch (InterruptedException var1) {
- System.out.println("Interrupted loading default joystick image");
- }
-
- this.tracker.checkID(0);
- this.done = true;
- this.ready = true;
- ((Component)this).repaint();
- }
-
- public void startMainTracker() {
- try {
- this.tracker.waitForID(1);
- } catch (InterruptedException var1) {
- System.out.println("Interrupted loading joystick images");
- }
-
- this.tracker.checkID(1);
- this.ready = true;
- ((Component)this).repaint();
- }
-
- private void sector(int var1, int var2) {
- if (var2 < this.field_0 * 2 / 5) {
- this.imagePos = var1;
- this.x_coord = 0;
- } else if (var2 < this.field_0 * 3 / 5) {
- this.imagePos = 1 + var1;
- this.x_coord = 30;
- } else {
- this.imagePos = 2 + var1;
- this.x_coord = 46;
- }
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (var3 < this.field_1 * 2 / 5) {
- this.sector(0, var2);
- this.y_coord = 0;
- } else if (var3 < this.field_1 * 3 / 5) {
- this.sector(3, var2);
- this.y_coord = 30;
- } else {
- this.sector(6, var2);
- this.y_coord = 46;
- }
-
- this.paintReady = true;
- this.buttonUp = false;
- ((egorctr)((Component)this).getParent()).egorDirection(this.imagePos);
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- this.buttonUp = true;
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseDrag(Event var1, int var2, int var3) {
- if (var3 < this.field_1 * 2 / 5) {
- this.sector(0, var2);
- this.y_coord = 0;
- } else if (var3 < this.field_1 * 3 / 5) {
- this.sector(3, var2);
- this.y_coord = 30;
- } else {
- this.sector(6, var2);
- this.y_coord = 46;
- }
-
- if (this.joyPos != this.imagePos) {
- this.paintReady = true;
- ((Component)this).repaint();
- this.joyPos = this.imagePos;
- }
-
- ((egorctr)((Component)this).getParent()).egorDirection(this.imagePos);
- return true;
- }
-
- public void defaultState(Graphics var1, int var2) {
- var1.setColor(bgcolor);
- var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- var1.drawImage(this.defaultImage, 0, 0, this);
- if (var2 < this.tracked) {
- var1.drawImage(this.art[var2], 30, 30, this);
- }
-
- }
-
- public void update(Graphics var1) {
- if (this.imagesLoaded()) {
- this.paint(var1);
- }
-
- }
-
- public void paint(Graphics var1) {
- if (this.ready) {
- if (this.firstTime) {
- if (this.done) {
- this.divider();
- var1.drawImage(this.defaultImage, 0, 0, this);
- this.offGraphics.setColor(Color.black);
- this.offGraphics.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- this.newGraphics.setColor(Color.black);
- this.newGraphics.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- this.defaultState(this.offGraphics, 4);
- this.defaultState(this.newGraphics, 100);
- this.firstTime = false;
- return;
- }
- } else {
- if (!this.buttonUp) {
- var1.drawImage(this.newImage, 0, 0, this);
- var1.drawImage(this.art[this.imagePos], this.x_coord, this.y_coord, this);
- return;
- }
-
- try {
- Thread.sleep(100L);
- } catch (InterruptedException var2) {
- }
-
- var1.drawImage(this.newImage, 0, 0, this);
- var1.drawImage(this.offImage, 0, 0, this);
- System.out.println("joystick back to center");
- }
- }
-
- }
-
- private boolean imagesLoaded() {
- if (this.done) {
- return this.done;
- } else if (this.tracker.isErrorAny()) {
- System.out.println("Tracker Error - drawbutt");
- return false;
- } else {
- this.done = this.tracker.checkID(0);
- if (this.done) {
- this.divider();
- }
-
- return this.done;
- }
- }
- }
-