integers!

This commit is contained in:
visionmercer 2026-05-04 11:51:47 +02:00
commit e343e06f1c

View file

@ -2,8 +2,8 @@ type statetype
tool as long
fcolor as long
bcolor as long
offsetX as single
offsetY as single
offsetX as long
offsetY as long
zoom as single
brushsize as integer
startX as integer
@ -84,8 +84,8 @@ do
' Panning (Middle Mouse)
if _mousebutton(3) then
state.offsetX = state.offsetX + (_mousex - lastMX)
state.offsetY = state.offsetY + (_mousey - lastMY)
state.offsetX = int(state.offsetX + (_mousex - lastMX))
state.offsetY = int(state.offsetY + (_mousey - lastMY))
end if
lastMX = _mousex: lastMY = _mousey
@ -183,6 +183,15 @@ sub canvas
_dest 0
' 2. Render Layers with Clipping
dim srcX1 as long
dim srcY1 as long
dim srcX2 as long
dim srcY2 as long
dim drawX1 as long
dim drawY1 as long
dim drawX2 as long
dim drawY2 as long
dim i as integer
for i = 0 to ubound(layers)
dim img as long: img = layers(i).ihandle
@ -194,10 +203,10 @@ sub canvas
dim fullScaledH as single: fullScaledH = imgH * state.zoom
' Calculate visible area in screen coordinates (Overlap of image and viewport)
dim drawX1 as single: drawX1 = state.offsetX
dim drawY1 as single: drawY1 = state.offsetY
dim drawX2 as single: drawX2 = state.offsetX + fullScaledW
dim drawY2 as single: drawY2 = state.offsetY + fullScaledH
drawX1 = state.offsetX
drawY1 = state.offsetY
drawX2 = state.offsetX + fullScaledW
drawY2 = state.offsetY + fullScaledH
' Clip the destination to the Viewport
if drawX1 < viewX1 then drawX1 = viewX1
@ -208,10 +217,10 @@ sub canvas
' Only draw if the image is actually inside the viewport
if drawX2 > drawX1 and drawY2 > drawY1 then
' Map screen-clipped coordinates back to the source image coordinates
dim srcX1 as single: srcX1 = (drawX1 - state.offsetX) / state.zoom
dim srcY1 as single: srcY1 = (drawY1 - state.offsetY) / state.zoom
dim srcX2 as single: srcX2 = (drawX2 - state.offsetX) / state.zoom
dim srcY2 as single: srcY2 = (drawY2 - state.offsetY) / state.zoom
srcX1 = int((drawX1 - state.offsetX) / state.zoom)
srcY1 = int((drawY1 - state.offsetY) / state.zoom)
srcX2 = int((drawX2 - state.offsetX) / state.zoom)
srcY2 = int((drawY2 - state.offsetY) / state.zoom)
' Syntax: _PUTIMAGE (destX1, destY1)-(destX2, destY2), sourceHandle, 0, (srcX1, srcY1)-(srcX2, srcY2)
_putimage (drawX1, drawY1)-(drawX2, drawY2), img, 0, (srcX1, srcY1)-(srcX2, srcY2)
@ -219,8 +228,8 @@ sub canvas
next
' 3. Calculate Canvas Coordinates
dim canX as integer: canX = (_mousex - state.offsetX) / state.zoom
dim canY as integer: canY = (_mousey - state.offsetY) / state.zoom
dim canX as integer: canX = int((_mousex - state.offsetX) / state.zoom)
dim canY as integer: canY = int((_mousey - state.offsetY) / state.zoom)
static drawCol
if _mousebutton(1) then drawCol = state.fcolor