TextGadget drop shadow?

Mac OSX specific forum
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

TextGadget drop shadow?

Post by Rinzwind »

Anyway to do this with macOS functionality?

I'm guessing something with NSShadow or NSShadowAttributeName... but clueless. Also guessing can't use UILabel. TextGadget is based on NSTextView?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: TextGadget drop shadow?

Post by wilbert »

Code: Select all

Procedure SetGadgetShadow(Gadget, hOffset, vOffset, blur, color)
  
  Protected.CGSize ShadowOffset
  Protected.CGFloat ShadowBlurRadius, R,G,B,A
  Protected.i Shadow, ShadowColor
  
  ShadowOffset\width = hOffset
  ShadowOffset\height = vOffset
  ShadowBlurRadius = blur
  R = Red(Color)
  G = Green(Color)
  B = Blue(Color)
  A = Alpha(Color)
  
  Shadow = CocoaMessage(0, 0, "NSShadow new")
  ShadowColor = CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@", @R, 
                             "green:@", @G,
                             "blue:@", @B,
                             "alpha:@", @A)
  
  CocoaMessage(0, Shadow, "setShadowOffset:@", @ShadowOffset)
  CocoaMessage(0, Shadow, "setShadowBlurRadius:@", @ShadowBlurRadius)
  CocoaMessage(0, Shadow, "setShadowColor:", ShadowColor)
  CocoaMessage(0, GadgetID(Gadget), "setWantsLayer:", #YES)
  CocoaMessage(0, GadgetID(Gadget), "setShadow:", Shadow)
  CocoaMessage(0, Shadow, "release")
  
EndProcedure




If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(0, 10,  10, 250, 20, "TextGadget Standard (Left)")
  TextGadget(1, 10,  70, 250, 20, "TextGadget Center", #PB_Text_Center)
  TextGadget(2, 10,  40, 250, 20, "TextGadget Right", #PB_Text_Right)
  TextGadget(3, 10, 100, 250, 20, "TextGadget Border", #PB_Text_Border)
  TextGadget(4, 10, 130, 250, 20, "TextGadget Center + Border", #PB_Text_Center | #PB_Text_Border)
  
  SetGadgetShadow(0, 4, 4, 4, $800000ff)
  SetGadgetShadow(3, 2, 2, 4, $8000ff00)
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Last edited by wilbert on Sun Dec 22, 2019 4:14 pm, edited 1 time in total.
Windows (x64)
Raspberry Pi OS (Arm64)
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: TextGadget drop shadow?

Post by Rinzwind »

Exceeded expectations. Fast and correct. So glad this forum (and Wilbert 8) ) exists ;)
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: TextGadget drop shadow?

Post by Justin »

I had to put:

Code: Select all

CocoaMessage(0, GadgetID(Gadget), "setWantsLayer:", #YES)
Just before:

Code: Select all

CocoaMessage(0, GadgetID(Gadget), "setShadow:", Shadow)
Otherwise it did not work here.
PB5.70 MacOS 10.12.6
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: TextGadget drop shadow?

Post by wilbert »

Justin wrote:Otherwise it did not work here.
PB5.70 MacOS 10.12.6
The Apple docs do mention that if the view does not have a layer, setting a border has no effect.
So you are probably right about this and to be sure I updated the code to include this line.
On macOS 10.15 however it also seems to work without this line so that's why I didn't notice it.
Windows (x64)
Raspberry Pi OS (Arm64)
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: TextGadget drop shadow?

Post by Justin »

Maybe is the PB version, I am using 5.70, have you tried in 5.71:

Code: Select all

  Debug CocoaMessage(0, GadgetID(Gadget), "wantsLayer")
Before setting it? Here it shows 0.
Post Reply