Skip to content

Commit

Permalink
#154 hit testを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Nov 30, 2024
1 parent 12ed6b8 commit 16ed225
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 26 deletions.
38 changes: 24 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,45 @@
const { Sprite, Shape } = next2d.display;
const { TextField } = next2d.text;
const { PointerEvent } = next2d.events;
const { Rectangle } = next2d.geom;

const sprite = root.addChild(new Sprite());
sprite.buttonMode = true;
sprite.x = 50;
sprite.y = 50;
sprite.addEventListener(PointerEvent.POINTER_DOWN, () =>
sprite.addEventListener(PointerEvent.POINTER_DOWN, (event) =>
{
sprite.startDrag();
});
sprite.addEventListener(PointerEvent.POINTER_UP, () =>
sprite.addEventListener(PointerEvent.POINTER_UP, (event) =>
{
sprite.stopDrag();
});

const textFiled = root.addChild(new TextField());
textFiled.x = 250;
textFiled.y = 100;
textFiled.border = true;
textFiled.type = "input";
textFiled.multiline = true;
// textFiled.wordWrap = true;
textFiled.text = "Hello Next2D\nTest Mode On Test Mode On Test Mode On Test Mode On Test Mode On Test Mode On Test Mode On\nText Field\nText Field\n\n\n\nText Field\nTest Mode On Test Mode On Test Mode On Test Mode On Test Mode On";
// const textFiled = root.addChild(new TextField());
// textFiled.x = 250;
// textFiled.y = 100;
// textFiled.border = true;
// textFiled.type = "input";
// textFiled.multiline = true;
// // textFiled.wordWrap = true;
// textFiled.text = "Hello Next2D\nTest Mode On Test Mode On Test Mode On Test Mode On Test Mode On Test Mode On Test Mode On\nText Field\nText Field\n\n\n\nText Field\nTest Mode On Test Mode On Test Mode On Test Mode On Test Mode On";

const shape = sprite.addChild(new Shape());
shape
const maskShape = sprite.addChild(new Shape());
const viewShape = sprite.addChild(new Shape());
viewShape.x = 100;
viewShape.y = 100;
viewShape
.graphics
.beginFill("#0eff0e")
.drawRect(0, 0, 100, 100);

maskShape.x = 100;
maskShape.y = 100;
maskShape
.graphics
.beginFill("#000")
.drawCircle(50, 50, 50);

sprite.mask = maskShape;
});
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
$getArray,
$poolArray,
$getMap,
$poolMap
$poolMap,
$MATRIX_ARRAY_IDENTITY
} from "../../DisplayObjectUtil";

/**
Expand Down Expand Up @@ -166,21 +167,55 @@ export const execute = <P extends DisplayObjectContainer, D extends DisplayObjec
const maskInstance = instance.mask as D | null;
if (maskInstance) {

if (display_object_container === maskInstance.parent) {

if (!maskInstance._$hit(hit_context, tMatrix, hit_object, true)) {
continue;
}

} else {
let maskMatrix = $MATRIX_ARRAY_IDENTITY;
if (maskInstance.parent) {
const matrix = displayObjectConcatenatedMatrixUseCase(maskInstance.parent);
maskMatrix = matrix.rawData;
}

const matrix = displayObjectConcatenatedMatrixUseCase(maskInstance);
if (!maskInstance._$hit(hit_context, matrix.rawData, hit_object, true)) {
continue;
}
let hitTest = false;
switch (true) {

Check failure on line 178 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

Trailing spaces not allowed

Check failure on line 178 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

Trailing spaces not allowed
case maskInstance.isContainerEnabled:
hitTest = execute(
maskInstance as unknown as DisplayObjectContainer,
hit_context, maskMatrix, hit_object, mouseChildren
);
break;

Check failure on line 185 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

Trailing spaces not allowed

Check failure on line 185 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

Trailing spaces not allowed
case maskInstance.isShape:
hitTest = shapeHitTestUseCase(
maskInstance as unknown as Shape,
hit_context, maskMatrix, hit_object
);
break;

Check failure on line 192 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

Trailing spaces not allowed

Check failure on line 192 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

Trailing spaces not allowed
case maskInstance.isText:
hitTest = textFieldHitTestUseCase(
maskInstance as unknown as TextField,
hit_context, maskMatrix, hit_object
);
break;

Check failure on line 199 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

Trailing spaces not allowed

Check failure on line 199 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

Trailing spaces not allowed
case maskInstance.isVideo:
hitTest = videoHitTestUseCase(
maskInstance as unknown as Video,
hit_context, maskMatrix, hit_object
);
break;

Check failure on line 206 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

Trailing spaces not allowed

Check failure on line 206 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

Trailing spaces not allowed
default:
break;

Check failure on line 209 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

Trailing spaces not allowed

Check failure on line 209 in packages/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerMouseHitUseCase.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

Trailing spaces not allowed
}

if (maskInstance.parent) {
Matrix.release(maskMatrix);
}

if (!hitTest) {
continue;
}
}

let hitTest = false;
Expand Down

0 comments on commit 16ed225

Please sign in to comment.