Drop Shadow in Canvas Gadget

Mac OSX specific forum
simberr
User
User
Posts: 46
Joined: Sun Jun 10, 2018 12:54 pm

Drop Shadow in Canvas Gadget

Post 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.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Drop Shadow in Canvas Gadget

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
simberr
User
User
Posts: 46
Joined: Sun Jun 10, 2018 12:54 pm

Re: Drop Shadow in Canvas Gadget

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Drop Shadow in Canvas Gadget

Post by mk-soft »

Cool :D

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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply