diff --git a/include/tools.bm b/include/tools.bm index cc937e3..501da0e 100644 --- a/include/tools.bm +++ b/include/tools.bm @@ -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) dim i as integer, j as integer @@ -158,7 +167,8 @@ end sub ' For large images, you may need to increase this size DIM stackX(2000) AS INTEGER DIM stackY(2000) AS INTEGER - targetColor~&=point(startX,startY) + targetColor~&=point(startX,startY) + if targetColor~&=fillColor~& then exit sub stackPtr = 1 stackX(stackPtr) = startX diff --git a/pixler.bas b/pixler.bas index 51d51fc..c299b0c 100644 --- a/pixler.bas +++ b/pixler.bas @@ -187,26 +187,93 @@ end sub sub redraw 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) + getnums commands(i),numarr() + _dest layers(1).ihandle select case lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1))) case "canvas" 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" - case "brushwidth" + 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) + ' 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 dim i, x, y dim btnSize : btnSize = 32 @@ -420,12 +487,10 @@ sub canvas r = sqr((canX - state.startX)^2 + (canY - state.startY)^2) filledcircle state.startX, state.startY, r, drawCol case 5 ' Rect - thickline state.startX, state.startY, canX, state.startY, drawCol - thickline canX, state.startY, canX, canY, drawCol - thickline canX, canY, state.startX, canY, drawCol - thickline state.startX, canY, state.startX, state.startY, drawCol + thickbox state.startX,state.starty,canX,canY,drawCol + 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 if pointCount > 0 then for p = 1 to pointCount - 1 @@ -485,10 +550,12 @@ sub canvas filledcircle state.startX, state.startY, r + 1, drawCol addcommand "fcircle ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")" 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)+")" 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)+")" end select end if