BrushSetOpacity

Syntax

Success = BrushSetOpacity(Brush, Opacity.f)

Description

Sets the overall opacity (alpha value) for the specified brush. This affects the transparency of the entire brush pattern when it is drawn.

Parameters

Brush
The handle of the brush whose opacity is to be set.

Opacity.f
The opacity value, ranging from 0.0 (fully transparent) to 1.0 (fully opaque).

Return Value

Returns #True if the opacity was successfully set, or #False if the brush handle was invalid. Values outside the 0.0-1.0 range might be clamped internally.

Remarks

This sets a uniform opacity level applied to the entire brush. For gradients with varying opacity, define the opacity at each color stop using CreateBrushGradientLinearEx, CreateBrushGradientRadialEx, or BrushGradientAddColor. The default opacity for new brushes is 1.0.

Example

IncludeFile "ProGUI_PB.pbi"

Global MyBrush

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
  DrawClear(RGB(240, 240, 240), 1)
  ; Draw a background element
  DrawBox(10, 10, 380, 280, RGB(0, 255, 0)) ; Green background
  ; Draw the semi-transparent brush over it
  DrawBoxFill(50, 50, 300, 200, MyBrush)
EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Brush Opacity Example")
MyImage = CreateImg(100, 100, RGB(255, 0, 0)) ; Red image

If MyWindow And MyImage
  MyBrush = CreateBrushImg(MyImage)
  If MyBrush
    ; Set brush to be semi-transparent
    BrushSetOpacity(MyBrush, 0.5)

    AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
    WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

    Repeat
        Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow

    FreeBrush(MyBrush)
  EndIf
  FreeImg(MyImage)
EndIf

StopProGUI()

See Also

BrushReset

Supported OS

Windows, Linux