|
@@ -855,6 +855,8 @@ class SymjaConsole {
|
|
|
|
|
|
|
|
createIJSAPI(pluginOutputs) {
|
|
createIJSAPI(pluginOutputs) {
|
|
|
const self = this;
|
|
const self = this;
|
|
|
|
|
+ // 闭包引用 — IJS.input.xy() 需要访问 canvas 对象
|
|
|
|
|
+ const canvasRef = { _canvas: null, _logicalW: 600, _logicalH: 800 };
|
|
|
return {
|
|
return {
|
|
|
// ── IJS.Symja 数学引擎 ─────────────────────────
|
|
// ── IJS.Symja 数学引擎 ─────────────────────────
|
|
|
Symja: {
|
|
Symja: {
|
|
@@ -940,6 +942,10 @@ class SymjaConsole {
|
|
|
this._ctx.scale(dpr, dpr);
|
|
this._ctx.scale(dpr, dpr);
|
|
|
this._logicalW = cw;
|
|
this._logicalW = cw;
|
|
|
this._logicalH = ch;
|
|
this._logicalH = ch;
|
|
|
|
|
+ // 同步给 input.xy() 的闭包引用
|
|
|
|
|
+ canvasRef._canvas = c;
|
|
|
|
|
+ canvasRef._logicalW = cw;
|
|
|
|
|
+ canvasRef._logicalH = ch;
|
|
|
panel.appendChild(c);
|
|
panel.appendChild(c);
|
|
|
return this._ctx;
|
|
return this._ctx;
|
|
|
},
|
|
},
|
|
@@ -969,6 +975,10 @@ class SymjaConsole {
|
|
|
if (this._canvas) {
|
|
if (this._canvas) {
|
|
|
this._canvas.width = w;
|
|
this._canvas.width = w;
|
|
|
this._canvas.height = h;
|
|
this._canvas.height = h;
|
|
|
|
|
+ this._logicalW = w;
|
|
|
|
|
+ this._logicalH = h;
|
|
|
|
|
+ canvasRef._logicalW = w;
|
|
|
|
|
+ canvasRef._logicalH = h;
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
// 动画循环
|
|
// 动画循环
|
|
@@ -997,17 +1007,14 @@ class SymjaConsole {
|
|
|
onTouchEnd: function(cb) { this._callbacks.touchend = cb; this._bind(); },
|
|
onTouchEnd: function(cb) { this._callbacks.touchend = cb; this._bind(); },
|
|
|
/** 将触摸事件的 clientX/Y 转换为画布逻辑坐标 */
|
|
/** 将触摸事件的 clientX/Y 转换为画布逻辑坐标 */
|
|
|
xy: function(e) {
|
|
xy: function(e) {
|
|
|
- var idx = 0;
|
|
|
|
|
- if (e.changedTouches) idx = 0;
|
|
|
|
|
- else if (e.touches) idx = 0;
|
|
|
|
|
var touch = e.changedTouches ? e.changedTouches[0] : (e.touches ? e.touches[0] : e);
|
|
var touch = e.changedTouches ? e.changedTouches[0] : (e.touches ? e.touches[0] : e);
|
|
|
if (!touch) return {x:0,y:0};
|
|
if (!touch) return {x:0,y:0};
|
|
|
- var c = IJS.canvas._canvas;
|
|
|
|
|
|
|
+ var c = canvasRef._canvas;
|
|
|
if (!c) return {x: touch.clientX, y: touch.clientY};
|
|
if (!c) return {x: touch.clientX, y: touch.clientY};
|
|
|
var r = c.getBoundingClientRect();
|
|
var r = c.getBoundingClientRect();
|
|
|
return {
|
|
return {
|
|
|
- x: (touch.clientX - r.left) * (IJS.canvas._logicalW / r.width),
|
|
|
|
|
- y: (touch.clientY - r.top) * (IJS.canvas._logicalH / r.height)
|
|
|
|
|
|
|
+ x: (touch.clientX - r.left) * (canvasRef._logicalW / r.width),
|
|
|
|
|
+ y: (touch.clientY - r.top) * (canvasRef._logicalH / r.height)
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
_bound: false,
|
|
_bound: false,
|