Less spaces in command history.

smaller save file size.
This commit is contained in:
visionmercer 2026-05-12 09:29:36 +02:00
commit 4bae8cde8f
2 changed files with 40 additions and 36 deletions

View file

@ -20,7 +20,7 @@ Sub SaveBinaryPPM (imageHandle As Long, fileName As String)
length = inPosition + w * h * 4 length = inPosition + w * h * 4
head = "P6" + Chr$(10) head = "P6" + Chr$(10)
head = head + "# Created with QB64" + Chr$(10) head = head + "# Created with QB64" + Chr$(10)
head = head + LTrim$(Str$(w) + Str$(h)) + Chr$(10) head = head + LTrim$(str$(w) + tst(h)) + Chr$(10)
head = head + "255" + Chr$(10) head = head + "255" + Chr$(10)
filebuffer = _MemNew(w * h * 3) filebuffer = _MemNew(w * h * 3)
outPosition = filebuffer.OFFSET outPosition = filebuffer.OFFSET

View file

@ -43,7 +43,7 @@ layers(2).ihandle=_newimage(320,320,32)
layers(3).ihandle=_newimage(320,320,32) layers(3).ihandle=_newimage(320,320,32)
_dest layers(0).ihandle _dest layers(0).ihandle
addcommand "canvas ("+str$(_width)+","+str$(_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
@ -137,10 +137,10 @@ canvas
select case keyin select case keyin
case "+" case "+"
state.brushsize=state.brushsize+1 state.brushsize=state.brushsize+1
addcommand "brushsize ("+str$(state.brushsize)+")" addcommand "brushsize ("+tst(state.brushsize)+")"
case "-" case "-"
if state.brushsize>1 then state.brushsize=state.brushsize-1 if state.brushsize>1 then state.brushsize=state.brushsize-1
addcommand "brushsize ("+str$(state.brushsize)+")" addcommand "brushsize ("+tst(state.brushsize)+")"
case chr$(19) ' ctrl+s case chr$(19) ' ctrl+s
'TODO: save logic 'TODO: save logic
case chr$(27)' esc case chr$(27)' esc
@ -213,12 +213,6 @@ sub toolbox
end if end if
end sub end sub
sub palettemanager(col as _unsigned long)
line (0,0)-(_width-1,_height-1),col,bf
_display
sleep
end sub
sub colorpicker sub colorpicker
dim img as long dim img as long
img=_newimage(16,16,32) img=_newimage(16,16,32)
@ -343,10 +337,10 @@ sub canvas
_source layers(1).ihandle _source layers(1).ihandle
if mouseclicked then if mouseclicked then
floodfill canX,canY,state.fcolor floodfill canX,canY,state.fcolor
addcommand "floodfill ("+str$(canX)+","+str$(canY)+","+hex$(state.fcolor)+")" addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.fcolor)+")"
else else
floodfill canX,canY,state.bcolor floodfill canX,canY,state.bcolor
addcommand "floodfill ("+str$(canX)+","+str$(canY)+","+hex$(state.bcolor)+")" addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.bcolor)+")"
end if end if
_dest 0 _dest 0
_source 0 _source 0
@ -392,10 +386,10 @@ sub canvas
_dest layers(1).ihandle _dest layers(1).ihandle
if canX=state.startX and canY=state.startY then if canX=state.startX and canY=state.startY then
thickpixel canX,canY,drawCol thickpixel canX,canY,drawCol
addcommand "pixel ("+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
else else
thickline state.startX, state.startY, canX, canY, drawCol thickline state.startX, state.startY, canX, canY, drawCol
addcommand "line ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end if end if
state.startX = canX: state.startY = canY state.startX = canX: state.startY = canY
case 2 ' Straight Line case 2 ' Straight Line
@ -440,17 +434,17 @@ sub canvas
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
tmpstr=tmpstr+str$(finalP(i))+"," tmpstr=tmpstr+tst(finalP(i))+","
next i next i
tmpstr=tmpstr+str$(finalP(i))+","+hex$(state.fcolor)+")" tmpstr=tmpstr+tst(finalP(i))+","+hex$(state.fcolor)+")"
addcommand tmpstr addcommand tmpstr
else else
Polygon finalP(), state.fcolor Polygon finalP(), state.fcolor
tmpstr="polygon (" tmpstr="polygon ("
for i=0 to ubound(finalP)-1 for i=0 to ubound(finalP)-1
tmpstr=tmpstr+str$(finalP(i))+"," tmpstr=tmpstr+tst(finalP(i))+","
next i next i
tmpstr=tmpstr+str$(finalP(i))+","+hex$(state.fcolor)+")" tmpstr=tmpstr+tst(finalP(i))+","+hex$(state.fcolor)+")"
addcommand tmpstr addcommand tmpstr
end if end if
else else
@ -460,25 +454,25 @@ sub canvas
case 2 ' Line case 2 ' Line
if canX=state.startX and canY=state.startY then if canX=state.startX and canY=state.startY then
thickpixel canX,canY,drawCol thickpixel canX,canY,drawCol
addcommand "pixel ("+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
else else
thickline state.startX, state.startY, canX, canY, drawCol thickline state.startX, state.startY, canX, canY, drawCol
addcommand "line ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end if end if
case 3 ' Circle case 3 ' Circle
r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2)) r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2))
thickcircle state.startX, state.startY, r + 1, drawCol thickcircle state.startX, state.startY, r + 1, drawCol
addcommand "circle ("+str$(state.startX)+","+str$(state.startY)+","+str$(int(r))+","+hex$(drawCol)+")" addcommand "circle ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")"
case 4 case 4
r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2)) r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2))
filledcircle state.startX, state.startY, r + 1, drawCol filledcircle state.startX, state.startY, r + 1, drawCol
addcommand "fcircle ("+str$(state.startX)+","+str$(state.startY)+","+str$(int(r))+","+hex$(drawCol)+")" addcommand "fcircle ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")"
case 5 ' Box case 5 ' Box
line (state.startX, state.startY)-(canX, canY), drawCol, b line (state.startX, state.startY)-(canX, canY), drawCol, b
addcommand "box ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" addcommand "box ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
case 6 ' Filled Box case 6 ' Filled Box
line (state.startX, state.startY)-(canX, canY), drawCol, bf line (state.startX, state.startY)-(canX, canY), drawCol, bf
addcommand "fbox ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" addcommand "fbox ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end select end select
end if end if
@ -631,6 +625,11 @@ _display
loop loop
end sub end sub
sub palettemanager(col as _unsigned long)
line (0,0)-(_width-1,_height-1),col,bf
'TODO: build palette mamager ui
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
@ -655,3 +654,8 @@ FUNCTION closestcolor~& (colour AS _UNSIGNED LONG, carr() AS _UNSIGNED LONG)
NEXT i NEXT i
closestcolor = carr(nearest) closestcolor = carr(nearest)
END FUNCTION END FUNCTION
' trimmed str$
function tst$(numb)
tst=_trim$(str$(numb))
end function