indenting and case lowering

This commit is contained in:
visionmercer 2026-05-19 12:23:01 +02:00
commit 7aacca5803

View file

@ -46,7 +46,7 @@ _dest layers(0).ihandle
addcommand "canvas ("+tst(_width)+","+tst(_height)+")" addcommand "canvas ("+tst(_width)+","+tst(_height)+")"
for y = 0 to _height - 16 step 16 for y = 0 to _height - 16 step 16
for x = 0 to _width - 16 step 16 for x = 0 to _width - 16 step 16
if ((x + y) / 16 AND 1) = 0 then if ((x + y) / 16 and 1) = 0 then
line (x, y)-(x + 16, y + 16), _rgb32(127), bf line (x, y)-(x + 16, y + 16), _rgb32(127), bf
else else
line (x, y)-(x + 16, y + 16), _rgb32(192), bf line (x, y)-(x + 16, y + 16), _rgb32(192), bf
@ -76,7 +76,7 @@ dim oldHeight as integer
oldWidth=_width oldWidth=_width
oldHeight=_height oldHeight=_height
do do
if CheckResize(_source) = -1 THEN if CheckResize(_source) = -1 then
diffX = _width - oldWidth diffX = _width - oldWidth
diffY = _height - oldHeight diffY = _height - oldHeight
state.offsetX = state.offsetX + (diffX / 2) state.offsetX = state.offsetX + (diffX / 2)
@ -207,7 +207,7 @@ sub redraw
_dest layers(0).ihandle _dest layers(0).ihandle
for y = 0 to _height - 16 step 16 for y = 0 to _height - 16 step 16
for x = 0 to _width - 16 step 16 for x = 0 to _width - 16 step 16
if ((x + y) / 16 AND 1) = 0 then if ((x + y) / 16 and 1) = 0 then
line (x, y)-(x + 16, y + 16), _rgb32(127), bf line (x, y)-(x + 16, y + 16), _rgb32(127), bf
else else
line (x, y)-(x + 16, y + 16), _rgb32(192), bf line (x, y)-(x + 16, y + 16), _rgb32(192), bf
@ -236,9 +236,9 @@ sub redraw
case "polygon" case "polygon"
polygon numarr(),state.fcolor polygon numarr(),state.fcolor
case "fpolygon" case "fpolygon"
filledpolygon numarr(),state.fcolor filledPolygon numarr(),state.fcolor
case "floodfill" case "floodfill"
floodfill numarr(0),numarr(1),numarr(2) FloodFill numarr(0),numarr(1),numarr(2)
case "" case ""
' blank line do nothing ' blank line do nothing
case else case else
@ -250,48 +250,48 @@ sub redraw
_source 0 _source 0
end sub end sub
SUB getnums (inputStr$, numArray() AS LONG) sub getnums (inputStr$, numArray() as long)
' 1. Extract inner content ' 1. Extract inner content
sPos = INSTR(inputStr$, "(") sPos = instr(inputStr$, "(")
ePos = INSTR(inputStr$, ")") ePos = instr(inputStr$, ")")
IF sPos = 0 OR ePos <= sPos THEN EXIT SUB if sPos = 0 or ePos <= sPos then exit sub
content$ = MID$(inputStr$, sPos + 1, ePos - sPos - 1) content$ = mid$(inputStr$, sPos + 1, ePos - sPos - 1)
idx = -1 ' Start at -1 so the first increment hits 0 idx = -1 ' Start at -1 so the first increment hits 0
' 2. Parse segments ' 2. Parse segments
DO do
cPos = INSTR(content$, ",") cPos = instr(content$, ",")
IF cPos > 0 THEN if cPos > 0 then
part$ = LTRIM$(RTRIM$(LEFT$(content$, cPos - 1))) part$ = ltrim$(rtrim$(left$(content$, cPos - 1)))
content$ = MID$(content$, cPos + 1) content$ = mid$(content$, cPos + 1)
ELSE else
part$ = LTRIM$(RTRIM$(content$)) part$ = ltrim$(rtrim$(content$))
content$ = "" content$ = ""
END IF end if
IF LEN(part$) > 0 THEN if len(part$) > 0 then
idx = idx + 1 idx = idx + 1
REDIM _PRESERVE numArray(idx) AS LONG redim _preserve numArray(idx) as long
' Determine if part is Hex (contains A-F) ' Determine if part is Hex (contains A-F)
isHex = 0 isHex = 0
FOR i = 1 TO LEN(part$) for i = 1 to len(part$)
c$ = UCASE$(MID$(part$, i, 1)) c$ = ucase$(mid$(part$, i, 1))
IF c$ >= "A" AND c$ <= "F" THEN if c$ >= "A" and c$ <= "F" then
isHex = 1 isHex = 1
EXIT FOR exit for
END IF end if
NEXT i next i
IF isHex THEN if isHex then
numArray(idx) = VAL("&H" + part$) numArray(idx) = val("&H" + part$)
ELSE else
numArray(idx) = VAL(part$) numArray(idx) = val(part$)
END IF end if
END IF end if
LOOP WHILE LEN(content$) > 0 loop while len(content$) > 0
END SUB end sub
sub toolbox sub toolbox
dim i, x, y dim i, x, y
@ -305,7 +305,7 @@ sub toolbox
' y will only increase every 2 buttons ' y will only increase every 2 buttons
' Use Int() if your language doesn't support the \ operator ' Use Int() if your language doesn't support the \ operator
y = Int(i / 2) * (btnSize + spacing) y = int(i / 2) * (btnSize + spacing)
if imagebutton(x, y, btnSize, btnSize, icon(i)) then if imagebutton(x, y, btnSize, btnSize, icon(i)) then
state.tool = i + 1 state.tool = i + 1
@ -472,126 +472,126 @@ sub canvas
end sub end sub
sub do.pencil(x as long,y as long, col as long) sub do.pencil(x as long,y as long, col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
osource = _source osource = _source
odest = _dest odest = _dest
_dest layers(1).ihandle _dest layers(1).ihandle
if _mousebutton(1) or _mousebutton(2) then if _mousebutton(1) or _mousebutton(2) then
thickpixel x,y,col thickpixel x,y,col
addcommand "pixel ("+tst(x)+","+tst(y)+","+hex$(col)+")" addcommand "pixel ("+tst(x)+","+tst(y)+","+hex$(col)+")"
end if end if
state.isdrawing=0 state.isDrawing=0
_dest odest _dest odest
end sub end sub
sub do.line(sx as long,sy as long,ex as long,ey as long,col as long) sub do.line(sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
if state.isdrawing then if state.isDrawing then
osource = _source osource = _source
odest = _dest odest = _dest
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
_dest layers(1).ihandle _dest layers(1).ihandle
addcommand "line (" + tst(sx) + "," + tst(sy) + "," + tst(ex) + "," + tst(ey) + "," + hex$(col) + ")" addcommand "line (" + tst(sx) + "," + tst(sy) + "," + tst(ex) + "," + tst(ey) + "," + hex$(col) + ")"
state.isdrawing=0 state.isDrawing=0
else else
_dest layers(2).ihandle _dest layers(2).ihandle
end if end if
thickline sx, sy, ex, ey, col thickline sx, sy, ex, ey, col
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.circle (x as long,y as long,r as long,col as long) sub do.circle (x as long,y as long,r as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
if state.isdrawing then if state.isDrawing then
osource = _source osource = _source
odest = _dest odest = _dest
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
_dest layers(1).ihandle _dest layers(1).ihandle
addcommand "circle ("+tst(x)+","+tst(y)+","+tst(int(r))+","+hex$(col)+")" addcommand "circle ("+tst(x)+","+tst(y)+","+tst(int(r))+","+hex$(col)+")"
state.isdrawing=0 state.isDrawing=0
else else
_dest layers(2).ihandle _dest layers(2).ihandle
end if end if
thickcircle x, y, r, col thickcircle x, y, r, col
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.fcircle (x as long,y as long,r as long,col as long) sub do.fcircle (x as long,y as long,r as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
if state.isdrawing then if state.isDrawing then
osource = _source osource = _source
odest = _dest odest = _dest
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
_dest layers(1).ihandle _dest layers(1).ihandle
addcommand "fcircle ("+tst(x)+","+tst(y)+","+tst(int(r))+","+hex$(col)+")" addcommand "fcircle ("+tst(x)+","+tst(y)+","+tst(int(r))+","+hex$(col)+")"
state.isdrawing=0 state.isDrawing=0
else else
_dest layers(2).ihandle _dest layers(2).ihandle
end if end if
filledcircle x, y, r, col filledcircle x, y, r, col
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.box(sx as long,sy as long,ex as long,ey as long,col as long) sub do.box(sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
if state.isdrawing then if state.isDrawing then
osource = _source osource = _source
odest = _dest odest = _dest
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
_dest layers(1).ihandle _dest layers(1).ihandle
addcommand "box ("+tst(sX)+","+tst(sY)+","+tst(eX)+","+tst(eY)+","+hex$(Col)+")" addcommand "box ("+tst(sx)+","+tst(sy)+","+tst(ex)+","+tst(ey)+","+hex$(col)+")"
state.isdrawing=0 state.isDrawing=0
else else
_dest layers(2).ihandle _dest layers(2).ihandle
end if end if
thickbox sX,sy,eX,eY,Col thickbox sx,sy,ex,ey,col
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.fbox(sx as long,sy as long,ex as long,ey as long,col as long) sub do.fbox(sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
if state.isdrawing then if state.isDrawing then
osource = _source osource = _source
odest = _dest odest = _dest
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
_dest layers(1).ihandle _dest layers(1).ihandle
addcommand "fbox ("+tst(sX)+","+tst(sY)+","+tst(eX)+","+tst(eY)+","+hex$(Col)+")" addcommand "fbox ("+tst(sx)+","+tst(sy)+","+tst(ex)+","+tst(ey)+","+hex$(col)+")"
state.isdrawing=0 state.isDrawing=0
else else
_dest layers(2).ihandle _dest layers(2).ihandle
end if end if
filledbox sX,sy,eX,eY,Col filledbox sx,sy,ex,ey,col
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.polygon(x as long, y as long) sub do.polygon(x as long, y as long)
' 1. Internalized State Memory ' 1. Internalized State Memory
static polypoints(500) as long static polypoints(500) as long
static pointCount as integer static pointCount as integer
dim osource as long dim osource as long
dim odest as long dim odest as long
dim p as integer dim p as integer
dim i as integer dim i as integer
dim tmpstr as string dim tmpstr as string
if state.isdrawing then if state.isDrawing then
osource = _source osource = _source
odest = _dest odest = _dest
@ -619,7 +619,7 @@ if state.isdrawing then
addcommand tmpstr addcommand tmpstr
' Clean up local tool state ' Clean up local tool state
state.isdrawing = 0 state.isDrawing = 0
pointCount = 0 pointCount = 0
else else
' Live preview rendering loop ' Live preview rendering loop
@ -634,21 +634,21 @@ if state.isdrawing then
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.fpolygon(x as long, y as long) sub do.fpolygon(x as long, y as long)
' 1. Internalized State Memory ' 1. Internalized State Memory
static polypoints(500) as long static polypoints(500) as long
static pointCount as integer static pointCount as integer
dim osource as long dim osource as long
dim odest as long dim odest as long
dim p as integer dim p as integer
dim i as integer dim i as integer
dim tmpstr as string dim tmpstr as string
if state.isdrawing then if state.isDrawing then
osource = _source osource = _source
odest = _dest odest = _dest
@ -666,7 +666,7 @@ if state.isdrawing then
redim finalP(pointCount * 2 - 1) as long redim finalP(pointCount * 2 - 1) as long
for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next
filledpolygon finalP(), state.fcolor filledPolygon finalP(), state.fcolor
tmpstr = "fpolygon (" tmpstr = "fpolygon ("
for i = 0 to ubound(finalP) - 1 for i = 0 to ubound(finalP) - 1
@ -676,7 +676,7 @@ if state.isdrawing then
addcommand tmpstr addcommand tmpstr
' Clean up local tool state ' Clean up local tool state
state.isdrawing = 0 state.isDrawing = 0
pointCount = 0 pointCount = 0
else else
' Live preview rendering loop ' Live preview rendering loop
@ -691,30 +691,30 @@ if state.isdrawing then
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.floodfill(x as long,y as long, col as long) sub do.floodfill(x as long,y as long, col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
osource = _source osource = _source
odest = _dest odest = _dest
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
_source layers(1).ihandle _source layers(1).ihandle
_dest layers(1).ihandle _dest layers(1).ihandle
floodfill x,y,col FloodFill x,y,col
addcommand "floodfill ("+tst(x)+","+tst(y)+","+hex$(col)+")" addcommand "floodfill ("+tst(x)+","+tst(y)+","+hex$(col)+")"
_source osource _source osource
_dest odest _dest odest
end if end if
end sub end sub
sub do.eyedropper(x,y) sub do.eyedropper(x,y)
dim osource as long dim osource as long
dim odest as long dim odest as long
osource = _source osource = _source
odest = _dest odest = _dest
_source layers(1).ihandle _source layers(1).ihandle
end sub end sub
@ -822,98 +822,98 @@ function __internaluiicon&(index as long,imagehandle as long,mode as integer)
end function end function
FUNCTION CheckResize (CurrentScreen AS _UNSIGNED LONG) 'pulled straight out of the wiki' function CheckResize (CurrentScreen as _unsigned long) 'pulled straight out of the wiki'
DIM TempScreen AS _UNSIGNED LONG dim TempScreen as _unsigned long
CheckResize = 0 CheckResize = 0
IF _RESIZE THEN if _resize then
TempScreen = _COPYIMAGE(CurrentScreen, 32) TempScreen = _copyimage(CurrentScreen, 32)
SCREEN TempScreen screen TempScreen
_FREEIMAGE CurrentScreen _freeimage CurrentScreen
CurrentScreen = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32) CurrentScreen = _newimage(_resizewidth, _resizeheight, 32)
SCREEN CurrentScreen screen CurrentScreen
_PUTIMAGE (0, 0), TempScreen, CurrentScreen _putimage (0, 0), TempScreen, CurrentScreen
_DISPLAY _display
_FREEIMAGE TempScreen _freeimage TempScreen
CheckResize = -1 CheckResize = -1
END IF end if
END FUNCTION end function
sub menu() sub menu()
dim logo as long dim logo as long
dim filename as string dim filename as string
' A logo is needed' ' A logo is needed'
'logo=_loadimage("logo.png") 'logo=_loadimage("logo.png")
Line (0,0)-(_width-1,_height-1),_rgb32(0,192),bf line (0,0)-(_width-1,_height-1),_rgb32(0,192),bf
'_putimage ((_width(0)-_width(logo))/2,10),logo '_putimage ((_width(0)-_width(logo))/2,10),logo
dim i as integer dim i as integer
dim fh as integer dim fh as integer
do until done do until done
k$=inkey$ k$=inkey$
while _mouseinput:wend while _mouseinput:wend
mouseclicked=mbd and not _mousebutton(1) mouseclicked=mbd and not _mousebutton(1)
mbd=_mousebutton(1) mbd=_mousebutton(1)
if link(10,10,"open") then if link(10,10,"open") then
filename=textinput(10,10,100,23,"") filename=textinput(10,10,100,23,"")
if filename="" then exit sub if filename="" then exit sub
fh = freefile fh = freefile
redim commands(2000) as string redim commands(2000) as string
open filename for input as fh open filename for input as fh
do until eof(fh) do until eof(fh)
line input #fh, commands(i) line input #fh, commands(i)
i=i+1 i=i+1
if i>ubound(commands) then redim _preserve commands(ubound(commands)*2) as string if i>ubound(commands) then redim _preserve commands(ubound(commands)*2) as string
loop loop
close fh close fh
redim _preserve commands(i-1) as string redim _preserve commands(i-1) as string
redraw redraw
done=-1 done=-1
end if end if
if link(10,34,"save") then if link(10,34,"save") then
filename=textinput(1,34,100,23,"") filename=textinput(1,34,100,23,"")
if filename="" then exit sub if filename="" then exit sub
fh = freefile fh = freefile
open filename for output as fh open filename for output as fh
for i=0 to ubound(commands) for i=0 to ubound(commands)
print #fh, commands(i) print #fh, commands(i)
next i next i
close fh close fh
done=-1 done=-1
end if end if
if link(10,56,"export") then if link(10,56,"export") then
filename=textinput(10,56,100,23,"") filename=textinput(10,56,100,23,"")
if filename="" then exit sub if filename="" then exit sub
select case lcase$(right$(filename,4)) select case lcase$(right$(filename,4))
case ".png" case ".png"
save32bitPNG layers(1).ihandle, filename save32bitPNG layers(1).ihandle, filename
case ".bmp" case ".bmp"
save24bitBmp layers(1).ihandle, filename save24bitBmp layers(1).ihandle, filename
case ".ppm" case ".ppm"
savebinaryPPM layers(1).ihandle, filename SaveBinaryPPM layers(1).ihandle, filename
case else case else
save32bitPNG layers(1).ihandle, filename save32bitPNG layers(1).ihandle, filename
end select end select
done=-1 done=-1
end if end if
if link(10,78,"refenece img") then if link(10,78,"refenece img") then
filename=textinput(10,78,100,23,"") filename=textinput(10,78,100,23,"")
if filename="" then exit sub if filename="" then exit sub
if not _fileexists(filename) then exit sub if not _fileexists(filename) then exit sub
if layers(3).ihandle <> 0 then _freeimage layers(3).ihandle if layers(3).ihandle <> 0 then _freeimage layers(3).ihandle
layers(3).ihandle=_loadimage(filename) layers(3).ihandle=_loadimage(filename)
_setalpha 20, layers(3).ihandle _setalpha 20, layers(3).ihandle
done=-1 done=-1
end if end if
if link(10,100,"exit") then system if link(10,100,"exit") then system
if k$=chr$(27) then done=-1 if k$=chr$(27) then done=-1
_limit 30 _limit 30
_display _display
loop loop
end sub end sub
sub palettemanager(col as _unsigned long) sub palettemanager(col as _unsigned long)
@ -921,30 +921,30 @@ sub palettemanager(col as _unsigned long)
'TODO: build palette mamager ui 'TODO: build palette mamager ui
end sub end sub
FUNCTION closestcolor~& (colour AS _UNSIGNED LONG, carr() AS _UNSIGNED LONG) function closestcolor~& (colour as _unsigned long, carr() as _unsigned long)
DIM r AS INTEGER dim r as integer
DIM g AS INTEGER dim g as integer
DIM b AS INTEGER dim b as integer
DIM ar AS INTEGER dim ar as integer
DIM ag AS INTEGER dim ag as integer
DIM ab AS INTEGER dim ab as integer
DIM i AS INTEGER dim i as integer
DIM nearest AS INTEGER dim nearest as integer
DIM shortestdistance AS INTEGER dim shortestdistance as integer
DIM distance AS INTEGER dim distance as integer
r = _RED (colour) r = _red (colour)
g = _GREEN(colour) g = _green(colour)
b = _BLUE (colour) b = _blue (colour)
shortestdistance = 443 shortestdistance = 443
FOR i = 0 TO UBOUND(carr) for i = 0 to ubound(carr)
ar = _RED (carr(i)) ar = _red (carr(i))
ag = _GREEN(carr(i)) ag = _green(carr(i))
ab = _BLUE (carr(i)) ab = _blue (carr(i))
distance = SQR((r - ar) ^ 2 + (g - ag) ^ 2 + (b - ab) ^ 2) distance = sqr((r - ar) ^ 2 + (g - ag) ^ 2 + (b - ab) ^ 2)
IF distance <= shortestdistance THEN shortestdistance = distance: nearest = i if distance <= shortestdistance then shortestdistance = distance: nearest = i
NEXT i next i
closestcolor = carr(nearest) closestcolor = carr(nearest)
END FUNCTION end function
' trimmed str$ ' trimmed str$
function tst$(numb) function tst$(numb)