small stuff
This commit is contained in:
parent
b04aaa7019
commit
a80182a5f5
2 changed files with 55 additions and 41 deletions
88
pixler.bas
88
pixler.bas
|
|
@ -18,7 +18,7 @@ type layertype
|
|||
kind as long
|
||||
end type
|
||||
|
||||
redim shared layers(2) as layertype
|
||||
redim shared layers(3) as layertype
|
||||
dim shared state as statetype
|
||||
|
||||
|
||||
|
|
@ -33,10 +33,12 @@ _delay 0.1
|
|||
temp&=_resize
|
||||
redim shared pal(0) as _unsigned long
|
||||
dim as integer ch1,ch2,ch3,bt
|
||||
loadpalette "endesga16",pal()
|
||||
loadpalette "slso8",pal()
|
||||
layers(0).ihandle=_newimage(640,350,32)
|
||||
layers(1).ihandle=_newimage(640,350,32)
|
||||
layers(2).ihandle=_newimage(640,350,32)
|
||||
layers(3).ihandle=_newimage(640, 350, 32)
|
||||
|
||||
_dest layers(0).ihandle
|
||||
line (0,0)-(_width-1,_height-1),_rgb32(255),bf
|
||||
_dest 0
|
||||
|
|
@ -99,9 +101,14 @@ do
|
|||
state.brushsize=state.brushsize+1
|
||||
case "-"
|
||||
if state.brushsize>1 then state.brushsize=state.brushsize-1
|
||||
case chr$(19) ' ctrl+s
|
||||
'TODO: save logic
|
||||
case chr$(27)' esc
|
||||
'TODO: main menu
|
||||
|
||||
end select
|
||||
_dest 0
|
||||
canvas 'draw canvas first so it doesn't over
|
||||
|
||||
canvas
|
||||
toolbox
|
||||
colorpicker
|
||||
|
||||
|
|
@ -148,40 +155,39 @@ sub colorpicker
|
|||
end sub
|
||||
|
||||
sub canvas
|
||||
dim boxX1 as integer: boxX1 = 70
|
||||
dim boxX1 as integer: boxX1 = 70
|
||||
dim boxWidth as integer: boxWidth = _width - 1 - boxX1
|
||||
dim boxHeight as integer: boxHeight = _height - 20
|
||||
' Added static array to persist points between frames
|
||||
static polypoints(200) as single
|
||||
static pointCount as integer
|
||||
|
||||
' Workspace background
|
||||
_dest 0
|
||||
line (boxX1, 0)-(_width - 1, boxHeight), _rgb32(32), bf
|
||||
|
||||
' Render Layers
|
||||
dim i as integer
|
||||
for i = 0 to ubound(layers)
|
||||
dim w as integer: w = _width(layers(i).ihandle) * state.zoom
|
||||
dim h as integer: h = _height(layers(i).ihandle) * state.zoom
|
||||
_putimage (state.offsetX, state.offsetY)-(state.offsetX + w, state.offsetY + h), layers(i).ihandle
|
||||
next
|
||||
|
||||
' Translate Mouse to Canvas Space
|
||||
' 3. Calculate Canvas Coordinates
|
||||
dim canX as integer: canX = (_mousex - state.offsetX) / state.zoom
|
||||
dim canY as integer: canY = (_mousey - state.offsetY) / state.zoom
|
||||
|
||||
dim drawCol as _unsigned long
|
||||
drawCol = state.fcolor
|
||||
|
||||
' 4. Interaction Logic
|
||||
if _mousex > boxX1 then
|
||||
' Handle First Point / Adding Points
|
||||
if mouseclicked then
|
||||
if state.tool = 7 or state.tool = 8 then
|
||||
' Start Drawing Logic
|
||||
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
|
||||
elseif state.isDrawing = 0 then
|
||||
end if
|
||||
else
|
||||
if (mousedown or rmousedown) and state.isDrawing = 0 then
|
||||
state.startX = canX
|
||||
state.startY = canY
|
||||
state.isDrawing = -1
|
||||
|
|
@ -189,22 +195,23 @@ sub canvas
|
|||
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
|
||||
case 1 ' Pencil: This is the only tool that writes to Layer 1 IMMEDIATELY[cite: 1]
|
||||
_dest layers(1).ihandle
|
||||
thickline state.startX, state.startY, canX, canY, drawCol
|
||||
state.startX = canX: state.startY = canY
|
||||
case 2 ' Line
|
||||
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)
|
||||
thickcircle state.startX, state.startY, r + 1, drawCol
|
||||
case 4 ' Filled Circle
|
||||
dim r_fill as single: r_fill = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
|
||||
filledcircle state.startX, state.startY, r_fill, drawCol
|
||||
dim r_f as single: r_f = sqr((canX - state.startX)^2 + (canY - state.startY)^2)
|
||||
filledcircle state.startX, state.startY, r_f, drawCol
|
||||
case 5 ' Rect
|
||||
thickline state.startX, state.startY, canX, state.startY, drawCol
|
||||
thickline canX, state.startY, canX, canY, drawCol
|
||||
|
|
@ -212,46 +219,42 @@ sub canvas
|
|||
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 ' Polygon Outline and Filled
|
||||
case 7, 8 ' Polygons[cite: 2]
|
||||
if pointCount > 0 then
|
||||
' Draw existing segments
|
||||
for p = 1 to pointCount - 1
|
||||
thickline polypoints((p - 1) * 2), polypoints((p - 1) * 2 + 1), polypoints(p * 2), polypoints(p * 2 + 1), drawCol
|
||||
next p
|
||||
' Draw "rubber-band" to cursor
|
||||
thickline polypoints((pointCount - 1) * 2), polypoints((pointCount - 1) * 2 + 1), canX, canY, drawCol
|
||||
end if
|
||||
end select
|
||||
|
||||
' Release/Commit Logic
|
||||
dim finishDrawing as integer: finishDrawing = 0
|
||||
|
||||
' Polygons finish on Right Click or Enter
|
||||
' 5. Commit Logic
|
||||
dim commit as integer: commit = 0
|
||||
if state.tool = 7 or state.tool = 8 then
|
||||
if rmouseclicked or _keydown(13) then finishDrawing = -1
|
||||
if rmouseclicked then commit = -1
|
||||
else
|
||||
if _mousebutton(1) = 0 then finishDrawing = -1
|
||||
if mousedown = 0 then commit = -1
|
||||
end if
|
||||
|
||||
if finishDrawing then
|
||||
_dest layers(1).ihandle
|
||||
if commit then
|
||||
_dest layers(1).ihandle ' Final destination is always the drawing layer
|
||||
if state.tool = 8 and pointCount > 2 then
|
||||
' Finalize Filled Polygon array for the helper
|
||||
redim finalPoints(pointCount * 2 - 1) as single
|
||||
for p = 0 to (pointCount * 2) - 1: finalPoints(p) = polypoints(p): next
|
||||
filledPolygon finalPoints(), drawCol
|
||||
redim finalP(pointCount * 2 - 1) as single
|
||||
for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next
|
||||
filledPolygon finalP(), drawCol ' Using tools.bm sub[cite: 2]
|
||||
else
|
||||
_putimage , layers(2).ihandle
|
||||
' Merge the preview into the drawing layer[cite: 1]
|
||||
_putimage , layers(2).ihandle, layers(1).ihandle
|
||||
end if
|
||||
|
||||
' Clear preview layer[cite: 1]
|
||||
_dest layers(2).ihandle: cls , 0
|
||||
state.isDrawing = 0
|
||||
pointCount = 0 ' Reset polygon points
|
||||
pointCount = 0
|
||||
end if
|
||||
_dest 0
|
||||
end if
|
||||
end if
|
||||
_dest 0 ' Ensure we return to main screen[cite: 1]
|
||||
end sub
|
||||
|
||||
function icon (index as long)
|
||||
|
|
@ -264,10 +267,17 @@ function icon (index as long)
|
|||
icons(0) = _newimage(32, 32, 32): _dest icons(0): line (5, 27)-(27, 5): _dest 0
|
||||
icons(1) = _newimage(32, 32, 32): _dest icons(1): circle (15, 15), 13: _dest 0
|
||||
icons(2) = _newimage(32, 32, 32): _dest icons(2): line (5, 5)-(27, 27), , b: _dest 0
|
||||
icons(6) = _newimage(32, 32, 32): _dest icons(6)
|
||||
line (5, 15)-(15, 5): line -(25, 15): line -(20, 25): line -(10, 25): line -(5, 15)
|
||||
_dest 0
|
||||
|
||||
icons(7) = _newimage(32, 32, 32): _dest icons(7)
|
||||
' Draw a small filled shape for the filled polygon icon
|
||||
for fy = 10 to 20: line (10, fy)-(22, fy): next
|
||||
_dest 0
|
||||
' Fill the remaining slots with blank 32x32 images
|
||||
dim j as integer
|
||||
for j = 3 to 19
|
||||
for j = 0 to 19
|
||||
if icons(j) = 0 then icons(j) = _newimage(32, 32, 32)
|
||||
next
|
||||
|
||||
|
|
|
|||
4
test.bas
Normal file
4
test.bas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
while k$=""
|
||||
k$ = inkey$
|
||||
if k$><"" then print k$
|
||||
wend
|
||||
Loading…
Add table
Add a link
Reference in a new issue