DrawImgShadowInset

Syntax

DrawImgShadowInset(Img, x.d, y.d, Width.d=#PG_Ignore, Height.d=#PG_Ignore, BlurAmount.f=10, Spread.f=0, ShadowColor.l=0, ShadowOpacity.f=1, xOffset.d=0, yOffset.d=0)

Description

Draws an inner (inset) drop shadow over an image, casting the shadow inside the opaque areas of the image. This is extremely useful for creating recessed, pressed, or “cut-out” effects for interface elements.

Parameters

Img
The handle of the source image object (created with CreateImg() or LoadImg()) that defines the alpha mask/shape for the inset shadow.

x.d
The horizontal coordinate to draw the shadow, in device-independent pixels (DIPs). This should typically match the x coordinate of the image being shadowed.

y.d
The vertical coordinate to draw the shadow, in DIPs. This should typically match the y coordinate of the image being shadowed.

Width.d (optional)
The scaled width for the shadow projection. Uses the image’s original width if #PG_Ignore or a negative value is passed. Default is #PG_Ignore.

Height.d (optional)
The scaled height for the shadow projection. Uses the image’s original height if #PG_Ignore or a negative value is passed. Default is #PG_Ignore.

BlurAmount.f (optional)
The amount of gaussian blur to apply to the shadow. Higher values create a softer, more diffused inner shadow. Default is 10.

Spread.f (optional)
The expansion or contraction amount of the shadow. Positive values expand the shadow further inward, while negative values contract it. Default is 0.

ShadowColor.l (optional)
The RGB color of the shadow (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 of the shadow in DIPs. Positive values shift the shadow to the right (simulating a light source from the left). Default is 0.

yOffset.d (optional)
The vertical offset of the shadow in DIPs. Positive values shift the shadow downward (simulating a light source from above). Default is 0.

Return Value

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

Remarks

The DrawImgShadowInset function works by taking the alpha channel of the provided Img and rendering a shadow inside the opaque bounds. It is generally called immediately after drawing the image itself to overlay the inset shadow on top of it. All coordinates and blur amounts are automatically scaled according to the current drawing context’s DPI settings.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Create a transparent image and draw a solid circle on it
Global CircleImg = CreateImg(150, 150, #PG_Img_Transparent)
If BeginDraw(OutputImg(CircleImg))
  ; Draw a solid grey circle
  DrawEllipse(75, 75, 70, 70, RGB(200, 200, 200))
  EndDraw()
EndIf

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)
  
    DrawClear(RGB(255, 255, 255), 1) ; White background

    ; Draw the base image first
    DrawImg(CircleImg, 50, 50)

    ; Draw a soft, dark inner shadow over the image to create a "recessed hole" effect
    ; Offset it slightly down and to the right (xOffset=5, yOffset=5)
    DrawImgShadowInset(CircleImg, 50, 50, #PG_Ignore, #PG_Ignore, 15, 0, RGB(0, 0, 0), 0.8, 5, 5)

EndProcedure

MyWindow = CreateWindow(0, 0, 250, 250, "DrawImgShadowInset 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(CircleImg)

StopProGUI()

See Also

DrawImgShadow, DrawImgShadowEx, DrawImgShadowInsetEx, DrawImg, BeginDraw, EndDraw

Supported OS

Windows, Linux