Code: Select all
Global OldProc
Global BackBuffer = CreateImage(#PB_Any, 512, 512, 24)
; Procedure Blend(source, target)
; R = Red(source)
; B = Blue(source)
; G = Green(source)
;
; R2 = Red(target)
; B2 = Blue(target)
; G2 = Green(target)
;
; Alpha = Alpha(source)
;
; R = ((R*Alpha)/255) + ((R2*(255-Alpha)) / 255)
; G = ((G*Alpha)/255) + ((G2*(255-Alpha)) / 255)
; B = ((B*Alpha)/255) + ((B2*(255-Alpha)) / 255)
;
; ProcedureReturn RGB(R, G, B)
; EndProcedure
Procedure Callback(WindowID, Message, wParam, lParam)
Protected Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_ERASEBKGND
; Debug "erase bkgnd"
Result = 1
Case #WM_PAINT
hDC_b = StartDrawing(ImageOutput(BackBuffer))
Box(0, 0, 512, 512, GetSysColor_(#COLOR_3DFACE))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(0), 0, 0)
hDC_w = BeginPaint_(WindowID, @paint.PAINTSTRUCT)
BitBlt_(hDC_w, 0, 0, 512, 512, hDC_b, 0, 0, #SRCCOPY)
EndPaint_(WindowID, @paint)
StopDrawing()
; Alternate blend code, without backbuffer, but too slow
; hDC_w = BeginPaint_(WindowID, @paint.PAINTSTRUCT)
; bg = GetSysColor_(#COLOR_3DFACE)
; hDC_i = StartDrawing(ImageOutput(0))
; DrawingMode(#PB_2DDrawing_AllChannels)
; For x = 0 To 511
; For y = 0 To 511
; color = Blend(Point(x, y), bg)
; SetPixel_(hDC_w, x, y, color)
; Next
; Next
; StopDrawing()
; EndPaint_(WindowID, @paint)
Result = 0
EndSelect
If Result = #PB_ProcessPureBasicEvents
ProcedureReturn CallWindowProc_(OldProc, WindowID, Message, wParam, lParam)
Else
ProcedureReturn Result
EndIf
EndProcedure
CreateImage(0, 512, 512, 32)
Procedure RotateImage()
Static Angle.d = 0
Angle + 0.5
Angle = Mod(Angle, 360)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_Gradient)
GradientColor(0, RGBA(192, 128, 0, 255))
GradientColor(1, RGBA(192, 128, 0, 0))
ConicalGradient(256, 256, Angle)
Box(0, 0, 512, 512)
StopDrawing()
EndProcedure
#W = 600
#H = 600
OpenWindow(0, 0, 0, #W, #H, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
AddWindowTimer(0, 0, 30)
SmartWindowRefresh(0, 1) ; !!
hwnd = GadgetID(0)
OldProc = SetWindowLongPtr_(hwnd, #GWLP_WNDPROC, @Callback())
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
RotateImage()
SetGadgetState(0, ImageID(0))
t2 = ElapsedMilliseconds()-t
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver