Fix Sta mode 100% CPU: skip checkerboard, skip idle repaints

- Replace pixel-by-pixel checkerboard with solid bg in Sta mode
- Animation timer skips repaint in static mode (no animation)
- Refresh timer only repaints Sta when source image actually changes
This commit is contained in:
Cidwel Highwind 2026-04-04 12:52:43 +02:00
parent 83645dbeae
commit b2a333405a
1 changed files with 16 additions and 9 deletions

View File

@ -1425,12 +1425,9 @@ openPreviewWindow = function()
local sy = S.previewStaScrollY local sy = S.previewStaScrollY
local sw = S.sourceImage.width * z local sw = S.sourceImage.width * z
local sh = S.sourceImage.height * z local sh = S.sourceImage.height * z
if S.useBgColor then -- Use solid bg instead of checkerboard for performance
gc.color = S.bgColor gc.color = S.useBgColor and S.bgColor or Color(50, 50, 50)
gc:fillRect(Rectangle(sx, sy, sw, sh)) gc:fillRect(Rectangle(sx, sy, sw, sh))
else
drawCheckerboard(gc, sw, sh, z, sx, sy)
end
gc:drawImage(S.sourceImage, gc:drawImage(S.sourceImage,
Rectangle(0, 0, S.sourceImage.width, S.sourceImage.height), Rectangle(0, 0, S.sourceImage.width, S.sourceImage.height),
Rectangle(sx, sy, sw, sh)) Rectangle(sx, sy, sw, sh))
@ -1581,18 +1578,28 @@ openPreviewWindow = function()
previewTimer = Timer{ previewTimer = Timer{
interval = S.animSpeed / 1000.0, interval = S.animSpeed / 1000.0,
ontick = function() ontick = function()
if S.previewMode ~= "static" then
pvAnimFrame.value = pvAnimFrame.value + 1 pvAnimFrame.value = pvAnimFrame.value + 1
pcall(function() previewDlg:repaint() end) pcall(function() previewDlg:repaint() end)
end end
end
} }
previewTimer:start() previewTimer:start()
pvRefreshTimer = Timer{ pvRefreshTimer = Timer{
interval = 0.5, interval = 0.5,
ontick = function() ontick = function()
local prevImg = S.sourceImage
refreshSource() refreshSource()
refreshLockFile() refreshLockFile()
-- In static mode, only repaint if source image changed
if S.previewMode == "static" then
if S.sourceImage ~= prevImg then
pcall(function() previewDlg:repaint() end) pcall(function() previewDlg:repaint() end)
end
else
pcall(function() previewDlg:repaint() end)
end
-- Auto-detect file change -- Auto-detect file change
local currentFile = app.sprite and app.sprite.filename or "" local currentFile = app.sprite and app.sprite.filename or ""