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?
TextGadget drop shadow?
Re: TextGadget drop shadow?
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)
Raspberry Pi OS (Arm64)
Re: TextGadget drop shadow?
Exceeded expectations. Fast and correct. So glad this forum (and Wilbert ) exists
Re: TextGadget drop shadow?
I had to put:
Just before:
Otherwise it did not work here.
PB5.70 MacOS 10.12.6
Code: Select all
CocoaMessage(0, GadgetID(Gadget), "setWantsLayer:", #YES)
Code: Select all
CocoaMessage(0, GadgetID(Gadget), "setShadow:", Shadow)
PB5.70 MacOS 10.12.6
Re: TextGadget drop shadow?
The Apple docs do mention that if the view does not have a layer, setting a border has no effect.Justin wrote:Otherwise it did not work here.
PB5.70 MacOS 10.12.6
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)
Raspberry Pi OS (Arm64)
Re: TextGadget drop shadow?
Maybe is the PB version, I am using 5.70, have you tried in 5.71:
Before setting it? Here it shows 0.
Code: Select all
Debug CocoaMessage(0, GadgetID(Gadget), "wantsLayer")