Edit history, like a true winner, start of redraw logic.

This commit is contained in:
visionmercer 2026-05-12 10:17:52 +02:00
commit 9e5db80b0a
2 changed files with 169 additions and 153 deletions

View file

@ -8,7 +8,7 @@ function textinput$ (x as integer,y as integer,w as integer,h as integer,__text
end if end if
drawtextinput x,y,w,h,__text,1 drawtextinput x,y,w,h,__text,1
if not mouseclicked then exit function if not mouseclicked then exit function
text="" 'text=""
cursor=len(text)+1 cursor=len(text)+1
dim relativeX as integer dim relativeX as integer
do do

View file

@ -65,14 +65,14 @@ addcommand "fcolor ("+hex$(state.fcolor)+")"
addcommand "bcolor ("+hex$(state.bcolor)+")" addcommand "bcolor ("+hex$(state.bcolor)+")"
dim lastMX, lastMY dim lastMX, lastMY
dim diffX as integer
dim diffY as integer
dim oldWidth as integer
dim oldHeight as integer
dim keyin as string dim keyin as string
dim mouseWorldY as integer dim mouseWorldY as integer
dim mouseWorldX as integer dim mouseWorldX as integer
dim diffX as integer
dim diffY as integer
dim oldWidth as integer
dim oldHeight as integer
oldWidth=_width oldWidth=_width
oldHeight=_height oldHeight=_height
do do
@ -164,7 +164,7 @@ loop
sub commandlist sub commandlist
dim i as long dim i as long
dim listWidth as integer:listWidth = 150 dim listWidth as integer:listWidth = 250
dim x as integer:x=_width-listWidth dim x as integer:x=_width-listWidth
' Draw background for the list ' Draw background for the list
@ -176,9 +176,35 @@ sub commandlist
for i = ubound(commands) - 1 to 0 step -1 for i = ubound(commands) - 1 to 0 step -1
y = (ubound(commands)-i) * 16 y = (ubound(commands)-i) * 16
if y < _height - 20 then if y < _height - 20 then
_printstring (x + 5, y + 5), left$(commands(i), 18) '_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))
end if
end if end if
next i next i
if button(x,_height-25, 60,23, "redraw") then redraw
end sub
sub redraw
redim numarr(0) as long
for i=lbound(commands) to ubound(commands)
select case lcase$(_trim$(left$(commands(i),instr(commands(i),"(")-1)))
case "canvas"
case "fcolor"
case "bcolor"
case "pixel"
case "line"
case "brushwidth"
case "box"
case "fbox"
case "circle"
case "fcircle"
case "polygon"
case "fpolygon"
case "floodfill"
case else
end select
next i
end sub end sub
sub toolbox sub toolbox
@ -328,161 +354,151 @@ sub canvas
static drawCol static drawCol
if _mousebutton(1) then drawCol = state.fcolor if _mousebutton(1) then drawCol = state.fcolor
if _mousebutton(2) then drawCol = state.bcolor if _mousebutton(2) then drawCol = state.bcolor
if state.tool = 9 and (mouseclicked or rmouseclicked) then
' 4. Interaction Logic _dest layers(1).ihandle
'if _mousex > boxX1 then _source layers(1).ihandle
' Start Drawing Logic if mouseclicked then
if state.tool = 9 and (mouseclicked or rmouseclicked) then floodfill canX,canY,state.fcolor
_dest layers(1).ihandle addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.fcolor)+")"
_source layers(1).ihandle
if mouseclicked then
floodfill canX,canY,state.fcolor
addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.fcolor)+")"
else
floodfill canX,canY,state.bcolor
addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.bcolor)+")"
end if
_dest 0
_source 0
exit sub
end if
if state.tool = 10 and (mouseclicked or rmouseclicked) then
_dest layers(1).ihandle
_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
exit sub
end if
if state.tool = 7 or state.tool = 8 then
if mouseclicked then
polypoints(pointCount * 2) = canX
polypoints(pointCount * 2 + 1) = canY
pointCount = pointCount + 1
state.isDrawing = -1
end if
else else
if (mousedown or rmousedown) and state.isDrawing = 0 then floodfill canX,canY,state.bcolor
state.startX = canX addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.bcolor)+")"
state.startY = canY
state.isDrawing = -1
end if
end if end if
_dest 0
if state.isDrawing then _source 0
' We use Layer 2 as the temporary preview "rubber-band" layer exit sub
_dest layers(2).ihandle end if
cls , 0 if state.tool = 10 and (mouseclicked or rmouseclicked) then
select case state.tool _dest layers(1).ihandle
case 1 ' Pencil _source layers(1).ihandle
_dest layers(1).ihandle if mouseclicked then
if canX=state.startX and canY=state.startY then state.fcolor=point(canX,canY)
thickpixel canX,canY,drawCol addcommand "fcolor ("+hex$(point(canX,canY))+")"
addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" else
else state.bcolor=point(canX,canY)
thickline state.startX, state.startY, canX, canY, drawCol addcommand "bcolor ("+hex$(point(canX,cany))+")"
addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" end if
end if _dest 0
state.startX = canX: state.startY = canY _source 0
case 2 ' Straight Line exit sub
thickline state.startX, state.startY, canX, canY, drawCol end if
case 3 ' Circle if state.tool = 7 or state.tool = 8 then
r = sqr((canX - state.startX)^2 + (canY - state.startY)^2) if mouseclicked then
thickcircle state.startX, state.startY, r + 1, drawCol polypoints(pointCount * 2) = canX
case 4 ' Filled Circle polypoints(pointCount * 2 + 1) = canY
r = sqr((canX - state.startX)^2 + (canY - state.startY)^2) pointCount = pointCount + 1
filledcircle state.startX, state.startY, r, drawCol state.isDrawing = -1
case 5 ' Rect end if
thickline state.startX, state.startY, canX, state.startY, drawCol else
thickline canX, state.startY, canX, canY, drawCol if (mousedown or rmousedown) and state.isDrawing = 0 then
thickline canX, canY, state.startX, canY, drawCol state.startX = canX
thickline state.startX, canY, state.startX, state.startY, drawCol state.startY = canY
case 6 ' Filled Rect state.isDrawing = -1
line (state.startX, state.startY)-(canX, canY), drawCol, bf end if
case 7, 8 ' Polygons end if
if pointCount > 0 then if state.isDrawing then
for p = 1 to pointCount - 1 ' We use Layer 2 as the temporary preview "rubber-band" layer
thickline polypoints((p - 1) * 2), polypoints((p - 1) * 2 + 1), polypoints(p * 2), polypoints(p * 2 + 1), state.fcolor _dest layers(2).ihandle
next p cls , 0
thickline polypoints((pointCount - 1) * 2), polypoints((pointCount - 1) * 2 + 1), canX, canY, state.fcolor select case state.tool
end if case 1 ' Pencil
end select _dest layers(1).ihandle
if canX=state.startX and canY=state.startY then
' 5. Commit Logic thickpixel canX,canY,drawCol
dim commit as integer: commit = 0 addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
if state.tool = 7 or state.tool = 8 then
if rmouseclicked then commit = -1
else
if (mousedown=0) and (rmousedown=0) then commit = -1
end if
if commit then
_dest layers(1).ihandle ' Final destination is always the drawing layer
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
dim tmpstr as string
if state.tool =8 then
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))+","+hex$(state.fcolor)+")"
addcommand tmpstr
else
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))+","+hex$(state.fcolor)+")"
addcommand tmpstr
end if
else else
' Merge the preview into the drawing layer thickline state.startX, state.startY, canX, canY, drawCol
'_putimage , layers(2).ihandle, layers(1).ihandle addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
select case state.tool
case 2 ' Line
if canX=state.startX and canY=state.startY then
thickpixel canX,canY,drawCol
addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
else
thickline state.startX, state.startY, canX, canY, drawCol
addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end if
case 3 ' Circle
r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2))
thickcircle state.startX, state.startY, r + 1, drawCol
addcommand "circle ("+tst(state.startX)+","+tst(state.startY)+","+tst(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 ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")"
case 5 ' Box
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
addcommand "fbox ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end select
end if end if
state.startX = canX: state.startY = canY
_dest layers(2).ihandle: cls , 0 case 2 ' Straight Line
state.isDrawing = 0 thickline state.startX, state.startY, canX, canY, drawCol
pointCount = 0 case 3 ' Circle
end if r = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
thickcircle state.startX, state.startY, r + 1, drawCol
case 4 ' Filled Circle
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
case 6 ' Filled Rect
line (state.startX, state.startY)-(canX, canY), drawCol, bf
case 7, 8 ' Polygons
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), canX, canY, state.fcolor
end if
end select
' 5. Commit Logic
dim commit as integer: commit = 0
if state.tool = 7 or state.tool = 8 then
if rmouseclicked then commit = -1
else
if (mousedown=0) and (rmousedown=0) then commit = -1
end if end if
'end if if commit then
_dest 0 ' Ensure we return to main screen _dest layers(1).ihandle ' Final destination is always the drawing layer
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
dim tmpstr as string
if state.tool =8 then
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))+","+hex$(state.fcolor)+")"
addcommand tmpstr
else
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))+","+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
if canX=state.startX and canY=state.startY then
thickpixel canX,canY,drawCol
addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
else
thickline state.startX, state.startY, canX, canY, drawCol
addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end if
case 3 ' Circle
r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2))
thickcircle state.startX, state.startY, r + 1, drawCol
addcommand "circle ("+tst(state.startX)+","+tst(state.startY)+","+tst(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 ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")"
case 5 ' Box
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
addcommand "fbox ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
end select
end if
_dest layers(2).ihandle: cls , 0
state.isDrawing = 0
pointCount = 0
end if
end if
_dest 0
end sub end sub
function icon (index as long) function icon (index as long)