command history

This commit is contained in:
visionmercer 2026-05-06 13:28:56 +02:00
commit b686bb6633

View file

@ -20,9 +20,10 @@ end type
redim shared layers(3) as layertype
dim shared state as statetype
redim shared commands(0) as string
dim shared showtoolbox as _byte: showtoolbox=-1
dim shared showcolorpicker as _byte: showcolorpicker=-1
dim shared showcommands as _byte: showcommands=0
dim shared mouseclicked as integer
dim shared mousedown as integer
@ -132,16 +133,36 @@ do
showtoolbox=not showtoolbox
case "c"
showcolorpicker=not showcolorpicker
case "l"
showcommands=not showcommands
end select
canvas
if showtoolbox then toolbox
if showcolorpicker then colorpicker
if showcommands then commandlist
_limit 30
_display
loop
sub commandlist
dim i as long
dim listWidth as integer: listWidth = 150
dim x as integer: x = _width - listWidth
' Draw background for the list
line (x, 0)-(_width - 1, _height - 1), _rgb32(40, 40, 40), bf
line (x, 0)-(x, _height - 1), _rgb32(100, 100, 100)
_printmode _keepbackground
for i = 0 to ubound(commands) - 1
dim y as integer: y = i * 16
if y < _height - 20 then
_printstring (x + 5, y + 5), left$(commands(i), 18)
end if
next i
end sub
sub toolbox
dim i, x, y
dim btnSize : btnSize = 32
@ -173,20 +194,31 @@ sub colorpicker
select case imagebutton(i*16,_height-17,16,16,img)
case -1
state.fcolor=pal(i)
addcommand "fcolor ("+hex$(pal(i))+")"
case -2
state.bcolor=pal(i)
addcommand "bcolor ("+hex$(pal(i))+")"
end select
next i
_freeimage img
end sub
sub canvas
sub addcommand(cmd as string)
'this check is probably more clever than good is.
if commands(ubound(commands)+(ubound(commands)>0))<>cmd then
commands(ubound(commands))=cmd
redim _preserve commands(ubound(commands)+1) as string
end if
end sub
sub canvas
' 1. Define the Viewport (The "Window" on your screen)
dim viewX1 as integer
if showtoolbox then viewX1 = 70 else viewX1 = 0
dim viewY1 as integer: viewY1 = 0
dim viewX2 as integer: viewX2 = _width - 1
dim viewX2 as integer
if showcommands then viewX2 = _width - 151 else viewX2 = _width - 1
dim viewY2 as integer
if showcolorpicker then viewY2 = _height - 20 else viewY2 = _height - 1
@ -248,11 +280,19 @@ sub canvas
exit sub
end if
end if
if showcommands then
if _mousex >= drawX2 then
exit sub
end if
end if
dim r as integer
' 3. Calculate Canvas Coordinates
dim canX as integer: canX = int((_mousex - state.offsetX) / state.zoom)
dim canY as integer: canY = int((_mousey - state.offsetY) / state.zoom)
dim canX as integer
dim canY as integer
canX = int((_mousex - state.offsetX) / state.zoom)
canY = int((_mousey - state.offsetY) / state.zoom)
static polypoints(200) as single
static pointCount as integer
@ -269,8 +309,10 @@ sub canvas
_source layers(1).ihandle
if mouseclicked then
floodfill canX,canY,state.fcolor
addcommand "floodfill ("+str$(canX)+","+str$(canY)+","+hex$(state.fcolor)+")"
else
floodfill canX,canY,state.bcolor
addcommand "floodfill ("+str$(canX)+","+str$(canY)+","+hex$(state.bcolor)+")"
end if
_dest 0
_source 0
@ -282,8 +324,10 @@ sub canvas
_source layers(1).ihandle
if mouseclicked then
state.fcolor=point(canX,canY)
addcommand "fcolor ("+hex$(point(canX,canY))+")"
else
state.bcolor=point(canX,canY)
addcommand "bcolor ("+hex$(point(canX,cany))+")"
end if
_dest 0
_source 0
@ -314,15 +358,16 @@ sub canvas
case 1 ' Pencil
_dest layers(1).ihandle
thickline state.startX, state.startY, canX, canY, drawCol
addcommand "line ("+str$(state.startX)+","+ str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")"
state.startX = canX: state.startY = canY
case 2 ' Straight Line
thickline state.startX, state.startY, canX, canY, drawCol
case 3 ' Circle
dim r as single: r = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
r = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
thickcircle state.startX, state.startY, r + 1, drawCol
case 4 ' Filled Circle
dim r_f as single: r_f = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
filledcircle state.startX, state.startY, r_f, drawCol
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
@ -352,10 +397,46 @@ sub canvas
if (state.tool = 8 or state.tool=7) and pointCount > 2 then
redim finalP(pointCount * 2 - 1) as long
for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next
if state.tool =8 then filledPolygon finalP(), state.fcolor else Polygon finalP(), state.fcolor
dim tmpstr as string
if state.tool =8 then
filledPolygon finalP(), state.fcolor
tmpstr="fpolygon ("
for i=0 to ubound(finalP)-1
tmpstr=tmpstr+str$(finalP(i))+","
next i
tmpstr=tmpstr+str$(finalP(i))+","+hex$(state.fcolor)+")"
addcommand tmpstr
else
Polygon finalP(), state.fcolor
tmpstr="polygon ("
for i=0 to ubound(finalP)-1
tmpstr=tmpstr+str$(finalP(i))+","
next i
tmpstr=tmpstr+str$(finalP(i))+","+hex$(state.fcolor)+")"
addcommand tmpstr
end if
else
' Merge the preview into the drawing layer
_putimage , layers(2).ihandle, layers(1).ihandle
select case state.tool
case 2 ' Line
thickline state.startX, state.startY, canX, canY, drawCol
addcommand "line ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")"
case 3 ' Circle
r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2))
thickcircle state.startX, state.startY, r + 1, drawCol
addcommand "circle ("+str$(state.startX)+","+str$(state.startY)+","+str$(int(r))+","+hex$(drawCol)+")"
case 4
r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2))
filledcircle state.startX, state.startY, r + 1, drawCol
addcommand "fcircle ("+str$(state.startX)+","+str$(state.startY)+","+str$(int(r))+","+hex$(drawCol)+")"
case 5 ' Box
line (state.startX, state.startY)-(canX, canY), drawCol, b
addcommand "box ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")"
case 6 ' Filled Box
line (state.startX, state.startY)-(canX, canY), drawCol, bf
addcommand "fbox ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")"
end select
end if
_dest layers(2).ihandle: cls , 0