From 7aacca5803790b463b3b8364dbfd1d7f4edf2143 Mon Sep 17 00:00:00 2001 From: visionmercer <62051836+visionmercer@users.noreply.github.com> Date: Tue, 19 May 2026 12:23:01 +0200 Subject: [PATCH] indenting and case lowering --- pixler.bas | 880 ++++++++++++++++++++++++++--------------------------- 1 file changed, 440 insertions(+), 440 deletions(-) diff --git a/pixler.bas b/pixler.bas index 15cac2d..4d63c1d 100644 --- a/pixler.bas +++ b/pixler.bas @@ -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) @@ -109,52 +109,52 @@ do lastMX = _mousex: lastMY = _mousey ' Zooming - if mw <> 0 then - ' 1. Capture current world position - mouseWorldX = (_mousex - state.offsetX) / state.zoom - mouseWorldY = (_mousey - state.offsetY) / state.zoom + if mw <> 0 then + ' 1. Capture current world position + mouseWorldX = (_mousex - state.offsetX) / state.zoom + mouseWorldY = (_mousey - state.offsetY) / state.zoom - ' 2. Calculate the new zoom level (Snap to whole numbers) - if mw > 0 then - state.zoom = state.zoom + 1 - else - state.zoom = state.zoom - 1 - end if - - ' 3. Constrain zoom (Min 1, Max 20) - if state.zoom < 1 then state.zoom = 1 - if state.zoom > 20 then state.zoom = 20 - - ' 4. Adjust offsets - state.offsetX = _mousex - (mouseWorldX * state.zoom) - state.offsetY = _mousey - (mouseWorldY * state.zoom) - - mw = 0 + ' 2. Calculate the new zoom level (Snap to whole numbers) + if mw > 0 then + state.zoom = state.zoom + 1 + else + state.zoom = state.zoom - 1 end if + ' 3. Constrain zoom (Min 1, Max 20) + if state.zoom < 1 then state.zoom = 1 + if state.zoom > 20 then state.zoom = 20 + + ' 4. Adjust offsets + state.offsetX = _mousex - (mouseWorldX * state.zoom) + state.offsetY = _mousey - (mouseWorldY * state.zoom) + + mw = 0 + end if + ' Keyboarding keyin=inkey$ select case keyin - case "+" - state.brushsize=state.brushsize+1 - addcommand "brushsize ("+tst(state.brushsize)+")" - case "-" - if state.brushsize>1 then state.brushsize=state.brushsize-1 - addcommand "brushsize ("+tst(state.brushsize)+")" - case chr$(19) ' ctrl+s - 'TODO: save logic - case chr$(27)' esc - menu - case "h" - state.zoom=1.0 - state.offsetX=(_width/2)- (_width(layers(0).ihandle)/2) - state.offsetY=(_height/2)- (_height(layers(0).ihandle)/2) - case "t" - showtoolbox=not showtoolbox - case "c" - showcolorpicker=not showcolorpicker - case "l" - showcommands=not showcommands + case "+" + state.brushsize=state.brushsize+1 + addcommand "brushsize ("+tst(state.brushsize)+")" + case "-" + if state.brushsize>1 then state.brushsize=state.brushsize-1 + addcommand "brushsize ("+tst(state.brushsize)+")" + case chr$(19) ' ctrl+s + 'TODO: save logic + case chr$(27)' esc + menu + case "h" + state.zoom=1.0 + state.offsetX=(_width/2)- (_width(layers(0).ihandle)/2) + state.offsetY=(_height/2)- (_height(layers(0).ihandle)/2) + case "t" + showtoolbox=not showtoolbox + case "c" + showcolorpicker=not showcolorpicker + case "l" + showcommands=not showcommands end select _limit 30 @@ -178,7 +178,7 @@ sub commandlist if y < _height - 20 then '_printstring (x + 5, y + 5), left$(commands(i), 31) if link(x + 5, y + 5, left$(commands(i), 31)) then - commands(i)=textinput(x + 5, y + 5,248,23, commands(i)) + commands(i)=textinput(x + 5, y + 5,248,23, commands(i)) end if end if next i @@ -199,99 +199,99 @@ sub redraw getnums commands(i),numarr() _dest layers(1).ihandle select case lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1))) - case "canvas" - for j=0 to 3 - if layers(j).ihandle <> 0 then _freeimage layers(j).ihandle - layers(j).ihandle = _newimage(numarr(0),numarr(1),32) - next j - _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 - line (x, y)-(x + 16, y + 16), _rgb32(127), bf - else - line (x, y)-(x + 16, y + 16), _rgb32(192), bf - end if + case "canvas" + for j=0 to 3 + if layers(j).ihandle <> 0 then _freeimage layers(j).ihandle + layers(j).ihandle = _newimage(numarr(0),numarr(1),32) + next j + _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 + line (x, y)-(x + 16, y + 16), _rgb32(127), bf + else + line (x, y)-(x + 16, y + 16), _rgb32(192), bf + end if + next next - next - - case "fcolor" - state.fcolor=numarr(0) - case "bcolor" - state.bcolor=numarr(0) - case "brushsize" - state.brushsize=numarr(0) - case "pixel" - thickpixel numarr(0),numarr(1),numarr(2) - case "line" - thickline numarr(0),numarr(1),numarr(2),numarr(3),numarr(4) - case "box" - thickbox numarr(0),numarr(1),numarr(2),numarr(3),numarr(4) - case "fbox" - filledbox numarr(0),numarr(1),numarr(2),numarr(3),numarr(4) - case "circle" - thickcircle numarr(0),numarr(1),numarr(2),numarr(3) - case "fcircle" - filledcircle numarr(0),numarr(1),numarr(2),numarr(3) - case "polygon" - polygon numarr(),state.fcolor - case "fpolygon" - filledpolygon numarr(),state.fcolor - case "floodfill" - floodfill numarr(0),numarr(1),numarr(2) - case "" - ' blank line do nothing - case else - 'debug info - print "'"+lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1)))+"'" + + case "fcolor" + state.fcolor=numarr(0) + case "bcolor" + state.bcolor=numarr(0) + case "brushsize" + state.brushsize=numarr(0) + case "pixel" + thickpixel numarr(0),numarr(1),numarr(2) + case "line" + thickline numarr(0),numarr(1),numarr(2),numarr(3),numarr(4) + case "box" + thickbox numarr(0),numarr(1),numarr(2),numarr(3),numarr(4) + case "fbox" + filledbox numarr(0),numarr(1),numarr(2),numarr(3),numarr(4) + case "circle" + thickcircle numarr(0),numarr(1),numarr(2),numarr(3) + case "fcircle" + filledcircle numarr(0),numarr(1),numarr(2),numarr(3) + case "polygon" + polygon numarr(),state.fcolor + case "fpolygon" + filledPolygon numarr(),state.fcolor + case "floodfill" + FloodFill numarr(0),numarr(1),numarr(2) + case "" + ' blank line do nothing + case else + 'debug info + print "'"+lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1)))+"'" end select next i _dest 0 _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 - - content$ = MID$(inputStr$, sPos + 1, ePos - sPos - 1) + 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$)) + 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 @@ -385,10 +385,10 @@ sub canvas dim fullScaledH as single: fullScaledH = imgH * state.zoom ' Calculate visible area in screen coordinates (Overlap of image and viewport) - drawX1 = state.offsetX - drawY1 = state.offsetY - drawX2 = state.offsetX + fullScaledW - 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 @@ -399,10 +399,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 - 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) + 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) @@ -410,7 +410,7 @@ sub canvas next _dest layers(2).ihandle: cls , 0: _dest 0 ' 2.5 if the mouse is in ui thats all we need - if showtoolbox then + if showtoolbox then if _mousex >= 0 and _mousex <= 70 then exit sub end if @@ -472,249 +472,249 @@ sub canvas end sub sub do.pencil(x as long,y as long, col as long) -dim osource as long -dim odest as long -osource = _source -odest = _dest -_dest layers(1).ihandle -if _mousebutton(1) or _mousebutton(2) then - thickpixel x,y,col - addcommand "pixel ("+tst(x)+","+tst(y)+","+hex$(col)+")" -end if -state.isdrawing=0 -_dest odest + dim osource as long + dim odest as long + osource = _source + odest = _dest + _dest layers(1).ihandle + if _mousebutton(1) or _mousebutton(2) then + thickpixel x,y,col + addcommand "pixel ("+tst(x)+","+tst(y)+","+hex$(col)+")" + end if + 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 -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 -else -_dest layers(2).ihandle -end if -thickline sx, sy, ex, ey, col -_source osource -_dest odest -end if + dim osource as long + dim odest as long + 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 + else + _dest layers(2).ihandle + end if + thickline sx, sy, ex, ey, col + _source osource + _dest odest + end if 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 -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 -else -_dest layers(2).ihandle -end if -thickcircle x, y, r, col -_source osource -_dest odest -end if + dim osource as long + dim odest as long + 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 + else + _dest layers(2).ihandle + end if + thickcircle x, y, r, col + _source osource + _dest odest + end if 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 -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 -else -_dest layers(2).ihandle -end if -filledcircle x, y, r, col -_source osource -_dest odest -end if + dim osource as long + dim odest as long + 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 + else + _dest layers(2).ihandle + end if + filledcircle x, y, r, col + _source osource + _dest odest + end if 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 -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 -else -_dest layers(2).ihandle -end if -thickbox sX,sy,eX,eY,Col -_source osource -_dest odest -end if + dim osource as long + dim odest as long + 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 + else + _dest layers(2).ihandle + end if + thickbox sx,sy,ex,ey,col + _source osource + _dest odest + end if 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 -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 -else -_dest layers(2).ihandle -end if -filledbox sX,sy,eX,eY,Col -_source osource -_dest odest -end if + dim osource as long + dim odest as long + 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 + else + _dest layers(2).ihandle + end if + filledbox sx,sy,ex,ey,col + _source osource + _dest odest + end if end sub sub do.polygon(x as long, y as long) -' 1. Internalized State Memory -static polypoints(500) as long -static pointCount as integer + ' 1. Internalized State Memory + static polypoints(500) as long + static pointCount as integer -dim osource as long -dim odest as long -dim p as integer -dim i as integer -dim tmpstr as string + dim osource as long + dim odest as long + dim p as integer + dim i as integer + dim tmpstr as string -if state.isdrawing then - osource = _source - odest = _dest - - ' If left-clicked, add the coordinate to this routine's local array - if mouseclicked then - polypoints(pointCount * 2) = x - polypoints(pointCount * 2 + 1) = y - pointCount = pointCount + 1 - end if - - ' Finish shape on Right-Click - if rmouseclicked and pointCount > 2 then - _dest layers(1).ihandle - - redim finalP(pointCount * 2 - 1) as long - for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next - - polygon finalP(), state.fcolor - - tmpstr = "polygon (" - for i = 0 to ubound(finalP) - 1 - tmpstr = tmpstr + tst(finalP(i)) + "," - next i - tmpstr = tmpstr + tst(finalP(i)) + ")" - addcommand tmpstr - - ' Clean up local tool state - state.isdrawing = 0 - pointCount = 0 - else - ' Live preview rendering loop - _dest layers(2).ihandle - if pointCount > 0 then - for p = 1 to pointCount - 1 - thickline polypoints((p - 1) * 2), polypoints((p - 1) * 2 + 1), polypoints(p * 2), polypoints(p * 2 + 1), state.fcolor - next p - thickline polypoints((pointCount - 1) * 2), polypoints((pointCount - 1) * 2 + 1), x, y, state.fcolor + if state.isDrawing then + osource = _source + odest = _dest + + ' If left-clicked, add the coordinate to this routine's local array + if mouseclicked then + polypoints(pointCount * 2) = x + polypoints(pointCount * 2 + 1) = y + pointCount = pointCount + 1 end if + + ' Finish shape on Right-Click + if rmouseclicked and pointCount > 2 then + _dest layers(1).ihandle + + redim finalP(pointCount * 2 - 1) as long + for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next + + polygon finalP(), state.fcolor + + tmpstr = "polygon (" + for i = 0 to ubound(finalP) - 1 + tmpstr = tmpstr + tst(finalP(i)) + "," + next i + tmpstr = tmpstr + tst(finalP(i)) + ")" + addcommand tmpstr + + ' Clean up local tool state + state.isDrawing = 0 + pointCount = 0 + else + ' Live preview rendering loop + _dest layers(2).ihandle + if pointCount > 0 then + for p = 1 to pointCount - 1 + thickline polypoints((p - 1) * 2), polypoints((p - 1) * 2 + 1), polypoints(p * 2), polypoints(p * 2 + 1), state.fcolor + next p + thickline polypoints((pointCount - 1) * 2), polypoints((pointCount - 1) * 2 + 1), x, y, state.fcolor + end if + end if + + _source osource + _dest odest end if - - _source osource - _dest odest -end if end sub sub do.fpolygon(x as long, y as long) -' 1. Internalized State Memory -static polypoints(500) as long -static pointCount as integer + ' 1. Internalized State Memory + static polypoints(500) as long + static pointCount as integer -dim osource as long -dim odest as long -dim p as integer -dim i as integer -dim tmpstr as string + dim osource as long + dim odest as long + dim p as integer + dim i as integer + dim tmpstr as string -if state.isdrawing then - osource = _source - odest = _dest - - ' If left-clicked, add the coordinate to this routine's local array - if mouseclicked then - polypoints(pointCount * 2) = x - polypoints(pointCount * 2 + 1) = y - pointCount = pointCount + 1 - end if - - ' Finish shape on Right-Click - if rmouseclicked and pointCount > 2 then - _dest layers(1).ihandle - - redim finalP(pointCount * 2 - 1) as long - for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next - - filledpolygon finalP(), state.fcolor - - tmpstr = "fpolygon (" - for i = 0 to ubound(finalP) - 1 - tmpstr = tmpstr + tst(finalP(i)) + "," - next i - tmpstr = tmpstr + tst(finalP(i)) + ")" - addcommand tmpstr - - ' Clean up local tool state - state.isdrawing = 0 - pointCount = 0 - else - ' Live preview rendering loop - _dest layers(2).ihandle - if pointCount > 0 then - for p = 1 to pointCount - 1 - thickline polypoints((p - 1) * 2), polypoints((p - 1) * 2 + 1), polypoints(p * 2), polypoints(p * 2 + 1), state.fcolor - next p - thickline polypoints((pointCount - 1) * 2), polypoints((pointCount - 1) * 2 + 1), x, y, state.fcolor + if state.isDrawing then + osource = _source + odest = _dest + + ' If left-clicked, add the coordinate to this routine's local array + if mouseclicked then + polypoints(pointCount * 2) = x + polypoints(pointCount * 2 + 1) = y + pointCount = pointCount + 1 end if + + ' Finish shape on Right-Click + if rmouseclicked and pointCount > 2 then + _dest layers(1).ihandle + + redim finalP(pointCount * 2 - 1) as long + for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next + + filledPolygon finalP(), state.fcolor + + tmpstr = "fpolygon (" + for i = 0 to ubound(finalP) - 1 + tmpstr = tmpstr + tst(finalP(i)) + "," + next i + tmpstr = tmpstr + tst(finalP(i)) + ")" + addcommand tmpstr + + ' Clean up local tool state + state.isDrawing = 0 + pointCount = 0 + else + ' Live preview rendering loop + _dest layers(2).ihandle + if pointCount > 0 then + for p = 1 to pointCount - 1 + thickline polypoints((p - 1) * 2), polypoints((p - 1) * 2 + 1), polypoints(p * 2), polypoints(p * 2 + 1), state.fcolor + next p + thickline polypoints((pointCount - 1) * 2), polypoints((pointCount - 1) * 2 + 1), x, y, state.fcolor + end if + end if + + _source osource + _dest odest end if - - _source osource - _dest odest -end if end sub sub do.floodfill(x as long,y as long, col as long) -dim osource as long -dim odest as long -osource = _source -odest = _dest -if mouseclicked or rmouseclicked then -_source layers(1).ihandle -_dest layers(1).ihandle -floodfill x,y,col -addcommand "floodfill ("+tst(x)+","+tst(y)+","+hex$(col)+")" -_source osource -_dest odest -end if + dim osource as long + dim odest as long + osource = _source + odest = _dest + if mouseclicked or rmouseclicked then + _source layers(1).ihandle + _dest layers(1).ihandle + FloodFill x,y,col + addcommand "floodfill ("+tst(x)+","+tst(y)+","+hex$(col)+")" + _source osource + _dest odest + end if end sub sub do.eyedropper(x,y) -dim osource as long -dim odest as long -osource = _source -odest = _dest -_source layers(1).ihandle + dim osource as long + dim odest as long + osource = _source + odest = _dest + _source layers(1).ihandle end sub @@ -822,98 +822,98 @@ 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 -'_putimage ((_width(0)-_width(logo))/2,10),logo -dim i as integer -dim fh as integer -do until done -k$=inkey$ -while _mouseinput:wend -mouseclicked=mbd and not _mousebutton(1) -mbd=_mousebutton(1) + 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 + '_putimage ((_width(0)-_width(logo))/2,10),logo + dim i as integer + dim fh as integer + do until done + k$=inkey$ + while _mouseinput:wend + mouseclicked=mbd and not _mousebutton(1) + mbd=_mousebutton(1) -if link(10,10,"open") then -filename=textinput(10,10,100,23,"") -if filename="" then exit sub -fh = freefile -redim commands(2000) as string -open filename for input as fh -do until eof(fh) -line input #fh, commands(i) -i=i+1 -if i>ubound(commands) then redim _preserve commands(ubound(commands)*2) as string -loop -close fh -redim _preserve commands(i-1) as string -redraw -done=-1 -end if + if link(10,10,"open") then + filename=textinput(10,10,100,23,"") + if filename="" then exit sub + fh = freefile + redim commands(2000) as string + open filename for input as fh + do until eof(fh) + line input #fh, commands(i) + i=i+1 + if i>ubound(commands) then redim _preserve commands(ubound(commands)*2) as string + loop + close fh + redim _preserve commands(i-1) as string + redraw + done=-1 + end if -if link(10,34,"save") then -filename=textinput(1,34,100,23,"") -if filename="" then exit sub -fh = freefile -open filename for output as fh -for i=0 to ubound(commands) -print #fh, commands(i) -next i -close fh -done=-1 -end if + if link(10,34,"save") then + filename=textinput(1,34,100,23,"") + if filename="" then exit sub + fh = freefile + open filename for output as fh + for i=0 to ubound(commands) + print #fh, commands(i) + next i + close fh + done=-1 + end if -if link(10,56,"export") then -filename=textinput(10,56,100,23,"") -if filename="" then exit sub -select case lcase$(right$(filename,4)) -case ".png" -save32bitPNG layers(1).ihandle, filename -case ".bmp" -save24bitBmp layers(1).ihandle, filename -case ".ppm" -savebinaryPPM layers(1).ihandle, filename -case else -save32bitPNG layers(1).ihandle, filename -end select -done=-1 -end if + if link(10,56,"export") then + filename=textinput(10,56,100,23,"") + if filename="" then exit sub + select case lcase$(right$(filename,4)) + case ".png" + save32bitPNG layers(1).ihandle, filename + case ".bmp" + save24bitBmp layers(1).ihandle, filename + case ".ppm" + SaveBinaryPPM layers(1).ihandle, filename + case else + save32bitPNG layers(1).ihandle, filename + end select + done=-1 + end if -if link(10,78,"refenece img") then -filename=textinput(10,78,100,23,"") -if filename="" then exit sub -if not _fileexists(filename) then exit sub -if layers(3).ihandle <> 0 then _freeimage layers(3).ihandle -layers(3).ihandle=_loadimage(filename) -_setalpha 20, layers(3).ihandle -done=-1 -end if + if link(10,78,"refenece img") then + filename=textinput(10,78,100,23,"") + if filename="" then exit sub + if not _fileexists(filename) then exit sub + if layers(3).ihandle <> 0 then _freeimage layers(3).ihandle + layers(3).ihandle=_loadimage(filename) + _setalpha 20, layers(3).ihandle + done=-1 + end if -if link(10,100,"exit") then system + if link(10,100,"exit") then system -if k$=chr$(27) then done=-1 -_limit 30 -_display -loop + if k$=chr$(27) then done=-1 + _limit 30 + _display + loop end sub sub palettemanager(col as _unsigned long) @@ -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)