snapping working

This commit is contained in:
Luis Fernando Molina committed 2020-03-15 15:26:37 +01:00
1 parent a80f1d9454
commit 1228cd444d
2 files changed
+48 -2

No files matched your search

+15
View File
@@ -11,6 +11,7 @@ function newWorkspace () {
container: undefined,
enabled: false,
nodeChildren: undefined,
getHierarchyHeads: getHierarchyHeads,
getNodeThatIsOnFocus: getNodeThatIsOnFocus,
getNodeByShortcutKey: getNodeByShortcutKey,
stopAllRunningTasks: stopAllRunningTasks,
@@ -217,6 +218,20 @@ function newWorkspace () {
}
}
function getHierarchyHeads () {
let nodes = []
for (let i = 0; i < thisObject.workspaceNode.rootNodes.length; i++) {
let rootNode = thisObject.workspaceNode.rootNodes[i]
let nodeDefinition = APP_SCHEMA_MAP.get(rootNode.type)
if (nodeDefinition !== undefined) {
if (nodeDefinition.isHierarchyHead === true) {
nodes.push(rootNode)
}
}
}
return nodes
}
function spawn (nodeText, mousePointer) {
try {
let point = {
+33 -2
View File
@@ -124,8 +124,38 @@ function newFloatingSpace () {
enterMapMode()
} else {
if (event.buttons !== 1) { return }
thisObject.container.frame.position.x = -event.x / browserCanvas.width * SPACE_SIZE + browserCanvas.width / 2
thisObject.container.frame.position.y = -event.y / browserCanvas.height * SPACE_SIZE + browserCanvas.height / 2
let mousePosition = {
x: event.x,
y: event.y
}
let mouseAtSpace = {
x: mousePosition.x / browserCanvas.width * SPACE_SIZE,
y: mousePosition.y / browserCanvas.height * SPACE_SIZE
}
/* Let's see if we can snap to some of the root nodes that are isHierarchyHead */
let snapCandidateNodes = canvas.designSpace.workspace.getHierarchyHeads()
for (let i = 0; i < snapCandidateNodes.length; i++) {
let node = snapCandidateNodes[i]
let nodePosition = {
x: node.payload.floatingObject.container.frame.position.x,
y: node.payload.floatingObject.container.frame.position.y
}
// nodePosition = node.payload.floatingObject.container.frame.frameThisPoint(nodePosition)
let distance = Math.sqrt(Math.pow(mouseAtSpace.x - nodePosition.x, 2) + Math.pow(mouseAtSpace.y - nodePosition.y, 2))
const SNAP_THREASHOLD = 1000
if (distance < SNAP_THREASHOLD) {
mousePosition.x = nodePosition.x / SPACE_SIZE * browserCanvas.width
mousePosition.y = nodePosition.y / SPACE_SIZE * browserCanvas.height
}
}
/* Movign the Floating Space to where the mouse is. */
thisObject.container.frame.position.x = -mousePosition.x / browserCanvas.width * SPACE_SIZE + browserCanvas.width / 2
thisObject.container.frame.position.y = -mousePosition.y / browserCanvas.height * SPACE_SIZE + browserCanvas.height / 2
exitMapMode()
}
}
@@ -355,3 +385,4 @@ function newFloatingSpace () {
browserCanvasContext.fill()
}
}