Code: Select all
; Demo: General purpose transparent drawing in 24 bits
; Authors: Lloyd Gallant (netmaestro): original idea
wilbert: improvements for speed and efficiency
DeclareModule filters
Declare SetTransparentColor(color.l)
Declare TransparentFilter(x, y, sourcecolor.l, targetcolor.l)
EndDeclareModule
Module filters
Global transcolor.l
Procedure SetTransparentColor(color.l)
transcolor.l = color | $FF<<24
EndProcedure
Procedure TransparentFilter(x, y, sourcecolor.l, targetcolor.l)
EnableASM
mov eax, sourcecolor
cmp eax, transcolor
!jne .cont
mov eax, targetcolor
!.cont:
ProcedureReturn
DisableASM
EndProcedure
EndModule
UseModule filters
CreateImage(0, 256,256,24,RGB(255,0,255)) ;Pink is the transparent color
StartDrawing(ImageOutput(0))
Box(96,96,64,64,#Blue)
StopDrawing()
OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowColor(0, #White)
CanvasGadget(0, 180,80,256,256)
StartDrawing(CanvasOutput(0))
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@TransparentFilter())
SetTransparentColor(RGB(255,0,255))
DrawImage(ImageID(0), 0, 0)
StopDrawing()
Repeat : EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow