summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WidgetButton.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/WidgetButton.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/WidgetButton.java')
-rw-r--r--NET/worlds/scape/WidgetButton.java125
1 files changed, 125 insertions, 0 deletions
diff --git a/NET/worlds/scape/WidgetButton.java b/NET/worlds/scape/WidgetButton.java
new file mode 100644
index 0000000..6d25390
--- /dev/null
+++ b/NET/worlds/scape/WidgetButton.java
@@ -0,0 +1,125 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.console.ImageCanvas;
+import java.awt.Canvas;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+
+abstract class WidgetButton extends Canvas {
+ private String name;
+ private Image image;
+ private Dimension dim;
+ private String prompt;
+ private ToolBar toolbar;
+ private boolean depressed;
+
+ WidgetButton(ToolBar toolbar, String name, String prompt) {
+ this.name = name;
+ this.toolbar = toolbar;
+ this.prompt = prompt;
+ }
+
+ public WObject getWObject() {
+ return this.toolbar.getCurrentWObject();
+ }
+
+ public String drag(boolean initialDrag, float deltax, float deltay) {
+ return null;
+ }
+
+ protected ToolBar getToolBar() {
+ return this.toolbar;
+ }
+
+ protected Point3Temp getWorldAxis(int ax, int ay, int az) {
+ Point3Temp p = new Point3(ax, ay, az).vectorTimes(Pilot.getActive());
+ float x = Math.abs(p.x);
+ float y = Math.abs(p.y);
+ float z = Math.abs(p.z);
+ if (x > y) {
+ if (x > z) {
+ return p.x > 0.0F ? Point3Temp.make(1.0F, 0.0F, 0.0F) : Point3Temp.make(-1.0F, 0.0F, 0.0F);
+ }
+ } else if (y > z) {
+ return p.y > 0.0F ? Point3Temp.make(0.0F, 1.0F, 0.0F) : Point3Temp.make(0.0F, -1.0F, 0.0F);
+ }
+
+ return p.z > 0.0F ? Point3Temp.make(0.0F, 0.0F, 1.0F) : Point3Temp.make(0.0F, 0.0F, -1.0F);
+ }
+
+ protected void applyWorldTransform(boolean initialDrag, Transform t) {
+ WObject wobj = this.getWObject();
+ if (initialDrag) {
+ Console.getFrame().getEditTile().addUndoable(new UndoablTransform(wobj));
+ }
+
+ Point3Temp pos = wobj.getPosition();
+ wobj.moveTo(0.0F, 0.0F, 0.0F).post(t).moveBy(pos);
+ wobj.markEdited();
+ }
+
+ public void draw(boolean depressed) {
+ this.depressed = depressed;
+ Graphics g = this.getGraphics();
+ this.drawOutline(g);
+ g.dispose();
+ }
+
+ public void perform() {
+ }
+
+ public boolean usesDrag() {
+ return true;
+ }
+
+ private void drawOutline(Graphics g) {
+ g.setColor(this.getBackground());
+ g.draw3DRect(0, 0, this.dim.width - 1, this.dim.height - 1, !this.depressed);
+ }
+
+ public boolean available() {
+ return this.getWObject() != null;
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+ if (this.available() && this.dim.width != 0) {
+ g.drawImage(this.image, 2, 2, this);
+ this.drawOutline(g);
+ }
+ }
+
+ private Dimension imageSize() {
+ if (this.image == null) {
+ this.image = ImageCanvas.getSystemImage(this.name, this);
+ if (this.image != null) {
+ int width = this.image.getWidth(this);
+ int height = this.image.getHeight(this);
+ if (width != -1 && height != -1) {
+ return this.dim = new Dimension(width + 4, height + 4);
+ }
+ }
+
+ this.dim = new Dimension(0, 0);
+ }
+
+ return this.dim;
+ }
+
+ @Override
+ public Dimension preferredSize() {
+ return this.imageSize();
+ }
+
+ @Override
+ public Dimension minimumSize() {
+ return this.imageSize();
+ }
+
+ public String getPrompt() {
+ return this.prompt;
+ }
+}