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)+")"
for y = 0 to _height - 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
else
line (x, y)-(x + 16, y + 16), _rgb32(192), bf
@ -76,7 +76,7 @@ dim oldHeight as integer
oldWidth=_width
oldHeight=_height
do
if CheckResize(_source) = -1 THEN
if CheckResize(_source) = -1 then
diffX = _width - oldWidth
diffY = _height - oldHeight
state.offsetX = state.offsetX + (diffX / 2)
@ -207,7 +207,7 @@ sub redraw
_dest layers(0).ihandle
for y = 0 to _height - 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
else
line (x, y)-(x + 16, y + 16), _rgb32(192), bf
@ -236,9 +236,9 @@ sub redraw
case "polygon"
polygon numarr(),state.fcolor
case "fpolygon"
filledpolygon numarr(),state.fcolor
filledPolygon numarr(),state.fcolor
case "floodfill"
floodfill numarr(0),numarr(1),numarr(2)
FloodFill numarr(0),numarr(1),numarr(2)
case ""
' blank line do nothing
case else
@ -250,48 +250,48 @@ sub redraw
_source 0
end sub
SUB getnums (inputStr$, numArray() AS LONG)
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
sPos = instr(inputStr$, "(")
ePos = instr(inputStr$, ")")
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
' 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$))
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
end if
IF LEN(part$) > 0 THEN
if len(part$) > 0 then
idx = idx + 1
REDIM _PRESERVE numArray(idx) AS LONG
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
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
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
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
dim i, x, y
@ -305,7 +305,7 @@ sub toolbox
' y will only increase every 2 buttons
' 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
state.tool = i + 1
@ -481,20 +481,20 @@ if _mousebutton(1) or _mousebutton(2) then
thickpixel x,y,col
addcommand "pixel ("+tst(x)+","+tst(y)+","+hex$(col)+")"
end if
state.isdrawing=0
state.isDrawing=0
_dest odest
end sub
sub do.line(sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long
dim odest as long
if state.isdrawing then
if state.isDrawing then
osource = _source
odest = _dest
if mouseclicked or rmouseclicked then
_dest layers(1).ihandle
addcommand "line (" + tst(sx) + "," + tst(sy) + "," + tst(ex) + "," + tst(ey) + "," + hex$(col) + ")"
state.isdrawing=0
state.isDrawing=0
else
_dest layers(2).ihandle
end if
@ -507,13 +507,13 @@ end sub
sub do.circle (x as long,y as long,r as long,col as long)
dim osource as long
dim odest as long
if state.isdrawing then
if state.isDrawing then
osource = _source
odest = _dest
if mouseclicked or rmouseclicked then
_dest layers(1).ihandle
addcommand "circle ("+tst(x)+","+tst(y)+","+tst(int(r))+","+hex$(col)+")"
state.isdrawing=0
state.isDrawing=0
else
_dest layers(2).ihandle
end if
@ -526,13 +526,13 @@ end sub
sub do.fcircle (x as long,y as long,r as long,col as long)
dim osource as long
dim odest as long
if state.isdrawing then
if state.isDrawing then
osource = _source
odest = _dest
if mouseclicked or rmouseclicked then
_dest layers(1).ihandle
addcommand "fcircle ("+tst(x)+","+tst(y)+","+tst(int(r))+","+hex$(col)+")"
state.isdrawing=0
state.isDrawing=0
else
_dest layers(2).ihandle
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)
dim osource as long
dim odest as long
if state.isdrawing then
if state.isDrawing then
osource = _source
odest = _dest
if mouseclicked or rmouseclicked then
_dest layers(1).ihandle
addcommand "box ("+tst(sX)+","+tst(sY)+","+tst(eX)+","+tst(eY)+","+hex$(Col)+")"
state.isdrawing=0
addcommand "box ("+tst(sx)+","+tst(sy)+","+tst(ex)+","+tst(ey)+","+hex$(col)+")"
state.isDrawing=0
else
_dest layers(2).ihandle
end if
thickbox sX,sy,eX,eY,Col
thickbox sx,sy,ex,ey,col
_source osource
_dest odest
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)
dim osource as long
dim odest as long
if state.isdrawing then
if state.isDrawing then
osource = _source
odest = _dest
if mouseclicked or rmouseclicked then
_dest layers(1).ihandle
addcommand "fbox ("+tst(sX)+","+tst(sY)+","+tst(eX)+","+tst(eY)+","+hex$(Col)+")"
state.isdrawing=0
addcommand "fbox ("+tst(sx)+","+tst(sy)+","+tst(ex)+","+tst(ey)+","+hex$(col)+")"
state.isDrawing=0
else
_dest layers(2).ihandle
end if
filledbox sX,sy,eX,eY,Col
filledbox sx,sy,ex,ey,col
_source osource
_dest odest
end if
@ -591,7 +591,7 @@ dim p as integer
dim i as integer
dim tmpstr as string
if state.isdrawing then
if state.isDrawing then
osource = _source
odest = _dest
@ -619,7 +619,7 @@ if state.isdrawing then
addcommand tmpstr
' Clean up local tool state
state.isdrawing = 0
state.isDrawing = 0
pointCount = 0
else
' Live preview rendering loop
@ -648,7 +648,7 @@ dim p as integer
dim i as integer
dim tmpstr as string
if state.isdrawing then
if state.isDrawing then
osource = _source
odest = _dest
@ -666,7 +666,7 @@ if state.isdrawing then
redim finalP(pointCount * 2 - 1) as long
for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next
filledpolygon finalP(), state.fcolor
filledPolygon finalP(), state.fcolor
tmpstr = "fpolygon ("
for i = 0 to ubound(finalP) - 1
@ -676,7 +676,7 @@ if state.isdrawing then
addcommand tmpstr
' Clean up local tool state
state.isdrawing = 0
state.isDrawing = 0
pointCount = 0
else
' Live preview rendering loop
@ -702,7 +702,7 @@ odest = _dest
if mouseclicked or rmouseclicked then
_source layers(1).ihandle
_dest layers(1).ihandle
floodfill x,y,col
FloodFill x,y,col
addcommand "floodfill ("+tst(x)+","+tst(y)+","+hex$(col)+")"
_source osource
_dest odest
@ -822,28 +822,28 @@ function __internaluiicon&(index as long,imagehandle as long,mode as integer)
end function
FUNCTION CheckResize (CurrentScreen AS _UNSIGNED LONG) 'pulled straight out of the wiki'
DIM TempScreen AS _UNSIGNED LONG
function CheckResize (CurrentScreen as _unsigned long) 'pulled straight out of the wiki'
dim TempScreen as _unsigned long
CheckResize = 0
IF _RESIZE THEN
TempScreen = _COPYIMAGE(CurrentScreen, 32)
SCREEN TempScreen
_FREEIMAGE CurrentScreen
CurrentScreen = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
SCREEN CurrentScreen
_PUTIMAGE (0, 0), TempScreen, CurrentScreen
_DISPLAY
_FREEIMAGE TempScreen
if _resize then
TempScreen = _copyimage(CurrentScreen, 32)
screen TempScreen
_freeimage CurrentScreen
CurrentScreen = _newimage(_resizewidth, _resizeheight, 32)
screen CurrentScreen
_putimage (0, 0), TempScreen, CurrentScreen
_display
_freeimage TempScreen
CheckResize = -1
END IF
END FUNCTION
end if
end function
sub menu()
dim logo as long
dim filename as string
' A logo is needed'
'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
dim i as integer
dim fh as integer
@ -891,7 +891,7 @@ save32bitPNG layers(1).ihandle, filename
case ".bmp"
save24bitBmp layers(1).ihandle, filename
case ".ppm"
savebinaryPPM layers(1).ihandle, filename
SaveBinaryPPM layers(1).ihandle, filename
case else
save32bitPNG layers(1).ihandle, filename
end select
@ -921,30 +921,30 @@ sub palettemanager(col as _unsigned long)
'TODO: build palette mamager ui
end sub
FUNCTION closestcolor~& (colour AS _UNSIGNED LONG, carr() AS _UNSIGNED LONG)
DIM r AS INTEGER
DIM g AS INTEGER
DIM b AS INTEGER
DIM ar AS INTEGER
DIM ag AS INTEGER
DIM ab AS INTEGER
DIM i AS INTEGER
DIM nearest AS INTEGER
DIM shortestdistance AS INTEGER
DIM distance AS INTEGER
r = _RED (colour)
g = _GREEN(colour)
b = _BLUE (colour)
function closestcolor~& (colour as _unsigned long, carr() as _unsigned long)
dim r as integer
dim g as integer
dim b as integer
dim ar as integer
dim ag as integer
dim ab as integer
dim i as integer
dim nearest as integer
dim shortestdistance as integer
dim distance as integer
r = _red (colour)
g = _green(colour)
b = _blue (colour)
shortestdistance = 443
FOR i = 0 TO UBOUND(carr)
ar = _RED (carr(i))
ag = _GREEN(carr(i))
ab = _BLUE (carr(i))
distance = SQR((r - ar) ^ 2 + (g - ag) ^ 2 + (b - ab) ^ 2)
IF distance <= shortestdistance THEN shortestdistance = distance: nearest = i
NEXT i
for i = 0 to ubound(carr)
ar = _red (carr(i))
ag = _green(carr(i))
ab = _blue (carr(i))
distance = sqr((r - ar) ^ 2 + (g - ag) ^ 2 + (b - ab) ^ 2)
if distance <= shortestdistance then shortestdistance = distance: nearest = i
next i
closestcolor = carr(nearest)
END FUNCTION
end function
' trimmed str$
function tst$(numb)