|
|
|
@ -413,6 +413,24 @@ |
|
|
|
return this._hitTestDetailed(clientX, clientY).uuid || ''; |
|
|
|
return this._hitTestDetailed(clientX, clientY).uuid || ''; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 取 UITransform(多种查找方式,与命中逻辑一致) */ |
|
|
|
|
|
|
|
WorkbenchAgent.prototype._getUiTransform = function (node) { |
|
|
|
|
|
|
|
var cc = this.cc; |
|
|
|
|
|
|
|
if (!cc || !node || !node.getComponent) return null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var uit = (cc.UITransform && node.getComponent(cc.UITransform)) || |
|
|
|
|
|
|
|
node.getComponent('cc.UITransform') || |
|
|
|
|
|
|
|
node.getComponent('UITransform') || |
|
|
|
|
|
|
|
null; |
|
|
|
|
|
|
|
if (uit && uit.getBoundingBoxToWorld) return uit; |
|
|
|
|
|
|
|
} catch (e) { /* */ } |
|
|
|
|
|
|
|
var comps = node.components || []; |
|
|
|
|
|
|
|
for (var i = 0; i < comps.length; i++) { |
|
|
|
|
|
|
|
if (comps[i] && typeof comps[i].getBoundingBoxToWorld === 'function') return comps[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WorkbenchAgent.prototype._ensureOverlay = function () { |
|
|
|
WorkbenchAgent.prototype._ensureOverlay = function () { |
|
|
|
var el = document.getElementById('pw-pick-overlay'); |
|
|
|
var el = document.getElementById('pw-pick-overlay'); |
|
|
|
if (!el) { |
|
|
|
if (!el) { |
|
|
|
@ -420,7 +438,10 @@ |
|
|
|
el.id = 'pw-pick-overlay'; |
|
|
|
el.id = 'pw-pick-overlay'; |
|
|
|
el.className = 'pw-pick-overlay'; |
|
|
|
el.className = 'pw-pick-overlay'; |
|
|
|
el.hidden = true; |
|
|
|
el.hidden = true; |
|
|
|
(document.body || document.documentElement).appendChild(el); |
|
|
|
// 挂到画布容器内,避免被设备壳/全局样式盖住
|
|
|
|
|
|
|
|
var canvas = this._getCanvasEl(); |
|
|
|
|
|
|
|
var host = (canvas && canvas.parentElement) || document.body || document.documentElement; |
|
|
|
|
|
|
|
host.appendChild(el); |
|
|
|
} |
|
|
|
} |
|
|
|
this._overlay = el; |
|
|
|
this._overlay = el; |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -439,24 +460,46 @@ |
|
|
|
overlay.hidden = true; |
|
|
|
overlay.hidden = true; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 相对画布父容器定位(absolute),比 fixed 更稳
|
|
|
|
|
|
|
|
var canvas = this._getCanvasEl(); |
|
|
|
|
|
|
|
var parent = (canvas && canvas.parentElement) || overlay.parentNode; |
|
|
|
|
|
|
|
var originLeft = 0; |
|
|
|
|
|
|
|
var originTop = 0; |
|
|
|
|
|
|
|
if (parent && parent.getBoundingClientRect) { |
|
|
|
|
|
|
|
var pr = parent.getBoundingClientRect(); |
|
|
|
|
|
|
|
originLeft = pr.left; |
|
|
|
|
|
|
|
originTop = pr.top; |
|
|
|
|
|
|
|
if (getComputedStyle(parent).position === 'static') { |
|
|
|
|
|
|
|
parent.style.position = 'relative'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
overlay.hidden = false; |
|
|
|
overlay.hidden = false; |
|
|
|
overlay.style.position = 'fixed'; |
|
|
|
overlay.style.position = 'absolute'; |
|
|
|
overlay.style.left = box.left + 'px'; |
|
|
|
overlay.style.left = (box.left - originLeft) + 'px'; |
|
|
|
overlay.style.top = box.top + 'px'; |
|
|
|
overlay.style.top = (box.top - originTop) + 'px'; |
|
|
|
overlay.style.width = box.width + 'px'; |
|
|
|
overlay.style.width = box.width + 'px'; |
|
|
|
overlay.style.height = box.height + 'px'; |
|
|
|
overlay.style.height = box.height + 'px'; |
|
|
|
overlay.style.zIndex = '99999'; |
|
|
|
overlay.style.zIndex = '99999'; |
|
|
|
|
|
|
|
overlay.style.display = 'block'; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WorkbenchAgent.prototype._nodeClientRect = function (node) { |
|
|
|
WorkbenchAgent.prototype._nodeClientRect = function (node) { |
|
|
|
var cc = this.cc; |
|
|
|
var cc = this.cc; |
|
|
|
var canvas = this._getCanvasEl(); |
|
|
|
var canvas = this._getCanvasEl(); |
|
|
|
if (!cc || !canvas || !node || !node.isValid) return null; |
|
|
|
if (!cc || !canvas || !node) return null; |
|
|
|
var uit = node.getComponent && node.getComponent(cc.UITransform); |
|
|
|
if (node.isValid === false) return null; |
|
|
|
|
|
|
|
var uit = this._getUiTransform(node); |
|
|
|
if (!uit || !uit.getBoundingBoxToWorld) return null; |
|
|
|
if (!uit || !uit.getBoundingBoxToWorld) return null; |
|
|
|
var box = null; |
|
|
|
var box = null; |
|
|
|
try { box = uit.getBoundingBoxToWorld(); } catch (e) { return null; } |
|
|
|
try { box = uit.getBoundingBoxToWorld(); } catch (e) { return null; } |
|
|
|
if (!box) return null; |
|
|
|
if (!box) return null; |
|
|
|
|
|
|
|
var bx = Number(box.x); |
|
|
|
|
|
|
|
var by = Number(box.y); |
|
|
|
|
|
|
|
var bw = Number(box.width); |
|
|
|
|
|
|
|
var bh = Number(box.height); |
|
|
|
|
|
|
|
if (!isFinite(bx) || !isFinite(by) || !isFinite(bw) || !isFinite(bh)) return null; |
|
|
|
|
|
|
|
if (bw < 0) { bx += bw; bw = -bw; } |
|
|
|
|
|
|
|
if (bh < 0) { by += bh; bh = -bh; } |
|
|
|
|
|
|
|
|
|
|
|
var rect = canvas.getBoundingClientRect(); |
|
|
|
var rect = canvas.getBoundingClientRect(); |
|
|
|
var cbox = this._canvasWorldBox(); |
|
|
|
var cbox = this._canvasWorldBox(); |
|
|
|
@ -474,10 +517,10 @@ |
|
|
|
oy = 0; |
|
|
|
oy = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
var corners = [ |
|
|
|
var corners = [ |
|
|
|
{ x: box.x, y: box.y }, |
|
|
|
{ x: bx, y: by }, |
|
|
|
{ x: box.x + box.width, y: box.y }, |
|
|
|
{ x: bx + bw, y: by }, |
|
|
|
{ x: box.x + box.width, y: box.y + box.height }, |
|
|
|
{ x: bx + bw, y: by + bh }, |
|
|
|
{ x: box.x, y: box.y + box.height }, |
|
|
|
{ x: bx, y: by + bh }, |
|
|
|
]; |
|
|
|
]; |
|
|
|
var xs = []; |
|
|
|
var xs = []; |
|
|
|
var ys = []; |
|
|
|
var ys = []; |
|
|
|
@ -502,6 +545,12 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
WorkbenchAgent.prototype._getOverlayRect = function () { |
|
|
|
WorkbenchAgent.prototype._getOverlayRect = function () { |
|
|
|
|
|
|
|
// 优先读最新计算框,避免 style 尚未写入
|
|
|
|
|
|
|
|
var node = this._findNode(this._selectedUuid); |
|
|
|
|
|
|
|
if (node) { |
|
|
|
|
|
|
|
var box = this._nodeClientRect(node); |
|
|
|
|
|
|
|
if (box) return box; |
|
|
|
|
|
|
|
} |
|
|
|
var overlay = this._overlay; |
|
|
|
var overlay = this._overlay; |
|
|
|
if (!overlay || overlay.hidden) return null; |
|
|
|
if (!overlay || overlay.hidden) return null; |
|
|
|
return { |
|
|
|
return { |
|
|
|
|