refactor done?
This commit is contained in:
parent
947c7eac4c
commit
8046809184
1 changed files with 157 additions and 161 deletions
318
pixler.bas
318
pixler.bas
|
|
@ -85,7 +85,7 @@ do
|
|||
oldHeight = _height
|
||||
end if
|
||||
|
||||
canvas
|
||||
canvas
|
||||
if showtoolbox then toolbox
|
||||
if showcolorpicker then colorpicker
|
||||
if showcommands then commandlist
|
||||
|
|
@ -457,9 +457,9 @@ sub canvas
|
|||
case 4
|
||||
do.fcircle state.startX,state.startY,sqr((canX - state.startX)^2 + (canY - state.startY)^2),drawCol
|
||||
case 5
|
||||
do.box canX,canY
|
||||
do.box state.startX,state.startY,canX,canY,drawCol
|
||||
case 6
|
||||
do.fbox canX,canY
|
||||
do.fbox state.startX,state.startY,canX,canY,drawCol
|
||||
case 7
|
||||
do.polygon canX,canY
|
||||
case 8
|
||||
|
|
@ -469,152 +469,6 @@ sub canvas
|
|||
case 10
|
||||
do.eyedropper canX,canY
|
||||
end select
|
||||
|
||||
'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
|
||||
'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
|
||||
'' _dest layers(2).ihandle
|
||||
'' cls , 0
|
||||
'' select case state.tool
|
||||
'' case 1
|
||||
'' _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
|
||||
'' thickline state.startX, state.startY, canX, canY, drawCol
|
||||
'' case 3
|
||||
'' r = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
|
||||
'' thickcircle state.startX, state.startY, r + 1, drawCol
|
||||
'' case 4
|
||||
'' r = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
|
||||
'' filledcircle state.startX, state.startY, r, drawCol
|
||||
'' case 5
|
||||
'' thickbox state.startX,state.starty,canX,canY,drawCol
|
||||
''
|
||||
'' case 6
|
||||
'' filledbox state.startX,state.startY,canX, canY, drawCol
|
||||
'' case 7, 8
|
||||
'' 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
|
||||
'' 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
|
||||
'' 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
|
||||
'' 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
|
||||
'' _dest layers(2).ihandle: cls , 0
|
||||
'' state.isDrawing = 0
|
||||
'' pointCount = 0
|
||||
'' end if
|
||||
'end if
|
||||
''
|
||||
_dest 0
|
||||
end sub
|
||||
|
||||
sub do.pencil(x as long,y as long, col as long)
|
||||
|
|
@ -634,9 +488,20 @@ end sub
|
|||
sub do.line(sx as long,sy as long,ex as long,ey as long,col as long)
|
||||
dim osource as long
|
||||
dim odest as long
|
||||
if state.isdrawing then
|
||||
osource = _source
|
||||
odest = _dest
|
||||
|
||||
if mouseclicked or rmouseclicked then
|
||||
_dest layers(1).ihandle
|
||||
addcommand "line (" + tst(sx) + "," + tst(sy) + "," + tst(ex) + "," + tst(ey) + "," + hex$(col) + ")"
|
||||
state.isdrawing=0
|
||||
else
|
||||
_dest layers(2).ihandle
|
||||
end if
|
||||
thickline sx, sy, ex, ey, col
|
||||
_source osource
|
||||
_dest odest
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub do.circle (x as long,y as long,r as long,col as long)
|
||||
|
|
@ -661,41 +526,172 @@ end sub
|
|||
sub do.fcircle (x as long,y as long,r as long,col as long)
|
||||
dim osource as long
|
||||
dim odest as long
|
||||
if state.isdrawing then
|
||||
osource = _source
|
||||
odest = _dest
|
||||
|
||||
if mouseclicked or rmouseclicked then
|
||||
_dest layers(1).ihandle
|
||||
addcommand "fcircle ("+tst(x)+","+tst(y)+","+tst(int(r))+","+hex$(col)+")"
|
||||
state.isdrawing=0
|
||||
else
|
||||
_dest layers(2).ihandle
|
||||
end if
|
||||
filledcircle x, y, r, col
|
||||
_source osource
|
||||
_dest odest
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub do.box(x,y)
|
||||
sub do.box(sx as long,sy as long,ex as long,ey as long,col as long)
|
||||
dim osource as long
|
||||
dim odest as long
|
||||
if state.isdrawing then
|
||||
osource = _source
|
||||
odest = _dest
|
||||
|
||||
if mouseclicked or rmouseclicked then
|
||||
_dest layers(1).ihandle
|
||||
addcommand "box ("+tst(sX)+","+tst(sY)+","+tst(eX)+","+tst(eY)+","+hex$(Col)+")"
|
||||
state.isdrawing=0
|
||||
else
|
||||
_dest layers(2).ihandle
|
||||
end if
|
||||
thickbox sX,sy,eX,eY,Col
|
||||
_source osource
|
||||
_dest odest
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub do.fbox(x,y)
|
||||
sub do.fbox(sx as long,sy as long,ex as long,ey as long,col as long)
|
||||
dim osource as long
|
||||
dim odest as long
|
||||
if state.isdrawing then
|
||||
osource = _source
|
||||
odest = _dest
|
||||
|
||||
if mouseclicked or rmouseclicked then
|
||||
_dest layers(1).ihandle
|
||||
addcommand "fbox ("+tst(sX)+","+tst(sY)+","+tst(eX)+","+tst(eY)+","+hex$(Col)+")"
|
||||
state.isdrawing=0
|
||||
else
|
||||
_dest layers(2).ihandle
|
||||
end if
|
||||
filledbox sX,sy,eX,eY,Col
|
||||
_source osource
|
||||
_dest odest
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub do.polygon(x,y)
|
||||
sub do.polygon(x as long, y as long)
|
||||
' 1. Internalized State Memory
|
||||
static polypoints(500) as long
|
||||
static pointCount as integer
|
||||
|
||||
dim osource as long
|
||||
dim odest as long
|
||||
osource = _source
|
||||
odest = _dest
|
||||
dim p as integer
|
||||
dim i as integer
|
||||
dim tmpstr as string
|
||||
|
||||
if state.isdrawing then
|
||||
osource = _source
|
||||
odest = _dest
|
||||
|
||||
' If left-clicked, add the coordinate to this routine's local array
|
||||
if mouseclicked then
|
||||
polypoints(pointCount * 2) = x
|
||||
polypoints(pointCount * 2 + 1) = y
|
||||
pointCount = pointCount + 1
|
||||
end if
|
||||
|
||||
' Finish shape on Right-Click
|
||||
if rmouseclicked and pointCount > 2 then
|
||||
_dest layers(1).ihandle
|
||||
|
||||
redim finalP(pointCount * 2 - 1) as long
|
||||
for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next
|
||||
|
||||
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
|
||||
|
||||
' Clean up local tool state
|
||||
state.isdrawing = 0
|
||||
pointCount = 0
|
||||
else
|
||||
' Live preview rendering loop
|
||||
_dest layers(2).ihandle
|
||||
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), x, y, state.fcolor
|
||||
end if
|
||||
end if
|
||||
|
||||
_source osource
|
||||
_dest odest
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub do.fpolygon(x,y)
|
||||
sub do.fpolygon(x as long, y as long)
|
||||
' 1. Internalized State Memory
|
||||
static polypoints(500) as long
|
||||
static pointCount as integer
|
||||
|
||||
dim osource as long
|
||||
dim odest as long
|
||||
osource = _source
|
||||
odest = _dest
|
||||
dim p as integer
|
||||
dim i as integer
|
||||
dim tmpstr as string
|
||||
|
||||
if state.isdrawing then
|
||||
osource = _source
|
||||
odest = _dest
|
||||
|
||||
' If left-clicked, add the coordinate to this routine's local array
|
||||
if mouseclicked then
|
||||
polypoints(pointCount * 2) = x
|
||||
polypoints(pointCount * 2 + 1) = y
|
||||
pointCount = pointCount + 1
|
||||
end if
|
||||
|
||||
' Finish shape on Right-Click
|
||||
if rmouseclicked and pointCount > 2 then
|
||||
_dest layers(1).ihandle
|
||||
|
||||
redim finalP(pointCount * 2 - 1) as long
|
||||
for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next
|
||||
|
||||
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
|
||||
|
||||
' Clean up local tool state
|
||||
state.isdrawing = 0
|
||||
pointCount = 0
|
||||
else
|
||||
' Live preview rendering loop
|
||||
_dest layers(2).ihandle
|
||||
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), x, y, state.fcolor
|
||||
end if
|
||||
end if
|
||||
|
||||
_source osource
|
||||
_dest odest
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub do.floodfill(x as long,y as long, col as long)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue