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
@ -481,20 +481,20 @@ 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
@ -507,13 +507,13 @@ 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
@ -526,13 +526,13 @@ 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
@ -545,17 +545,17 @@ 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
@ -564,17 +564,17 @@ 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
@ -591,7 +591,7 @@ 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
@ -648,7 +648,7 @@ 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
@ -702,7 +702,7 @@ 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
@ -822,28 +822,28 @@ 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
@ -891,7 +891,7 @@ 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
@ -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)