redraw, and fix floodfill.

This commit is contained in:
visionmercer 2026-05-12 11:47:31 +02:00
commit b945e5f1b5
2 changed files with 86 additions and 9 deletions

View file

@ -1,4 +1,13 @@
sub thickbox(sx,sy,ex,ey,col as long)
thickline sx, sy, ex, sy, col
thickline ex, sy, ex, ey, col
thickline ex, ey, sx, ey, col
thickline sx, ey, sx, sy, col
end sub
sub filledbox(sx,sy,ex,ey,col as long)
line(sx,sy)-(ex,ey),col,bf
end sub
sub filledPolygon (Points() as long, col as long) sub filledPolygon (Points() as long, col as long)
dim i as integer, j as integer dim i as integer, j as integer
@ -159,6 +168,7 @@ end sub
DIM stackX(2000) AS INTEGER DIM stackX(2000) AS INTEGER
DIM stackY(2000) AS INTEGER DIM stackY(2000) AS INTEGER
targetColor~&=point(startX,startY) targetColor~&=point(startX,startY)
if targetColor~&=fillColor~& then exit sub
stackPtr = 1 stackPtr = 1
stackX(stackPtr) = startX stackX(stackPtr) = startX

View file

@ -187,26 +187,93 @@ end sub
sub redraw sub redraw
redim numarr(0) as long redim numarr(0) as long
_dest layers(1).ihandle
_source layers(1).ihandle
cls ,_rgb32(255)
_clearcolor _rgb32(255)
for i=lbound(commands) to ubound(commands) for i=lbound(commands) to ubound(commands)
getnums commands(i),numarr()
_dest layers(1).ihandle
select case lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1))) select case lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1)))
case "canvas" case "canvas"
case "fcolor" case "fcolor"
state.fcolor=numarr(0)
case "bcolor" case "bcolor"
state.bcolor=numarr(0)
case "brushsize"
state.brushsize=numarr(0)
case "pixel" case "pixel"
thickpixel numarr(0),numarr(1),numarr(2)
case "line" case "line"
case "brushwidth" thickline numarr(0),numarr(1),numarr(2),numarr(3),numarr(4)
case "box" case "box"
thickbox numarr(0),numarr(1),numarr(2),numarr(3),numarr(4)
case "fbox" case "fbox"
filledbox numarr(0),numarr(1),numarr(2),numarr(3),numarr(4)
case "circle" case "circle"
thickcircle numarr(0),numarr(1),numarr(2),numarr(3)
case "fcircle" case "fcircle"
filledcircle numarr(0),numarr(1),numarr(2),numarr(3)
case "polygon" case "polygon"
polygon numarr(),state.fcolor
case "fpolygon" case "fpolygon"
filledpolygon numarr(),state.fcolor
case "floodfill" case "floodfill"
floodfill numarr(0),numarr(1),numarr(2)
case ""
' blank line do nothing
case else case else
'debug info
print "'"+lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1)))+"'"
end select end select
next i next i
_dest 0
_source 0
end sub end sub
SUB getnums (inputStr$, numArray() AS LONG)
' 1. Extract inner content
sPos = INSTR(inputStr$, "(")
ePos = INSTR(inputStr$, ")")
IF sPos = 0 OR ePos <= sPos THEN EXIT SUB
content$ = MID$(inputStr$, sPos + 1, ePos - sPos - 1)
idx = -1 ' Start at -1 so the first increment hits 0
' 2. Parse segments
DO
cPos = INSTR(content$, ",")
IF cPos > 0 THEN
part$ = LTRIM$(RTRIM$(LEFT$(content$, cPos - 1)))
content$ = MID$(content$, cPos + 1)
ELSE
part$ = LTRIM$(RTRIM$(content$))
content$ = ""
END IF
IF LEN(part$) > 0 THEN
idx = idx + 1
REDIM _PRESERVE numArray(idx) AS LONG
' Determine if part is Hex (contains A-F)
isHex = 0
FOR i = 1 TO LEN(part$)
c$ = UCASE$(MID$(part$, i, 1))
IF c$ >= "A" AND c$ <= "F" THEN
isHex = 1
EXIT FOR
END IF
NEXT i
IF isHex THEN
numArray(idx) = VAL("&H" + part$)
ELSE
numArray(idx) = VAL(part$)
END IF
END IF
LOOP WHILE LEN(content$) > 0
END SUB
sub toolbox sub toolbox
dim i, x, y dim i, x, y
dim btnSize : btnSize = 32 dim btnSize : btnSize = 32
@ -420,12 +487,10 @@ sub canvas
r = sqr((canX - state.startX)^2 + (canY - state.startY)^2) r = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
filledcircle state.startX, state.startY, r, drawCol filledcircle state.startX, state.startY, r, drawCol
case 5 ' Rect case 5 ' Rect
thickline state.startX, state.startY, canX, state.startY, drawCol thickbox state.startX,state.starty,canX,canY,drawCol
thickline canX, state.startY, canX, canY, drawCol
thickline canX, canY, state.startX, canY, drawCol
thickline state.startX, canY, state.startX, state.startY, drawCol
case 6 ' Filled Rect case 6 ' Filled Rect
line (state.startX, state.startY)-(canX, canY), drawCol, bf filledbox state.startX,state.startY,canX, canY, drawCol
case 7, 8 ' Polygons case 7, 8 ' Polygons
if pointCount > 0 then if pointCount > 0 then
for p = 1 to pointCount - 1 for p = 1 to pointCount - 1
@ -485,10 +550,12 @@ sub canvas
filledcircle state.startX, state.startY, r + 1, drawCol filledcircle state.startX, state.startY, r + 1, drawCol
addcommand "fcircle ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")" addcommand "fcircle ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")"
case 5 ' Box case 5 ' Box
line (state.startX, state.startY)-(canX, canY), drawCol, b thickbox state.startX,state.starty,canX,canY,drawCol
'line (state.startX, state.startY)-(canX, canY), drawCol, b
addcommand "box ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" addcommand "box ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
case 6 ' Filled Box case 6 ' Filled Box
line (state.startX, state.startY)-(canX, canY), drawCol, bf filledbox state.startX,state.startY,canX, canY, drawCol
'line (state.startX, state.startY)-(canX, canY), drawCol, bf
addcommand "fbox ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" addcommand "fbox ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end select end select
end if end if