Skip to content

Commit d33c89e

Browse files
authored
Paint Tool Panel Addon --Make width/height settable
1 parent 860ada8 commit d33c89e

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/addons/addons/paint-tool-panel/userscript.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export default async function () {
5353
{ title: "x", input: "number", params: "sx" },
5454
{ title: "y", input: "number", params: "sy" },
5555
"br",
56-
{ title: "width", input: "monitor", params: "width" },
57-
{ title: "height", input: "monitor", params: "height" },
56+
{ title: "width", input: "number", params: "width" },
57+
{ title: "height", input: "number", params: "height" },
5858
"br",
5959
{ title: "Group Scaling", id: "groupScale", input: "toggler" },
6060
"br",
@@ -348,7 +348,7 @@ export default async function () {
348348
}
349349

350350
function getToolFunc(name) {
351-
const isX = name.endsWith("x");
351+
const isX = name.endsWith("x") || name.endsWith("width);
352352
switch (name) {
353353
case "Position/x":
354354
case "Position/y": return (item, value) => {
@@ -376,6 +376,25 @@ export default async function () {
376376

377377
scaleItem(item, value, isX, modalStorage["groupScale"], modalStorage["strokeScale"]);
378378
}
379+
case "Scaling/width":
380+
case "Scaling/height": return (item, value) => {
381+
if (!item[panelTag]) item[panelTag] = structuredClone(valueObserverObj);
382+
const currentScale = item.getBounds()[isX ? "width" : "height"] / 2;
383+
384+
// determine the delta needed to move the currentScale to value
385+
value = value / currentScale;
386+
if (!value) value = epsilon;
387+
388+
if (isX) {
389+
value /= item[panelTag].sx;
390+
item[panelTag].sx *= value;
391+
} else {
392+
value /= item[panelTag].sy;
393+
item[panelTag].sy *= value;
394+
}
395+
396+
scaleItem(item, value, isX, modalStorage["groupScale"], modalStorage["strokeScale"]);
397+
}
379398
case "Skewing/x":
380399
case "Skewing/y": return (item, value) => {
381400
if (isX) {

0 commit comments

Comments
 (0)