I've used it in several situations, one is for creating shadows for objects which are transparent...
Code: Select all
Procedure Min(a,b)
If a<b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
Macro StartClipping()
SaveVectorState()
ClipPath()
EndMacro
Macro StopClipping()
RestoreVectorState()
EndMacro
Procedure AddPathRoundBox(x.d,y.d,w.d,h.d,radius.d,flags=#PB_Path_Default)
If radius>h/2 : radius=h/2 : EndIf
If radius>w/2 : radius=w/2 : EndIf
If radius<0
radius=0
EndIf
MovePathCursor(x+radius,y,flags)
AddPathArc(w-radius,0,w-radius,radius,radius,#PB_Path_Relative)
AddPathArc(0,h-radius,-radius,h-radius,radius,#PB_Path_Relative)
AddPathArc(-w+radius,0,-w+radius,-radius,radius,#PB_Path_Relative)
AddPathArc(0,-h+radius,radius,-h+radius,radius,#PB_Path_Relative)
ClosePath()
MovePathCursor(-radius,0,#PB_Path_Relative)
EndProcedure
Procedure AddPathHighlight(x.d,y.d,w.d,h.d,r.d,angle.d,flags=#PB_Path_Default)
Protected t1.d,t2.d,t3.d,t4.d,t5.d
t1=Cos(angle*#PI/180); 1-89°
t2=Sin(angle*#PI/180)
t3=r*t1
t4=r*t2
t5=2*r-t4
MovePathCursor(x,y+r,flags)
AddPathCircle(r,0,r,180,270,#PB_Path_Relative)
AddPathLine(w-r*2,0,#PB_Path_Relative)
AddPathCircle(0,r,r,270,270+angle,#PB_Path_Relative|#PB_Path_Connected)
AddPathLine(-w+t5,0,#PB_Path_Relative)
AddPathCircle(0,t3,t3,270,180,#PB_Path_Relative|#PB_Path_Connected|#PB_Path_CounterClockwise)
AddPathLine(0,h-t5,#PB_Path_Relative)
AddPathCircle(t3,-t4,r,180-angle,180,#PB_Path_Relative|#PB_Path_Connected)
ClosePath()
EndProcedure
Procedure AddPathShadow(x.d,y.d,w.d,h.d,r.d,angle.d,flags=#PB_Path_Default)
Protected ro.d
Protected t1.d,t2.d,t3.d,t4.d,t5.d
ro=Min(Min(r,h/2),w/2)
t1=Cos(angle*#PI/180); 1-89°
t2=Sin(angle*#PI/180)
t3=r*t1
t4=r*t2
t5=2*r-t4
r=ro
MovePathCursor(x+w,y+h-r,flags)
AddPathCircle(-r,0,r,0,90,#PB_Path_Relative)
AddPathLine(-w+r*2,0,#PB_Path_Relative)
AddPathCircle(0,-r,r,90,90+angle,#PB_Path_Relative|#PB_Path_Connected)
AddPathLine(w-t5,0,#PB_Path_Relative)
AddPathCircle(0,-t3,t3,90,0,#PB_Path_Relative|#PB_Path_Connected|#PB_Path_CounterClockwise)
AddPathLine(0,-h+t5,#PB_Path_Relative)
AddPathCircle(-t3,t4,r,360-angle,360,#PB_Path_Relative|#PB_Path_Connected)
ClosePath()
EndProcedure
Procedure DrawVectorShadow(x.d,y.d,w.d,h.d,radius.d,size.d=20,offset.d=5,alpha.d=20,color=#Black,flags=#PB_Path_Default)
Protected i
AddPathBox(0,0,VectorOutputWidth(),VectorOutputHeight())
AddPathRoundBox(x,y,w,h,radius)
StartClipping()
For i=1 To size
AddPathRoundBox(x+offset-i,y+offset-i,w+i*2,h+i*2,((w+i)*radius/w) )
VectorSourceColor(RGBA(Red(color), Green(color), Blue(color), Alpha/size))
FillPath()
Next
StopClipping()
EndProcedure
Procedure boxs(x.f,y.f,w.f,h.f,radius.f,col,alpha=255,button.f=8,shadow.f=20,darkness=100,offset.f=15)
Protected shadowcount=20
radius=min(min(radius,h/2),w/2)
BeginVectorLayer(min(alpha,255))
; Shadow
shadow/shadowcount
darkness=darkness/shadowcount+1
For i=0 To shadowcount
AddPathRoundBox(x+offset+shadow*i/2,y+offset+shadow*i/2,w-shadow*i,h-shadow*i,radius-shadow*(i-shadowcount/2)/2)
VectorSourceColor(darkness<<24)
FillPath()
Next i
; Filled Button
AddPathRoundBox(x,y,w,h,radius)
VectorSourceColor($ff000000|col)
FillPath()
; Erasing area...
;AddPathBox(x+50,y+50,150,50)
;VectorSourceColor($fffffffff)
;FillPath()
; Highlight and Shadow
VectorSourceColor($40ffffff)
AddPathHighlight(x,y,w,h,radius,button*2)
FillPath()
AddPathHighlight(x,y,w,h,radius,button*3)
FillPath()
VectorSourceColor($20000000)
AddPathShadow(x,y,w,h,radius,button*2)
FillPath()
AddPathShadow(x,y,w,h,radius,button*3)
FillPath()
; Button Border
AddPathRoundBox(x,y,w,h,radius)
VectorSourceColor($60000000)
StrokePath(1)
EndVectorLayer()
EndProcedure
Procedure show()
Protected i
StartVectorDrawing(CanvasVectorOutput(0))
AddPathBox(0,0,VectorOutputWidth(),VectorOutputHeight())
VectorSourceColor($Ff000000|#White)
FillPath()
; some random background
For i=0 To 100
AddPathBox(Random(VectorOutputWidth())-50,Random(VectorOutputHeight())-50, 50+Random(50), 50+Random(50))
VectorSourceColor(RGBA(Random(255),Random(255),Random(255),Random(40)))
FillPath()
Next
boxs(300,100,130,400,90,$9AF0B8,160,10)
boxs(50,50,400,150,90,$D1ADF3,180,5,50,170)
boxs(50,350,500,100,40,$F3D1AD,250,10,20,50); smaller radius
boxs(400,100,300,200,90,$9AF0F8,120,5)
boxs(500,250,100,300,90,$9AF0B8,180,10)
boxs(100,100,130,400,90,$9AF0B8,100,10)
StopVectorDrawing()
EndProcedure
Procedure main()
#X=800
#Y=600
OpenWindow(0,0,0,#X,#Y,"")
CanvasGadget(0,0,0,#X,#Y)
show()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #WM_CHAR
End
EndSelect
ForEver
EndProcedure
main()