Context Drop Shadow Declares for Windows and Linux

Hi,

I’m looking for an equivalent declare to display shadows under Windows using Direct2D/DirectWrite and under Linux (GTK+3). For macOS I found the CGContextSetShadowWithColor Declare successfully and it works wonderfully. So far I haven’t found anything for the other two platforms in my search. Does anyone have a tip?

Thanks.

Hi Martin,

Xojo in Windows usually seems to have a DropShadow for a Window. Maybe I am misinterpreting the request. Here is API code that will show a DropShadow on a Window.

Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (hWnd As Int32, nIndex As Int32) As Int32 Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (hWnd As Int32, nIndex As Int32, dwNewLong As Int32) As Int32 Const CS_DROPSHADOW As Int32 = &H20000 Const GCL_STYLE As Int32 = -26 Call SetClassLong(Window1.Handle, GCL_STYLE, GetClassLong(Window1.Handle, GCL_STYLE) or CS_DROPSHADOW)

Is this what you are wanting?

Hi Eugene,

thanks for your reply. No, it’s not directly what I’m looking for. I’d love to create native drop shadows behind Graphics.DrawString like here: https://docs.microsoft.com/en-us/windows/desktop/Direct2D/drop-shadow or here https://www.codeproject.com/Articles/21071/Glow-and-Shadow-Effects-using-Windows-GDI. I’m not fit into Windows, that’s why I asked. Under macOS, this code snippet is enough to create drop shadows:

[code]Declare Sub CGContextSetShadow Lib “CoreGraphics” (context As Integer, offset As CGSize_FTC, blur As CGFloat)
Declare Sub CGContextSetShadowWithColor Lib “CoreGraphics” (context As Integer, offset As CGSize_FTC, blur As CGFloat, CGColorRef As Ptr)

Declare Function CGColorSpaceCreateWithName Lib “CoreGraphics” (name As CFStringRef) As Ptr
Declare Function CGColorCreate Lib “CoreGraphics” (space As Ptr, components As Ptr) As Ptr

Dim context As Integer = g.Handle(g.HandleTypeCGContextRef)
Dim s As CGSize_FTC

s.Width = 8
s.Height = -8

Dim cspace, colorref As Ptr
Dim components As MemoryBlock
Dim shadowColor As Color = &cF4A80800

#If Target32Bit

components = New MemoryBlock(4 * 4) ’ 4 components per color * sizeof(Single)
components.SingleValue(0 * 4) = shadowColor.Red / 255
components.SingleValue(1 * 4) = shadowColor.Green / 255
components.SingleValue(2 * 4) = shadowColor.Blue / 255
components.SingleValue(3 * 4) = 100 /100 ’ must be single /100

#ElseIf Target64Bit

components = New MemoryBlock(4 * 8) ’ 4 components per color * sizeof(Single)
components.DoubleValue(0 * 8) = shadowColor.Red / 255
components.DoubleValue(1 * 8) = shadowColor.Green / 255
components.DoubleValue(2 * 8) = shadowColor.Blue / 255
components.DoubleValue(3 * 8) = 100 /100 ’ must be single /100

#Endif

cspace = CGColorSpaceCreateWithName(“kCGColorSpaceGenericRGB”)
colorref = CGColorCreate(cspace, components)

CGContextSetShadowWithColor(context, s, 10, colorref)

g.TextSize = 48
g.Bold = True
g.ForeColor = &cFB271100
g.TextFont = “Courier New”
g.DrawString(“Hello World!”, 10, 60)[/code]

CGPoint, CGSize and CGSize are Structures.

CGPoint
x As CGFloat
y As CGFloat

CGSize
width As CGFloat
height As CGFloat

CGRect
origin As CGPoint
rSize As CGSize