@visactor/vrender-core
Version:
## Description
38 lines (33 loc) • 2.76 kB
JavaScript
import { AABBBounds } from "@visactor/vutils";
import { Generator } from "../../common/generator";
import { application } from "../../application";
const globalBounds = new AABBBounds;
export class DirtyBoundsPlugin {
constructor() {
this.name = "DirtyBoundsPlugin", this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(),
this.key = this.name + this._uid;
}
activate(context) {
this.pluginService = context, context.stage.hooks.afterRender.tap(this.key, (stage => {
stage && stage === this.pluginService.stage && stage.dirtyBounds.clear();
})), application.graphicService.hooks.beforeUpdateAABBBounds.tap(this.key, ((graphic, stage, willUpdate, bounds) => {
graphic.glyphHost && (graphic = graphic.glyphHost), stage && stage === this.pluginService.stage && stage.renderCount && (graphic.isContainer && !graphic.shouldSelfChangeUpdateAABBBounds() || willUpdate && (globalBounds.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2),
stage.dirty(globalBounds, graphic.parent && graphic.parent.globalTransMatrix)));
})), application.graphicService.hooks.afterUpdateAABBBounds.tap(this.key, ((graphic, stage, bounds, params, selfChange) => {
stage && stage === this.pluginService.stage && stage.renderCount && (graphic.isContainer && !selfChange || stage.dirty(params.globalAABBBounds));
})), application.graphicService.hooks.clearAABBBounds.tap(this.key, ((graphic, stage, bounds) => {
stage && stage === this.pluginService.stage && stage.renderCount && stage && stage.dirty(bounds);
})), application.graphicService.hooks.onRemove.tap(this.key, (graphic => {
const stage = graphic.stage;
stage && stage === this.pluginService.stage && stage.renderCount && stage && stage.dirty(graphic.globalAABBBounds);
}));
}
deactivate(context) {
application.graphicService.hooks.beforeUpdateAABBBounds.taps = application.graphicService.hooks.beforeUpdateAABBBounds.taps.filter((item => item.name !== this.key)),
application.graphicService.hooks.afterUpdateAABBBounds.taps = application.graphicService.hooks.afterUpdateAABBBounds.taps.filter((item => item.name !== this.key)),
application.graphicService.hooks.clearAABBBounds.taps = application.graphicService.hooks.clearAABBBounds.taps.filter((item => item.name !== this.key)),
context.stage.hooks.afterRender.taps = context.stage.hooks.afterRender.taps.filter((item => item.name !== this.key)),
application.graphicService.hooks.onRemove.taps = application.graphicService.hooks.onRemove.taps.filter((item => item.name !== this.key));
}
}
//# sourceMappingURL=dirty-bounds-plugin.js.map