diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/RenderCanvas.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/RenderCanvas.java')
| -rw-r--r-- | NET/worlds/console/RenderCanvas.java | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/NET/worlds/console/RenderCanvas.java b/NET/worlds/console/RenderCanvas.java new file mode 100644 index 0000000..619accd --- /dev/null +++ b/NET/worlds/console/RenderCanvas.java @@ -0,0 +1,233 @@ +package NET.worlds.console; + +import NET.worlds.scape.Camera; +import NET.worlds.scape.EventQueue; +import NET.worlds.scape.FrameEvent; +import NET.worlds.scape.LibraryDropTarget; +import NET.worlds.scape.Pilot; +import NET.worlds.scape.ToolTipManager; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.IllegalComponentStateException; +import java.awt.Point; +import java.util.Enumeration; +import java.util.Vector; + +public class RenderCanvas extends Canvas implements FramePart, LibraryDropTarget { + private static final long serialVersionUID = -811200590685352009L; + DefaultConsole universeConsole; + private Window w; + private Dimension dim; + private Camera camera; + private int xRenderExtent; + private int yRenderExtent; + private boolean fullScreenOverlay = false; + private boolean mayNeedToResize; + private Vector<RenderCanvasOverlay> overlays; + + public RenderCanvas(Dimension d) { + this(null, d); + } + + public RenderCanvas(DefaultConsole dc, Dimension d) { + this.universeConsole = dc; + this.dim = d; + this.overlays = new Vector<RenderCanvasOverlay>(); + } + + public void drive() { + if (this.w != null && Pilot.getActiveRoom() != null) { + this.w.setDeltaMode(true); + } + } + + public boolean getDeltaMode() { + return this.w == null ? false : this.w.getDeltaMode(); + } + + @Override + public void activate(Console c, Container f, Console prev) { + } + + @Override + public void deactivate() { + } + + public void setCamera(Camera cam) { + this.camera = cam; + if (cam != null) { + cam.setCanvas(this); + } + } + + public Camera getCamera() { + return this.camera; + } + + public Window getWindow() { + return this.w; + } + + @Override + public void update(Graphics g) { + } + + @Override + public void paint(Graphics g) { + } + + @Override + public void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + this.mayNeedToResize = true; + } + + @Override + public Dimension minimumSize() { + return this.dim; + } + + @Override + public Dimension preferredSize() { + return this.dim; + } + + public void addOverlay(RenderCanvasOverlay overlay) { + assert this.overlays != null; + + this.overlays.addElement(overlay); + this.mayNeedToResize = true; + } + + public void removeOverlay(RenderCanvasOverlay overlay) { + assert this.overlays != null; + + this.overlays.removeElement(overlay); + this.mayNeedToResize = true; + } + + private void computeOverlayDimensions() { + int minYPer = 100; + int minXPer = 100; + this.fullScreenOverlay = false; + Dimension size = this.getSize(); + if (this.overlays != null) { + Enumeration<RenderCanvasOverlay> e = this.overlays.elements(); + + while (e.hasMoreElements()) { + RenderCanvasOverlay o = e.nextElement(); + o.canvasResized(size.width, size.height); + if (o.isFullscreen()) { + this.fullScreenOverlay = true; + minYPer = 0; + minXPer = 0; + } + + int ox = 100 - o.getXPercent(); + int oy = 100 - o.getYPercent(); + if (ox < minXPer) { + minXPer = ox; + } + + if (oy < minYPer) { + minYPer = oy; + } + } + } + + if (minXPer == 0 && minYPer == 0) { + this.xRenderExtent = this.yRenderExtent = 0; + } else if (minXPer == 0) { + this.xRenderExtent = size.width; + this.yRenderExtent = (int)((double)size.height * minYPer * 0.01); + } else if (minYPer == 0) { + this.xRenderExtent = (int)((double)size.width * minXPer * 0.01); + this.yRenderExtent = size.height; + } else { + this.xRenderExtent = size.width; + this.yRenderExtent = size.height; + } + } + + @Override + public boolean handle(FrameEvent f) { + if (this.camera == null) { + return true; + } else if (!this.checkForWindow(true)) { + return true; + } else { + EventQueue.pollForEvents(this.camera); + if (this.w == null) { + return true; + } else { + if (this.mayNeedToResize) { + this.computeOverlayDimensions(); + this.w.maybeResize(this.xRenderExtent, this.yRenderExtent); + if (Window.usingMicrosoftVMHacks()) { + Point pt = this.getLocationOnScreen(); + Dimension dim = this.getSize(); + this.w.reShape(pt.x, pt.y, dim.width, dim.height); + } + + this.mayNeedToResize = false; + } + + if (this.camera != null) { + this.doRender(); + } + + return true; + } + } + } + + public boolean checkForWindow(boolean interceptEvents) { + if (this.w == null) { + String title = Console.getFrame().getTitle(); + if (title == null) { + return false; + } + + try { + this.w = new Window(title, this.getLocationOnScreen(), this.getSize(), this.camera, interceptEvents); + } catch (IllegalComponentStateException var4) { + return false; + } catch (WindowNotFoundException var5) { + return false; + } + + this.mayNeedToResize = false; + } + + return true; + } + + private synchronized void doRender() { + if (this.universeConsole != null && this.universeConsole.isUniverseMode()) { + ToolTipManager.toolTipManager().killToolTip(); + if (this.w != null) { + this.w.hideNativeWindow(); + } + } else { + ToolTipManager.toolTipManager().heartbeat(); + this.w.showNativeWindow(); + if (this.fullScreenOverlay) { + ToolTipManager.toolTipManager().killToolTip(); + } else { + this.camera.renderToCanvas(); + } + } + } + + @Override + public void removeNotify() { + if (this.w != null) { + this.w.dispose(); + this.w = null; + } + + super.removeNotify(); + } +} |