X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fgraphics%2FSurface.java;h=ced451a9c68a325ea7046ec9ac97d86386a1ba99;hp=e6c5c4e1d41a8993aa00e158136cf041c92e90ed;hb=76b21655a0710caf4f972c107a3ab991032d7e10;hpb=3c89bc8a0b5f3d13abe38b5deb0c5ad4deb98ea5 diff --git a/src/org/ibex/graphics/Surface.java b/src/org/ibex/graphics/Surface.java index e6c5c4e..ced451a 100644 --- a/src/org/ibex/graphics/Surface.java +++ b/src/org/ibex/graphics/Surface.java @@ -1,4 +1,7 @@ -// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the GNU General Public License version 2 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.graphics; import org.ibex.js.*; @@ -17,8 +20,8 @@ public abstract class Surface extends PixelBuffer implements Task { // Static Data //////////////////////////////////////////////////////////////////////////////// - private static Boolean T = Boolean.TRUE; - private static Boolean F = Boolean.FALSE; + private static final JS T = JS.T; + private static final JS F = JS.F; /** all instances of Surface which need to be refreshed by the Scheduler */ public static Vec allSurfaces = new Vec(); @@ -96,7 +99,7 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(new Task() { public void perform() throws JSExn { Platform.clipboardReadEnabled = true; try { - root.putAndTriggerTraps("_Press3", T); + root.putAndTriggerTraps(JS.S("_Press3"), T); } finally { Platform.clipboardReadEnabled = false; } @@ -130,6 +133,7 @@ public abstract class Surface extends PixelBuffer implements Task { } } + private final static JS MOVE = JS.S("_Move"); /** we enqueue ourselves in the Scheduler when we have a Move message to deal with */ private Task mover = new Task() { public void perform() { @@ -139,7 +143,7 @@ public abstract class Surface extends PixelBuffer implements Task { String oldcursor = cursor; cursor = "default"; // FIXME: Root (ONLY) gets motion events outside itself (if trapped) if (oldmousex != mousex || oldmousey != mousey) - root.putAndTriggerTrapsAndCatchExceptions("_Move", T); + root.putAndTriggerTrapsAndCatchExceptions(MOVE, T); if (!cursor.equals(oldcursor)) syncCursor(); } }; @@ -155,10 +159,10 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(mover); } - protected final void HScroll(int pixels) { new Message("_HScroll", new Integer(pixels), root); } - protected final void VScroll(int pixels) { new Message("_VScroll", new Integer(pixels), root); } - protected final void HScroll(float lines) { new Message("_HScroll", new Float(lines), root); } - protected final void VScroll(float lines) { new Message("_VScroll", new Float(lines), root); } + protected final void HScroll(int pixels) { new Message("_HScroll", JS.N(pixels), root); } + protected final void VScroll(int pixels) { new Message("_VScroll", JS.N(pixels), root); } + protected final void HScroll(float lines) { new Message("_HScroll", JS.N(lines), root); } + protected final void VScroll(float lines) { new Message("_VScroll", JS.N(lines), root); } /** subclasses should invoke this method when the user resizes the window */ protected final void SizeChange(final int width, final int height) { @@ -175,14 +179,14 @@ public abstract class Surface extends PixelBuffer implements Task { Scheduler.add(new Task() { public void perform() throws JSExn { root.x = x; root.y = y; - root.putAndTriggerTrapsAndCatchExceptions("PosChange", T); + root.putAndTriggerTrapsAndCatchExceptions(JS.S("PosChange"), T); }}); } private final String[] doubleClick = new String[] { null, "_DoubleClick1", "_DoubleClick2", "_DoubleClick3" }; protected final void DoubleClick(int button) { new Message(doubleClick[button], T, root); } - protected final void KeyPressed(String key) { new Message("_KeyPressed", key, root); } - protected final void KeyReleased(String key) { new Message("_KeyReleased", key, root); } + protected final void KeyPressed(String key) { new Message("_KeyPressed", JS.S(key), root); } + protected final void KeyReleased(String key) { new Message("_KeyReleased", JS.S(key), root); } protected final void Close() { new Message("Close", T, root); } protected final void Minimized(boolean b) { minimized = b; new Message("Minimized", b ? T : F, root); } protected final void Maximized(boolean b) { maximized = b; new Message("Maximized", b ? T : F, root); } @@ -225,8 +229,19 @@ public abstract class Surface extends PixelBuffer implements Task { public Surface(Box root) { this.root = root; - root.setWidth(root.minwidth, Math.min(Platform.getScreenWidth(), root.maxwidth)); - root.setHeight(root.minheight, Math.min(Platform.getScreenHeight(), root.maxheight)); + // FIXME: document this in the reference + if (!root.test(root.HSHRINK) && root.maxwidth == Integer.MAX_VALUE) + root.maxwidth = Platform.getScreenWidth() / 2; + if (!root.test(root.VSHRINK) && root.maxheight == Integer.MAX_VALUE) + root.maxheight = Platform.getScreenHeight() / 2; + root.setWidth(root.minwidth, + root.test(root.HSHRINK) + ? Math.max(root.minwidth, root.contentwidth) + : Math.min(Platform.getScreenWidth(), root.maxwidth)); + root.setHeight(root.minheight, + root.test(root.VSHRINK) + ? Math.max(root.minheight, root.contentheight) + : Math.min(Platform.getScreenHeight(), root.maxheight)); Surface old = fromBox(root); if (old != null) old.dispose(false); else root.removeSelf(); @@ -247,13 +262,15 @@ public abstract class Surface extends PixelBuffer implements Task { root.setHeight(root.minheight, pendingHeight); syncRootBoxToSurface = false; } - if (root.maxwidth != root.width || root.maxheight != root.height) { + int rootwidth = root.test(root.HSHRINK) ? root.contentwidth : root.maxwidth; + int rootheight = root.test(root.VSHRINK) ? root.contentheight : root.maxheight; + if (rootwidth != root.width || rootheight != root.height) { // dirty the place where the scar used to be and where it is now dirty(0, root.height - scarImage.height, scarImage.width, scarImage.height); - dirty(0, root.maxheight - scarImage.height, scarImage.width, scarImage.height); + dirty(0, rootheight - scarImage.height, scarImage.width, scarImage.height); } root.reflow(); - setSize(root.width, root.height); + setSize(rootwidth, rootheight); /*String oldcursor = cursor; cursor = "default"; root.putAndTriggerTrapsAndCatchExceptions("_Move", JS.T); @@ -291,42 +308,42 @@ public abstract class Surface extends PixelBuffer implements Task { public class Message implements Task { private Box boxContainingMouse; - private Object value; + private JS value; public String name; - Message(String name, Object value, Box boxContainingMouse) { + Message(String name, JS value, Box boxContainingMouse) { this.boxContainingMouse = boxContainingMouse; this.name = name; this.value = value; Scheduler.add(this); } - public void perform() { + public void perform() throws JSExn { if (name.equals("_KeyPressed")) { - String value = (String)this.value; + String value = JS.toString(this.value); if (value.toLowerCase().endsWith("shift")) shift = true; else if (shift) value = value.toUpperCase(); if (value.toLowerCase().equals("alt")) alt = true; else if (alt) value = "A-" + value; if (value.toLowerCase().endsWith("control")) control = true; else if (control) value = "C-" + value; if (value.equals("C-v") || value.equals("A-v")) Platform.clipboardReadEnabled = true; - this.value = value; + this.value = JS.S(value); } else if (name.equals("_KeyReleased")) { - String value = (String)this.value; + String value = JS.toString(this.value); if (value.toLowerCase().equals("alt")) alt = false; else if (value.toLowerCase().equals("control")) control = false; else if (value.toLowerCase().equals("shift")) shift = false; - this.value = value; + this.value = JS.S(value); } else if (name.equals("_HScroll") || name.equals("_VScroll")) { // FIXME: technically points != pixels - if (value instanceof Integer) - value = new Float(((Integer)value).intValue() * root.fontSize()); + if (JS.isInt(value)) + value = JS.N(JS.toInt(value) * root.fontSize()); } try { - boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(name, value); + boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(JS.S(name), value); } finally { Platform.clipboardReadEnabled = false; } } - public String toString() { return "Message [name=" + name + ", value=" + value + "]"; } + public String toString() { return "Message [name=" + name + ", value=" + JS.debugToString(value) + "]"; } }