AlphaBlendColor

Syntax

Color.l = AlphaBlendColor(Color1, Color2, Alpha)

Description

Calculates a new color by blending Color1 and Color2 together using the specified Alpha level.

Parameters

Color1
The background or destination color in RGB format.

Color2
The foreground or source color in RGB format to blend over Color1.

Alpha
The alpha transparency level to apply to Color2 during the blend, ranging from 0 (fully transparent, returns Color1) to 255 (fully opaque, returns Color2).

Return Value

Returns the resulting blended color in RGB format.

Remarks

This is a utility function often used to manually calculate pre-blended solid colors for performance optimizations or custom drawing routines without relying on the graphics pipeline’s alpha blending.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Blend a 50% opaque Red over a solid Blue background
BlendedColor = AlphaBlendColor(RGB(0, 0, 255), RGB(255, 0, 0), 128)

MyWindow = CreateWindow(0, 0, 300, 200, "AlphaBlendColor Example")

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData)
  DrawClear(RGB(255, 255, 255), 1)
  
  ; Draw boxes to show the color blend
  DrawBox(10, 10, 100, 100, RGB(0, 0, 255), 1) ; Original Background
  DrawBox(120, 10, 100, 100, RGB(255, 0, 0), 1) ; Original Foreground
  DrawBox(65, 120, 100, 50, *UserData, 1) ; Pre-blended Result
EndProcedure

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler(), BlendedColor)
  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

StopProGUI()

Supported OS

Windows, Linux