Skip to content

Commit

Permalink
added a concept of shadow tranform to SchemeContainer but not using i…
Browse files Browse the repository at this point in the history
…t yet
  • Loading branch information
ishubin committed Nov 30, 2024
1 parent 3bc3818 commit 6486618
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/ui/components/editor/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function loadAndMountExternalComponent(schemeContainer, userEventBus, ite
rectItem.area.sx = scale;
rectItem.area.sy = scale;


rectItem.meta.componentItemIdsForInit = componentSchemeContainer.indexUserEvents(componentUserEventBus, compilerErrorCallback);
rectItem.meta.componentSchemeContainer = componentSchemeContainer;
rectItem.meta.componentUserEventBus = componentUserEventBus;
Expand All @@ -107,6 +108,12 @@ export function loadAndMountExternalComponent(schemeContainer, userEventBus, ite

schemeContainer.indexUserEventsForItems(item._childItems, userEventBus, compilerErrorCallback);

const shadowTransform = myMath.standardTransformWithArea(
myMath.multiplyMatrices(schemeContainer.shadowTransform, rectItem.meta.transformMatrix),
rectItem.area
);
componentSchemeContainer.setShadowTransform(shadowTransform);

EditorEventBus.item.changed.specific.$emit(schemeContainer.editorId, item.id);
})
.catch(err => {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/scheme/ItemMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export function calculateScreenTransformForArea(area, width, height) {
};
}

export function worldPointOnItem(x, y, item) {
export function worldPointOnItem(x, y, item, transformMatrix) {
// if (transformMatrix)
return myMath.worldPointInArea(x, y, item.area, (item.meta && item.meta.transformMatrix) ? item.meta.transformMatrix : null);
}

Expand Down
14 changes: 14 additions & 0 deletions src/ui/scheme/SchemeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ function _markTemplateRef(items, templateRef, templateRootId) {
})
}

/**
*
* @returns {Item}
*/
export function createDefaultRectItem() {
const item = utils.clone(defaultItem);
item.shape = 'rect';
Expand Down Expand Up @@ -362,6 +366,12 @@ class SchemeContainer {

this.svgOutlinePathCache = new ItemCache(getItemOutlineSVGPath);

// Shadow transform is used in external components and it represents the complete transformation of
// the component item root. This is needed to correctly convert child component items
// to the global world transform (e.g. when dragging items in view mode,
// or converting mouse coords to local item coords)
this.shadowTransform = myMath.identityMatrix();

// stores all snapping rules for items (used when user drags an item)
this.relativeSnappers = {
horizontal: [],
Expand All @@ -380,6 +390,10 @@ class SchemeContainer {
this.reindexItems();
}

setShadowTransform(shadowTransform) {
this.shadowTransform = shadowTransform;
}

hasDependencyOnItem(itemId, potentialDependencyItemId) {
const dependencyIds = this.dependencyItemMap[itemId];
if (!dependencyIds || dependencyIds.length === 0) {
Expand Down

0 comments on commit 6486618

Please sign in to comment.