DrawImgShadowEx

Syntax

DrawImgShadowEx(Img, x.d, y.d, Width.d, Height.d, dx.d, dy.d, dWidth.d, dHeight.d, BlurAmount.f=10, Spread.f=0, ShadowColor.l=0, ShadowOpacity.f=1, xOffset.d=0, yOffset.d=0, isHollow=#False)

Description

Draws an extended drop shadow based on the alpha channel of a specific rectangular segment of a source image, and projects it onto a destination rectangle on the current drawing target. This allows you to scale the shadow and apply it to only a portion (or sprite) of a larger image.

Parameters

Img
The handle of the source image object (created with CreateImg() or LoadImg()) to generate a shadow from.

x.d
The horizontal coordinate of the top-left corner of the source clipping rectangle within the image, in device-independent pixels (DIPs).

y.d
The vertical coordinate of the top-left corner of the source clipping rectangle within the image, in DIPs.

Width.d
The width of the source clipping rectangle within the image, in DIPs. Use negative values or #PG_Ignore for the natural width.

Height.d
The height of the source clipping rectangle within the image, in DIPs. Use negative values or #PG_Ignore for the natural height.

dx.d
The horizontal coordinate of the top-left corner of the destination rectangle on the drawing target, in DIPs.

dy.d
The vertical coordinate of the top-left corner of the destination rectangle on the drawing target, in DIPs.

dWidth.d
The desired width of the destination rectangle on the drawing target, in DIPs. If different from Width.d, the shadow will be scaled.

dHeight.d
The desired height of the destination rectangle on the drawing target, in DIPs. If different from Height.d, the shadow will be scaled.

BlurAmount.f (optional)
The gaussian blur amount (radius) to apply to the shadow. Default is 10.

Spread.f (optional)
The expansion (positive value) or contraction (negative value) amount of the shadow’s spread. Default is 0.

ShadowColor.l (optional)
The color of the shadow in RGB format (e.g., using RGB(r, g, b)). Default is 0 (Black).

ShadowOpacity.f (optional)
The opacity of the shadow, ranging from 0.0 (fully transparent) to 1.0 (fully opaque). Default is 1.0.

xOffset.d (optional)
The horizontal offset distance of the shadow relative to the destination rectangle. Default is 0.

yOffset.d (optional)
The vertical offset distance of the shadow relative to the destination rectangle. Default is 0.

isHollow (optional)
If set to #True, the shadow will only be drawn outside the opaque bounds of the image segment (the inner part is hollowed out). Default is #False.

Return Value

This command does not return a value. It returns internally if the Img handle is invalid or the ShadowOpacity is zero or less.

Remarks

All coordinates and dimensions are specified in DIPs but are converted internally to physical pixels based on the current output’s DPI. This function is particularly useful when working with sprite sheets or when you only want to cast a shadow from a dynamically scaled specific region of an image.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Create an image and draw a solid red ellipse on it to use as our shadow source
Global MyImage = CreateImg(200, 200, #PG_Img_Transparent)
If BeginDraw(OutputImg(MyImage))
  DrawEllipse(100, 100, 80, 50, RGB(255, 0, 0)) 
  EndDraw()
EndIf

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)
  
    DrawClear(RGB(240, 240, 240), 1) ; Light grey background

    ; 1) Draw the original image for reference
    DrawTxt(CreateText("Original:", "Arial", 12), 20, 20, RGB(0,0,0))
    DrawImg(MyImage, 20, 40)

    ; 2) Use DrawImgShadowEx to draw a shadow of ONLY the right half of the image
    ; Source Rect: x=100, y=0, width=100, height=200
    ; Dest Rect: dx=250, dy=40, dWidth=100, dHeight=200
    ; Shadow config: Blur=15, Spread=2, Color=DarkBlue, Opacity=0.8, xOffset=15, yOffset=15
    DrawTxt(CreateText("ShadowEx (Right Half):", "Arial", 12), 250, 20, RGB(0,0,0))
    DrawImgShadowEx(MyImage, 100, 0, 100, 200, 250, 40, 100, 200, 15, 2, RGB(0, 0, 150), 0.8, 15, 15)
    
    ; Draw the exact same image portion on top to see the shadow casting correctly
    DrawImgEx(MyImage, 100, 0, 100, 200, 250, 40, 100, 200, 1.0)
    
EndProcedure

MyWindow = CreateWindow(0, 0, 420, 280, "DrawImgShadowEx Example")

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

FreeImg(MyImage)
StopProGUI()

See Also

DrawImgShadow, DrawImgShadowInset, DrawImgShadowInsetEx, DrawImgEx, BeginDraw, EndDraw

Supported OS

Windows, Linux