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/ScapePicPanel.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/ScapePicPanel.java')
| -rw-r--r-- | NET/worlds/console/ScapePicPanel.java | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/NET/worlds/console/ScapePicPanel.java b/NET/worlds/console/ScapePicPanel.java new file mode 100644 index 0000000..29f5f75 --- /dev/null +++ b/NET/worlds/console/ScapePicPanel.java @@ -0,0 +1,150 @@ +package NET.worlds.console; + +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Panel; +import java.awt.Point; + +public class ScapePicPanel extends Panel { + private static final long serialVersionUID = -1019314311757410999L; + private static final int QUARTERED = 0; + private static final int UPPERLEFT = 1; + private ScapePicImage image = null; + private int hWnd; + private int drawMode = 0; + + public ScapePicPanel() { + this(null); + } + + public ScapePicPanel(ScapePicImage image) { + this.setImage(image); + } + + public void setImage(ScapePicImage image) { + this.image = image; + } + + @Override + public void paint(Graphics g) { + this.drawBackground(); + super.paint(g); + } + + @Override + public void update(Graphics g) { + this.paint(g); + } + + public void setQuartered() { + this.drawMode = 0; + } + + public void setUpperLeft() { + this.drawMode = 1; + } + + private void drawBackground() { + assert this.drawMode == 1 || this.drawMode == 0; + + if (this.image != null) { + Dimension size = this.getSize(); + + assert size != null; + + assert size.height >= 0 && size.width >= 0; + + if (this.drawMode == 1) { + for (int j = 0; j < size.height; j += this.image.getHeight()) { + for (int i = 0; i < size.width; i += this.image.getWidth()) { + this.drawScapePicImage(this.image, i, j, 0, 0, this.image.getWidth(), this.image.getHeight()); + } + } + } + + if (this.drawMode == 0) { + int cx = size.width / 2; + int cy = size.height / 2; + + for (int j = 0; j < cy; j += this.image.getHeight()) { + for (int i = 0; i < cx; i += this.image.getWidth()) { + int endX = Math.min(cx - i, this.image.getWidth()); + int endY = Math.min(cy - j, this.image.getHeight()); + this.drawScapePicImage(this.image, i, j, 0, 0, endX, endY); + } + } + + for (int j = 0; j < cy; j += this.image.getHeight()) { + for (int i = size.width; i > cx; i -= this.image.getWidth()) { + int startX = Math.max(i - this.image.getWidth(), cx); + int imageStartX = this.image.getWidth() - (i - startX); + int endY = Math.min(cy - j, this.image.getHeight()); + this.drawScapePicImage(this.image, startX, j, imageStartX, 0, i - startX, endY); + } + } + + for (int j = size.height; j > cy; j -= this.image.getHeight()) { + for (int i = 0; i < cx; i += this.image.getWidth()) { + int endX = Math.min(cx - i, this.image.getWidth()); + int startY = Math.max(j - this.image.getHeight(), cy); + int imageStartY = this.image.getHeight() - (j - startY); + this.drawScapePicImage(this.image, i, startY, 0, imageStartY, endX, j - startY); + } + } + + for (int j = size.height; j > cy; j -= this.image.getHeight()) { + for (int i = size.width; i > cx; i -= this.image.getWidth()) { + int startX = Math.max(i - this.image.getWidth(), cx); + int imageStartX = this.image.getWidth() - (i - startX); + int startY = Math.max(j - this.image.getHeight(), cy); + int imageStartY = this.image.getHeight() - (j - startY); + this.drawScapePicImage(this.image, startX, startY, imageStartX, imageStartY, i - startX, j - startY); + } + } + } + } + } + + public void drawScapePicImage(ScapePicImage image, int xDst, int yDst, int xSrc, int ySrc, int width, int height) { + if (this.hWnd == 0) { + Point loc = this.locationInWindow(); + Dimension size = this.getSize(); + String title = this.getFrameTitle(); + + assert title != null; + + int hWndParent = Window.findWindow(title); + + assert hWndParent != 0; + + this.hWnd = Window.findChildWindow(hWndParent, loc.x, loc.y, size.width, size.height); + + assert this.hWnd != 0; + } + + ScapePicCanvas.bitBlt(this.hWnd, image.getDIB(), xDst, yDst, xSrc, ySrc, width, height); + } + + private String getFrameTitle() { + for (Container c = this.getParent(); c != null; c = c.getParent()) { + if (c instanceof Frame) { + return ((Frame)c).getTitle(); + } + } + + return null; + } + + private Point locationInWindow() { + Point offset = this.location(); + + for (Container c = this.getParent(); c != null; c = c.getParent()) { + Point move = c.location(); + offset.translate(move.x, move.y); + } + + return offset; + } +} |