Edit history, like a true winner, start of redraw logic.
This commit is contained in:
parent
8b5c09d7dd
commit
9e5db80b0a
2 changed files with 169 additions and 153 deletions
328
pixler.bas
328
pixler.bas
|
|
@ -65,14 +65,14 @@ addcommand "fcolor ("+hex$(state.fcolor)+")"
|
|||
addcommand "bcolor ("+hex$(state.bcolor)+")"
|
||||
|
||||
dim lastMX, lastMY
|
||||
dim diffX as integer
|
||||
dim diffY as integer
|
||||
dim oldWidth as integer
|
||||
dim oldHeight as integer
|
||||
dim keyin as string
|
||||
dim mouseWorldY as integer
|
||||
dim mouseWorldX as integer
|
||||
|
||||
dim diffX as integer
|
||||
dim diffY as integer
|
||||
dim oldWidth as integer
|
||||
dim oldHeight as integer
|
||||
oldWidth=_width
|
||||
oldHeight=_height
|
||||
do
|
||||
|
|
@ -164,7 +164,7 @@ loop
|
|||
|
||||
sub commandlist
|
||||
dim i as long
|
||||
dim listWidth as integer:listWidth = 150
|
||||
dim listWidth as integer:listWidth = 250
|
||||
dim x as integer:x=_width-listWidth
|
||||
|
||||
' Draw background for the list
|
||||
|
|
@ -176,9 +176,35 @@ sub commandlist
|
|||
for i = ubound(commands) - 1 to 0 step -1
|
||||
y = (ubound(commands)-i) * 16
|
||||
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
|
||||
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
|
||||
|
||||
sub toolbox
|
||||
|
|
@ -328,161 +354,151 @@ sub canvas
|
|||
static drawCol
|
||||
if _mousebutton(1) then drawCol = state.fcolor
|
||||
if _mousebutton(2) then drawCol = state.bcolor
|
||||
|
||||
' 4. Interaction Logic
|
||||
'if _mousex > boxX1 then
|
||||
' Start Drawing Logic
|
||||
if state.tool = 9 and (mouseclicked or rmouseclicked) then
|
||||
_dest layers(1).ihandle
|
||||
_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
|
||||
if state.tool = 9 and (mouseclicked or rmouseclicked) then
|
||||
_dest layers(1).ihandle
|
||||
_source layers(1).ihandle
|
||||
if mouseclicked then
|
||||
floodfill canX,canY,state.fcolor
|
||||
addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.fcolor)+")"
|
||||
else
|
||||
if (mousedown or rmousedown) and state.isDrawing = 0 then
|
||||
state.startX = canX
|
||||
state.startY = canY
|
||||
state.isDrawing = -1
|
||||
end if
|
||||
floodfill canX,canY,state.bcolor
|
||||
addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.bcolor)+")"
|
||||
end if
|
||||
|
||||
if state.isDrawing then
|
||||
' We use Layer 2 as the temporary preview "rubber-band" layer
|
||||
_dest layers(2).ihandle
|
||||
cls , 0
|
||||
select case state.tool
|
||||
case 1 ' Pencil
|
||||
_dest layers(1).ihandle
|
||||
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
|
||||
state.startX = canX: state.startY = canY
|
||||
case 2 ' Straight Line
|
||||
thickline state.startX, state.startY, canX, canY, drawCol
|
||||
case 3 ' Circle
|
||||
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
|
||||
|
||||
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
|
||||
_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
|
||||
if (mousedown or rmousedown) and state.isDrawing = 0 then
|
||||
state.startX = canX
|
||||
state.startY = canY
|
||||
state.isDrawing = -1
|
||||
end if
|
||||
end if
|
||||
if state.isDrawing then
|
||||
' We use Layer 2 as the temporary preview "rubber-band" layer
|
||||
_dest layers(2).ihandle
|
||||
cls , 0
|
||||
select case state.tool
|
||||
case 1 ' Pencil
|
||||
_dest layers(1).ihandle
|
||||
if canX=state.startX and canY=state.startY then
|
||||
thickpixel canX,canY,drawCol
|
||||
addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
|
||||
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
|
||||
thickline state.startX, state.startY, canX, canY, drawCol
|
||||
addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")"
|
||||
end if
|
||||
|
||||
_dest layers(2).ihandle: cls , 0
|
||||
state.isDrawing = 0
|
||||
pointCount = 0
|
||||
end if
|
||||
state.startX = canX: state.startY = canY
|
||||
case 2 ' Straight Line
|
||||
thickline state.startX, state.startY, canX, canY, drawCol
|
||||
case 3 ' Circle
|
||||
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
|
||||
_dest 0 ' Ensure we return to main screen
|
||||
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
|
||||
' 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
|
||||
|
||||
function icon (index as long)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue