Skip to content

Commit

Permalink
#154 TextFieldのhit testの処理を実装(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Nov 20, 2024
1 parent 30684c8 commit 79281fe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { $setEvent } from "@next2d/events";
import { execute as playerHitTestUseCase } from "../../Player/usecase/PlayerHitTestUseCase";
import { execute as playerSetCurrentMousePoint } from "../../Player/service/PlayerSetCurrentMousePointService";
import { execute as playerPointerMoveEventService } from "../../Player/service/PlayerPointerMoveEventService";
import { $hitObject } from "../../CoreUtil";

/**
* @description プレイヤーのポインタームーブイベントを処理します。
Expand All @@ -25,6 +26,11 @@ export const execute = (event: PointerEvent): void =>
// start position
playerHitTestUseCase(event, element);

// ヒットしたオブジェクトがある場合
if ($hitObject.hit !== null) {
event.preventDefault();
}

// fixed logic
// ポインタームーブイベントを発火
playerPointerMoveEventService(event.pageX, event.pageY);
Expand Down
25 changes: 15 additions & 10 deletions packages/core/src/Player/service/PlayerPointerMoveEventService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DisplayObject } from "@next2d/display";
import type { TextField } from "@next2d/text";
import { $getSelectedTextField } from "@next2d/text";
import { PointerEvent } from "@next2d/events";
import { $player } from "../../Player";
import {
Expand All @@ -20,22 +20,27 @@ export const execute = <D extends DisplayObject> (
page_x: number = 0,

Check warning on line 20 in packages/core/src/Player/service/PlayerPointerMoveEventService.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

'page_x' is assigned a value but never used. Allowed unused args must match /^_/u

Check warning on line 20 in packages/core/src/Player/service/PlayerPointerMoveEventService.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

'page_x' is assigned a value but never used. Allowed unused args must match /^_/u
page_y: number = 0

Check warning on line 21 in packages/core/src/Player/service/PlayerPointerMoveEventService.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

'page_y' is assigned a value but never used. Allowed unused args must match /^_/u

Check warning on line 21 in packages/core/src/Player/service/PlayerPointerMoveEventService.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

'page_y' is assigned a value but never used. Allowed unused args must match /^_/u
): void => {

// text field
const selectedTextField = $getSelectedTextField();
if (selectedTextField && $player.mouseState === "down") {
selectedTextField.setFocusIndex(
$hitObject.x - $hitMatrix[4],
$hitObject.y - $hitMatrix[5],
true
);

return ;
}

const displayObject = $hitObject.hit as D;
if (displayObject) {
if (displayObject.isText && $player.mouseState === "down") {
(displayObject as unknown as TextField).setFocusIndex(
$hitObject.x - $hitMatrix[4],
$hitObject.y - $hitMatrix[5],
true
);
}

if (displayObject.willTrigger(PointerEvent.POINTER_MOVE)) {
displayObject.dispatchEvent(new PointerEvent(
PointerEvent.POINTER_MOVE
));
}
} else {
console.log(page_x, page_y);
// console.log(page_x, page_y);
}
};
9 changes: 3 additions & 6 deletions packages/core/src/Player/usecase/PlayerHitTestUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ export const execute = (event: PointerEvent, canvas: HTMLCanvasElement): void =>
// ヒット判定
$stage.$mouseHit($hitContext, $hitMatrix, $hitObject);

// ヒットしたオブジェクトがある場合
if ($hitObject.hit !== null) {
event.preventDefault();
}

// カーソルの表示を更新
if ($currentCursor !== $hitObject.pointer) {
if ($player.mouseState === "up"
&& $currentCursor !== $hitObject.pointer
) {
canvas.style.cursor = $currentCursor = $hitObject.pointer;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ export const execute = (
}
}

if (line > 0 && text_data.ascentTable[line] === 0) {
line++;
}
for (let idx = 0; idx < line; ++idx) {
y += text_data.heightTable[idx];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ export const execute = (
) {
const index = idx;
if (selected) {
if (text_field.selectIndex !== index
&& text_field.focusIndex === index
) {
if (text_field.selectIndex !== index) {
text_field.selectIndex = index;

if (text_field.focusIndex !== index) {
if (text_field.focusVisible) {
text_field.focusVisible = false;
textFieldBlinkingClearTimeoutService();
textFieldApplyChangesService(text_field);
}
textFieldApplyChangesService(text_field);
}
} else {
if (text_field.focusIndex !== index || text_field.selectIndex > -1) {
Expand Down Expand Up @@ -172,11 +170,12 @@ export const execute = (
if (text_field.selectIndex !== index) {
text_field.selectIndex = index;

if (text_field.focusIndex !== index) {
if (text_field.focusVisible) {
text_field.focusVisible = false;
textFieldBlinkingClearTimeoutService();
textFieldApplyChangesService(text_field);
}

textFieldApplyChangesService(text_field);
}
} else {
if (text_field.focusIndex !== index || text_field.selectIndex > -1) {
Expand Down Expand Up @@ -204,6 +203,23 @@ export const execute = (
} else {
textFieldApplyChangesService(text_field);
}
} else {
let height = 0;
for (let idx = 0; textData.heightTable.length > idx; ++idx) {
height += textData.heightTable[idx];
}

if (y > height || 2 > y) {
text_field.selectIndex = 2 > y
? 1
: textData.textTable.length;

if (text_field.focusVisible) {
text_field.focusVisible = false;
textFieldBlinkingClearTimeoutService();
}
textFieldApplyChangesService(text_field);
}
}
}
};

0 comments on commit 79281fe

Please sign in to comment.