//To add a DropShadow to graphics in Cocoa:
Sub CGSetShadow(g As Graphics, xOffset As integer, yOffset As integer, blur As Double, c as Color)
#if TargetCocoa then
declare sub CGContextSetShadowWithColor lib "Cocoa" (context as integer,offset as cgsize,blur as single,c as ptr)
declare function CGColorSpaceCreateDeviceRGB lib "Cocoa" () as ptr
declare function CGColorCreate lib "Cocoa" (colorspace as ptr, val as ptr) as ptr
declare sub CGColorRelease lib "Cocoa" (c as ptr)
declare sub CGColorSpaceRelease lib "Cocoa" (c as ptr)
dim offset As CGSize
offset.width=xOffset
offset.height=0-yOffset
dim cgcm As MemoryBlock
dim cgcolor As ptr
cgcm= new MemoryBlock(16)
cgcm.SingleValue(0)=c.red/255
cgcm.SingleValue(4)=c.Green/255
cgcm.SingleValue(8)=c.Blue/255
cgcm.SingleValue(12)=(255-c.Alpha)/255
dim cgcspace as ptr=CGColorSpaceCreateDeviceRGB
cgcolor=CGColorCreate(cgcspace,cgcm)
CGColorSpaceRelease(cgcspace)
CGContextSetShadowWithColor g.Handle(Graphics.HandleTypeCGContextRef),offset,blur,cgcolor
if cgcolor<>nil then CGColorRelease(cgcolor)
#endif
End Sub
//And to turn them back off:
Sub CGClearShadow(g As Graphics)
#if TargetCocoa then
declare sub CGContextSetShadowWithColor lib "Cocoa" (context as integer,offset as CGSize,blur as single,c as ptr)
dim s As CGSize
CGContextSetShadowWithColor g.Handle(Graphics.HandleTypeCGContextRef),s,0,nil
#endif
End Sub
// Don't forget to add the CGSize struct! width as single height as single
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.