Browse Source

リファクタリング

sqlite
みてるぞ 7 months ago
parent
commit
5a0cefbfbb
1 changed files with 30 additions and 28 deletions
  1. +30
    -28
      scripts/paint.js

+ 30
- 28
scripts/paint.js View File

@@ -892,46 +892,48 @@ closeModal ()
function
applyResolution ()
{
if (!(((changeWidth.value < canvasRoot.width)
|| changeHeight.value < canvasRoot.height)
&& !(window.confirm ('指定されている幅もしくは高さの値がサイズ変更前よりも小さいです.\nこのままだと右端もしくは下端が変更後のサイズに合わせてカットされてしまいます.\nよろしいかな?????'))))
{
canvasWidth = Math.max (32, Math.min (changeWidth.value, 640));
canvasHeight = Math.max (24, Math.min (changeHeight.value, 480));

canvasArea.style.width = canvasWidth + 'px';
canvasArea.style.height = canvasHeight + 'px';
if ((changeWidth.value >= canvasRoot.width)
&& (changeHeight.value >= canvasRoot.height))
return;

for (let i = 0; i < layerMax; ++i)
{
const canvas4replace = document.createElement ('canvas');
if (!(window.confirm ('指定されている幅もしくは高さの値がサイズ変更前よりも小さいです.\nこのままだと右端もしくは下端が変更後のサイズに合わせてカットされてしまいます.\nよろしいかな?????')))
return;

canvas4replace.width = canvasWidth;
canvas4replace.height = canvasHeight;
canvasWidth = Math.max (32, Math.min (changeWidth.value, 640));
canvasHeight = Math.max (24, Math.min (changeHeight.value, 480));

const canvas4replaceCtx = canvas4replace.getContext ('2d');
canvasArea.style.width = canvasWidth + 'px';
canvasArea.style.height = canvasHeight + 'px';

if (i == 0)
{
canvas4replaceCtx.fillStyle = 'white';
canvas4replaceCtx.fillRect (0, 0, canvasWidth, canvasHeight);
}
for (let i = 0; i < layerMax; ++i)
{
const canvas4replace = document.createElement ('canvas');

canvas4replaceCtx.drawImage (canvas[i], 0, 0);
canvas4replace.width = canvasWidth;
canvas4replace.height = canvasHeight;

canvas[i].width = canvasWidth;
canvas[i].height = canvasHeight;
const canvas4replaceCtx = canvas4replace.getContext ('2d');

canvasCtx[i].drawImage (canvas4replace, 0, 0);
if (i == 0)
{
canvas4replaceCtx.fillStyle = 'white';
canvas4replaceCtx.fillRect (0, 0, canvasWidth, canvasHeight);
}

canvasPerfect.width = canvasRoot.width = canvasWidth;
canvasPerfect.height = canvasRoot.height = canvasHeight;
canvas4replaceCtx.drawImage (canvas[i], 0, 0);

reDraw ();
canvas[i].width = canvasWidth;
canvas[i].height = canvasHeight;

closeModal ();
canvasCtx[i].drawImage (canvas4replace, 0, 0);
}

canvasPerfect.width = canvasRoot.width = canvasWidth;
canvasPerfect.height = canvasRoot.height = canvasHeight;

reDraw ();

closeModal ();
}




Loading…
Cancel
Save