Skip to content

Commit

Permalink
Use cursor offsets as hotspots
Browse files Browse the repository at this point in the history
Co-authored-by: Maximilian Stiede <[email protected]>
  • Loading branch information
fniephaus and Maximilian Stiede committed May 11, 2020
1 parent 26853d0 commit 6847f02
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public boolean isVisible() {
}

@Override
public void setCursor(final int[] cursorWords, final int[] mask, final int width, final int height, final int depth) {
public void setCursor(final int[] cursorWords, final int[] mask, final int width, final int height, final int depth, final int offsetX, final int offsetY) {
if (window.isNull()) {
return;
}
Expand All @@ -195,7 +195,7 @@ public void setCursor(final int[] cursorWords, final int[] mask, final int width
final byte[] maskBytes = cursorWordsToBytes(nCursorBytes, mask);
try (PinnedObject pinnedCursorBytes = PinnedObject.create(cursorBytes)) {
try (PinnedObject pinnedMaskBytes = PinnedObject.create(maskBytes)) {
cursor = SDL.createCursor(pinnedCursorBytes.addressOfArrayElement(0), pinnedMaskBytes.addressOfArrayElement(0), 16, 16, 0, 0);
cursor = SDL.createCursor(pinnedCursorBytes.addressOfArrayElement(0), pinnedMaskBytes.addressOfArrayElement(0), 16, 16, offsetX, offsetY);
}
}
if (!sdlError(cursor.isNonNull())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public boolean isVisible() {

@Override
@TruffleBoundary
public void setCursor(final int[] cursorWords, final int[] mask, final int width, final int height, final int depth) {
public void setCursor(final int[] cursorWords, final int[] mask, final int width, final int height, final int depth, final int offsetX, final int offsetY) {
final Dimension bestCursorSize = TOOLKIT.getBestCursorSize(width, height);
final Cursor cursor;
if (bestCursorSize.width == 0 || bestCursorSize.height == 0) {
Expand Down Expand Up @@ -300,7 +300,7 @@ public void setCursor(final int[] cursorWords, final int[] mask, final int width
}
}
}
cursor = TOOLKIT.createCustomCursor(bufferedImage, new Point(0, 0), "TruffleSqueak Cursor");
cursor = TOOLKIT.createCustomCursor(bufferedImage, new Point(offsetX, offsetY), "TruffleSqueak Cursor");
}
canvas.setCursor(cursor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface SqueakDisplayInterface {

boolean isVisible();

void setCursor(int[] cursorWords, int[] mask, int width, int height, int depth);
void setCursor(int[] cursorWords, int[] mask, int width, int height, int depth, int offsetX, int offsetY);

long[] getNextEvent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public int getFormHeight(final AbstractPointersObjectReadNode readNode) {
return (int) readNode.executeLong(this, FORM.HEIGHT);
}

public PointersObject getFormOffset(final AbstractPointersObjectReadNode readNode) {
return readNode.executePointers(this, FORM.OFFSET);
}

public int getFormWidth(final AbstractPointersObjectReadNode readNode) {
return (int) readNode.executeLong(this, FORM.WIDTH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import de.hpi.swa.trufflesqueak.model.WeakVariablePointersObject;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.CHARACTER_SCANNER;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.FORM;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.POINT;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.SPECIAL_OBJECT;
import de.hpi.swa.trufflesqueak.nodes.AbstractNode;
import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes.AbstractPointersObjectInstSizeNode;
Expand Down Expand Up @@ -192,13 +193,18 @@ protected static final ArrayObject doLoad(final Object receiver, final NativeObj
@GenerateNodeFactory
@SqueakPrimitive(indices = 101)
protected abstract static class PrimBeCursorNode extends AbstractPrimitiveNode implements BinaryPrimitive {
@Child private AbstractPointersObjectReadNode readNode = AbstractPointersObjectReadNode.create();
@Child private AbstractPointersObjectReadNode cursorReadNode = AbstractPointersObjectReadNode.create();
@Child private AbstractPointersObjectReadNode offsetReadNode = AbstractPointersObjectReadNode.create();

@Specialization
protected final PointersObject doCursor(final PointersObject receiver, @SuppressWarnings("unused") final NotProvided mask,
@CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
if (image.hasDisplay()) {
image.getDisplay().setCursor(receiver.getFormBits(readNode), null, receiver.getFormWidth(readNode), receiver.getFormHeight(readNode), receiver.getFormDepth(readNode));
final PointersObject offset = receiver.getFormOffset(cursorReadNode);
final int offsetX = Math.abs((int) offsetReadNode.executeLong(offset, POINT.X));
final int offsetY = Math.abs((int) offsetReadNode.executeLong(offset, POINT.Y));
image.getDisplay().setCursor(receiver.getFormBits(cursorReadNode), null, receiver.getFormWidth(cursorReadNode), receiver.getFormHeight(cursorReadNode),
receiver.getFormDepth(cursorReadNode), offsetX, offsetY);
}
return receiver;
}
Expand All @@ -208,13 +214,18 @@ protected final PointersObject doCursor(final PointersObject receiver, final Poi
@CachedContext(SqueakLanguage.class) final SqueakImageContext image,
@Cached("createBinaryProfile()") final ConditionProfile depthProfile) {
if (image.hasDisplay()) {
final int[] words = receiver.getFormBits(readNode);
final int depth = receiver.getFormDepth(readNode);
final int[] words = receiver.getFormBits(cursorReadNode);
final int depth = receiver.getFormDepth(cursorReadNode);
final int height = receiver.getFormHeight(cursorReadNode);
final int width = receiver.getFormWidth(cursorReadNode);
final PointersObject offset = receiver.getFormOffset(cursorReadNode);
final int offsetX = Math.abs((int) offsetReadNode.executeLong(offset, POINT.X));
final int offsetY = Math.abs((int) offsetReadNode.executeLong(offset, POINT.Y));
if (depthProfile.profile(depth == 1)) {
final int[] mask = readNode.executeNative(maskObject, FORM.BITS).getIntStorage();
image.getDisplay().setCursor(words, mask, receiver.getFormWidth(readNode), receiver.getFormHeight(readNode), 2);
final int[] mask = cursorReadNode.executeNative(maskObject, FORM.BITS).getIntStorage();
image.getDisplay().setCursor(words, mask, width, height, 2, offsetX, offsetY);
} else {
image.getDisplay().setCursor(words, null, receiver.getFormWidth(readNode), receiver.getFormHeight(readNode), depth);
image.getDisplay().setCursor(words, null, width, height, depth, offsetX, offsetY);
}
}
return receiver;
Expand Down

0 comments on commit 6847f02

Please sign in to comment.