Fixed CENTERX and CENTERY variables

This commit is contained in:
2025-12-25 19:50:13 +00:00
parent 8ca6d8d0e1
commit a0c603ee7a
2 changed files with 28 additions and 13 deletions

View File

@@ -162,29 +162,43 @@ var $builtinmodule = function (name) {
};
}
Object.defineProperty(mod, 'T', { get: function () { return toPy(typeof T !== 'undefined' ? T : 0); } });
Object.defineProperty(mod, 'W', { get: function () { return toPy(typeof W !== 'undefined' ? W : 0); } });
Object.defineProperty(mod, 'H', { get: function () { return toPy(typeof H !== 'undefined' ? H : 0); } });
Object.defineProperty(mod, 'T', { get: function () { return toPy(lc_instance ? lc_instance.T : (window.T || 0)); } });
Object.defineProperty(mod, 'W', { get: function () { return toPy(lc_instance ? lc_instance.W : (window.W || 0)); } });
Object.defineProperty(mod, 'H', { get: function () { return toPy(lc_instance ? lc_instance.H : (window.H || 0)); } });
Object.defineProperty(mod, 'MX', {
get: function () {
if (typeof MX === 'undefined') return toPy(-1);
let mx = lc_instance ? lc_instance.MX : (window.MX || -1);
const el = document.getElementById('canvas');
if (!el) return toPy(MX);
if (!el || mx === -1) return toPy(mx);
const r = el.getBoundingClientRect();
return toPy((MX - r.left) * (el.width / r.width));
return toPy((mx - r.left) * (el.width / r.width));
}
});
Object.defineProperty(mod, 'MY', {
get: function () {
if (typeof MY === 'undefined') return toPy(-1);
let my = lc_instance ? lc_instance.MY : (window.MY || -1);
const el = document.getElementById('canvas');
if (!el) return toPy(MY);
if (!el || my === -1) return toPy(my);
const r = el.getBoundingClientRect();
return toPy((MY - r.top) * (el.height / r.height));
return toPy((my - r.top) * (el.height / r.height));
}
});
Object.defineProperty(mod, 'CENTERX', {
get: function () {
if (lc_instance && lc_instance.CENTERX !== undefined) return toPy(lc_instance.CENTERX);
if (window.CENTERX !== undefined) return toPy(window.CENTERX);
let w = lc_instance ? lc_instance.W : (window.W || 0);
return toPy(w / 2);
}
});
Object.defineProperty(mod, 'CENTERY', {
get: function () {
if (lc_instance && lc_instance.CENTERY !== undefined) return toPy(lc_instance.CENTERY);
if (window.CENTERY !== undefined) return toPy(window.CENTERY);
let h = lc_instance ? lc_instance.H : (window.H || 0);
return toPy(h / 2);
}
});
Object.defineProperty(mod, 'CENTERX', { get: function () { return toPy(typeof CENTERX !== 'undefined' ? CENTERX : 0); } });
Object.defineProperty(mod, 'CENTERY', { get: function () { return toPy(typeof CENTERY !== 'undefined' ? CENTERY : 0); } });
mod.PI = toPy(Math.PI);
mod.TWO_PI = toPy(Math.PI * 2);
@@ -223,4 +237,4 @@ var $builtinmodule = function (name) {
mod.resume = new Sk.builtin.func(() => { resume(); return Sk.builtin.none.none$; });
return mod;
};
};