Page 1 of 1

desktop disc chase : AddWindowTimer & windows transparent

Posted: Sat Aug 15, 2009 2:02 am
by eddy
It's a mod of netmaestro's example : http://www.purebasic.fr/english/viewtopic.php?t=38560
ESC or click on the disc to close.

Code: Select all

#w=65
#d=#w/2
imgDisc=CreateImage(0, #w, #w)
StartDrawing(ImageOutput(0))
   ;set transparency
   DrawingMode(#PB_2DDrawing_AlphaChannel)
   Box(0, 0, #w, #w, RGBA(0, 0, 0, 0))
   ;disc colors
   DrawingMode(#PB_2DDrawing_Gradient |#PB_2DDrawing_AlphaBlend )
   GradientColor(0.0, RGBA(255, 255, 255, 255))
   GradientColor(0.9, RGBA(255, 200, 66, 255))
   GradientColor(1.0, RGBA(240, 155, 33, 255))
   CircularGradient(#d, #d, #d)
   Circle(#d, #d, #d)
StopDrawing()

winMaskColor=RGB(0, 0, 0)
win=OpenWindow(0, 0, 0, #w, #w, "", #PB_Window_ScreenCentered | #PB_Window_BorderLess | #PB_Window_Invisible)

;window transparency mask
SetWindowColor(0, winMaskColor)
SetWindowLongPtr_(win, #GWL_EXSTYLE, GetWindowLongPtr_(win, #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(win, winMaskColor, 255, #LWA_COLORKEY)

;shortcut, timer, gadget (to display colored disc)
AddWindowTimer(0, 100, 10)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 1)
ImageGadget(2, 0, 0, 0, 0, imgDisc)

HideWindow(0, #False)
StickyWindow(0, #True)
Repeat
   e=WaitWindowEvent()
   Select e
      Case #PB_Event_Menu, #PB_Event_Gadget
         End
      Case #PB_Event_Timer
         If EventTimer()=100
            x=WindowX(0)
            y=WindowY(0)
            mx=DesktopMouseX()-#d
            my=DesktopMouseY()-#d
            If x<mx : x+1 : EndIf
            If x>mx : x-1 : EndIf
            If y<my : y+1 : EndIf
            If y>my : y-1 : EndIf
            ResizeWindow(0, x, y, #PB_Ignore, #PB_Ignore)
         EndIf
   EndSelect
ForEver