Page 1 of 1
Drop Shadow in Canvas Gadget
Posted: Wed Oct 17, 2018 2:27 pm
by simberr
I would really like to use the OSX Dropshadow availability within the canvas gadgets and have no real idea how to code this in PB.
Can someone provide me with the cocoa calls to undertake this facility?
Thanks in advance.
Re: Drop Shadow in Canvas Gadget
Posted: Wed Oct 17, 2018 3:46 pm
by wilbert
Code: Select all
ImportC ""
CGColorCreateGenericRGB(red.CGFloat, green.CGFloat, blue.CGFloat, alpha.CGFloat)
CGColorRelease(color)
CGContextSetShadowWithColor(context, x_offset.CGFloat, y_offset.CGFloat, blur.CGFloat, color)
EndImport
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
CGContext = StartVectorDrawing(CanvasVectorOutput(0))
If CGContext
VectorSourceColor(RGBA(255, 0, 0, 255))
; Enable dark blue shadow
ShadowColor = CGColorCreateGenericRGB(0, 0, 0.4, 0.8)
CGContextSetShadowWithColor(CGContext, 4, -4, 4, ShadowColor)
CGColorRelease(ShadowColor)
MovePathCursor(100, 100)
AddPathCircle(100, 100, 75, 0, 235, #PB_Path_Connected)
ClosePath()
StrokePath(10)
; Disable shadow
CGContextSetShadowWithColor(CGContext, 0, 0, 0, #Null)
MovePathCursor(300, 100)
AddPathCircle(300, 100, 75, 0, 235, #PB_Path_Connected)
ClosePath()
StrokePath(10)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Re: Drop Shadow in Canvas Gadget
Posted: Wed Oct 17, 2018 5:08 pm
by simberr
Wilbert
Yet again, you have provided the perfect example and answer to my question. Thank you.
I am new to PB and really exploring the software. I am a Xojo user and about to decide to drop Xojo altogether in favour of PB.
I have created a significant number of objects that I use in my Xojo apps and am in the process of converting them all to PB code so that I can replicate the solutions. The more that I delve into PB the easier it is to do this and you have been a significant help in this endeavour.
Thanks again.
Simon.
Re: Drop Shadow in Canvas Gadget
Posted: Wed Oct 17, 2018 9:32 pm
by mk-soft
Cool
Works with fonts...
Code: Select all
ImportC ""
CGColorCreateGenericRGB(red.CGFloat, green.CGFloat, blue.CGFloat, alpha.CGFloat)
CGColorRelease(color)
CGContextSetShadowWithColor(context, x_offset.CGFloat, y_offset.CGFloat, blur.CGFloat, color)
EndImport
LoadFont(0, "Arial", 20, #PB_Font_Bold)
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
CGContext = StartVectorDrawing(CanvasVectorOutput(0))
If CGContext
VectorSourceColor(RGBA(255, 0, 0, 255))
; Enable dark blue shadow
ShadowColor = CGColorCreateGenericRGB(0, 0, 0.4, 0.8)
CGContextSetShadowWithColor(CGContext, 4, -4, 4, ShadowColor)
CGColorRelease(ShadowColor)
MovePathCursor(40, 55)
VectorFont(FontID(0), 85)
DrawVectorText("Purebasic")
; Disable shadow
CGContextSetShadowWithColor(CGContext, 0, 0, 0, #Null)
StopVectorDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf