-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
233 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/display/src/DisplayObject/service/DisplayObjectDispatchRemovedEventService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { DisplayObject } from "../../DisplayObject"; | ||
import { Event } from "@next2d/events"; | ||
|
||
/** | ||
* @description DisplayObjectのREMOVEDイベントを実行 | ||
* Execute the REMOVED event of DisplayObject | ||
* | ||
* @param {DisplayObject} display_object | ||
* @return {void} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = <D extends DisplayObject>(display_object: D): void => | ||
{ | ||
if (!display_object.$added) { | ||
return ; | ||
} | ||
|
||
display_object.$added = false; | ||
if (display_object.willTrigger(Event.REMOVED)) { | ||
display_object.dispatchEvent(new Event(Event.REMOVED, true)); | ||
} | ||
}; |
26 changes: 26 additions & 0 deletions
26
...ages/display/src/DisplayObject/service/DisplayObjectDispatchRemovedToStageEventService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { DisplayObject } from "../../DisplayObject"; | ||
import { Event } from "@next2d/events"; | ||
import { $stageAssignedMap } from "../../DisplayObjectUtil"; | ||
|
||
/** | ||
* @description DisplayObjectのREMOVED_FROM_STAGEイベントを実行 | ||
* Execute the REMOVED_FROM_STAGE event of DisplayObject | ||
* | ||
* @param {DisplayObject} display_object | ||
* @return {void} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = <D extends DisplayObject>(display_object: D): void => | ||
{ | ||
if (!display_object.$addedToStage | ||
|| !$stageAssignedMap.has(display_object) | ||
) { | ||
return ; | ||
} | ||
|
||
display_object.$addedToStage = false; | ||
if (display_object.willTrigger(Event.REMOVED_FROM_STAGE)) { | ||
display_object.dispatchEvent(new Event(Event.REMOVED_FROM_STAGE)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...display/src/DisplayObjectContainer/service/DisplayObjectContainerRemovedToStageService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { DisplayObjectContainer } from "../../DisplayObjectContainer"; | ||
import { execute as displayObjectDispatchRemovedToStageEventService } from "../../DisplayObject/service/DisplayObjectDispatchRemovedToStageEventService"; | ||
|
||
/** | ||
* @description ステージに追加された DisplayObjectContainer の子要素のREMOVED_FROM_STAGEイベントを発行 | ||
* Issue REMOVED_FROM_STAGE events for child elements of DisplayObjectContainer added to the stage | ||
* | ||
* @param {DisplayObjectContainer} display_object_container | ||
* @return {void} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = <C extends DisplayObjectContainer>( | ||
display_object_container: C | ||
): void => { | ||
|
||
const children = display_object_container.children; | ||
for (let idx = 0; idx < children.length; ++idx) { | ||
|
||
const child = children[idx]; | ||
if (!child) { | ||
continue; | ||
} | ||
|
||
displayObjectDispatchRemovedToStageEventService(child); | ||
|
||
if (!child.isContainerEnabled) { | ||
continue; | ||
} | ||
|
||
execute(child as unknown as DisplayObjectContainer); | ||
} | ||
}; |
38 changes: 38 additions & 0 deletions
38
...y/src/DisplayObjectContainer/service/DisplayObjectContainerUnAssignStageAndRootService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { DisplayObjectContainer } from "../../DisplayObjectContainer"; | ||
import { | ||
$rootMap, | ||
$stageAssignedMap | ||
} from "../../DisplayObjectUtil"; | ||
|
||
/** | ||
* @description DisplayObjectContainer の子要素に設定した root と stage を解除 | ||
* Remove the root and stage set for the child elements of DisplayObjectContainer | ||
* | ||
* @param {DisplayObjectContainer} display_object_container | ||
* @return {void} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = <C extends DisplayObjectContainer>( | ||
display_object_container: C | ||
): void => { | ||
|
||
const children = display_object_container.children; | ||
for (let idx = 0; idx < children.length; ++idx) { | ||
|
||
const child = children[idx]; | ||
if (!child) { | ||
continue; | ||
} | ||
|
||
// set root and stage | ||
$rootMap.delete(child); | ||
$stageAssignedMap.delete(child); | ||
|
||
if (!child.isContainerEnabled) { | ||
continue; | ||
} | ||
|
||
execute(child as DisplayObjectContainer); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...es/display/src/DisplayObjectContainer/usecase/DisplayObjectContainerRemoveChildUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import type { DisplayObject } from "../../DisplayObject"; | ||
import type { DisplayObjectContainer } from "../../DisplayObjectContainer"; | ||
import { execute as displayObjectApplyChangesService } from "../../DisplayObject/service/DisplayObjectApplyChangesService"; | ||
import { execute as displayObjectContainerUnAssignStageAndRootService } from "../service/DisplayObjectContainerUnAssignStageAndRootService"; | ||
import { execute as displayObjectDispatchRemovedEventService } from "../../DisplayObject/service/DisplayObjectDispatchRemovedEventService"; | ||
import { execute as displayObjectDispatchRemovedToStageEventService } from "../../DisplayObject/service/DisplayObjectDispatchRemovedToStageEventService"; | ||
import { execute as displayObjectContainerRemovedToStageService } from "../service/DisplayObjectContainerRemovedToStageService"; | ||
import { | ||
$parentMap, | ||
$rootMap, | ||
$stageAssignedMap | ||
} from "../../DisplayObjectUtil"; | ||
|
||
/** | ||
* @description 指定の DisplayObject を DisplayObjectContainer から削除します。 | ||
* Deletes the specified DisplayObject from the DisplayObjectContainer. | ||
* | ||
* @param {DisplayObjectContainer} display_object_container | ||
* @param {DisplayObject} display_object | ||
* @return {DisplayObject} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = <P extends DisplayObjectContainer, D extends DisplayObject>( | ||
display_object_container: P, | ||
display_object: D | ||
): D => { | ||
|
||
const children = display_object_container.children; | ||
const depth = children.indexOf(display_object); | ||
if (depth > -1) { | ||
children.splice(depth, 1); | ||
} | ||
|
||
// dispatch removed event | ||
displayObjectDispatchRemovedEventService(display_object); | ||
|
||
// ステージに登録されている場合はステージからの削除イベントを実行 | ||
if ($stageAssignedMap.has(display_object_container)) { | ||
displayObjectDispatchRemovedToStageEventService(display_object); | ||
|
||
if (display_object.isContainerEnabled) { | ||
displayObjectContainerRemovedToStageService( | ||
display_object as unknown as DisplayObjectContainer | ||
); | ||
} | ||
} | ||
|
||
// remove root and stage | ||
if ($stageAssignedMap.has(display_object_container)) { | ||
if (!$rootMap.has(display_object)) { | ||
$rootMap.delete(display_object); | ||
} | ||
|
||
if ($stageAssignedMap.has(display_object)) { | ||
$stageAssignedMap.delete(display_object); | ||
} | ||
|
||
// コンテナであれば子孫の DisplayObject に対しても Stage と Root を解除 | ||
if (display_object.isContainerEnabled) { | ||
displayObjectContainerUnAssignStageAndRootService( | ||
display_object as unknown as DisplayObjectContainer | ||
); | ||
} | ||
} | ||
|
||
// remove parent-child relationship | ||
if ($parentMap.has(display_object)) { | ||
$parentMap.delete(display_object); | ||
} | ||
|
||
// apply changes | ||
displayObjectApplyChangesService(display_object_container); | ||
|
||
return display_object; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters