Attribute VB_Name = "modul_Calaym_Animations"
' Calaym - Media player GUI for sound systems
' Copyright (C) 2002-2012 Jan Vorel
'
' You can redistribute the official software packages under the terms of the
' User-friendly Open-source License Version 1.00, published by Jan Vorel
'
' You can use this software under the terms of the
' User-friendly Software License Version 1.00, published by Jan Vorel
'
' You should have received copies of the licenses along with this program. If
' not, contact the author.
'
' If you want to use or distribute this software under a different license, ask
' the author.
'
' The software is provided "as is" without warrenty of any kind. The Licensor
' cannot be held responsible for any damage caused by using, extracting or
' installing the software.

Option Explicit
Option Base 0


Public OldAnimIcon As Long
Public xDoAnimColor1 As Long
Public xDoAnimColor2 As Long
Public xDoAnimColor3 As Long
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function FrameRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long

Public Sub DoAnimateReadDir(ByVal xStep As Long)
  Static xLong1 As Long
  Dim xLong2 As Long
  'Dim xLong3 As Long
  Dim xType1 As RECT
  Dim xType2 As RECT
  Dim xhBrush As Long
  Const xADRDMaxLeft = 33
  Const xStepperA = 10&
  Dim xBmp As Long
  Dim xBmpOld As Long
  
  xType1.Bottom = AnimHeightAnimProg
  xType1.Right = 33&
  
  xBmp = CreateCompatibleBitmapX(32&, AnimHeightAnimProg)
  If Not xBmp = 0& Then
    xBmpOld = SelectObject(xSharedDC, xBmp)
    Call FillRect(xSharedDC, xType1, 6&)
    If Not OldAnimIcon = 0& Then Call DrawIcon(xSharedDC, 0&, 0&, OldAnimIcon)
    
    xType1.Top = 34&
    xType1.Bottom = 38&
    
    
    If xPStateIconSndcard Or xPStateIconStartup Or xAutoDoing Or AllTears_TypesCount > AnimateForTearCountX Or xForceAnimationNow Or (xLoadingStream And Not xClassicBlockingOnLoad) Then
      If xIsActiveBW Then
        xhBrush = CreateSolidBrush(xDoAnimColor1)
        If Not xhBrush = 0& Then
          xType2.Top = 41&
          xType2.Bottom = 46&
          xType2.Left = 2&
          xType2.Right = 30&
          Call FrameRect(xSharedDC, xType2, xhBrush)
          Call DeleteObject(xhBrush)
          xhBrush = CreateSolidBrush(xDoAnimColor2)
          If Not xhBrush = 0& Then
            xType2.Left = 3&
            xType2.Top = 42&
            xType2.Bottom = 45&
            xType2.Right = xCurBWPos / xDefBWDifL * 27& + 3&
            Call FillRect(xSharedDC, xType2, xhBrush)
            Call TaskbarProgress_SetProgressValue(MainHWnd, CCur(xCurBWPos), xDefBWDifC)
            Call DeleteObject(xhBrush)
            End If
          End If
        End If
      
      
      xhBrush = CreateSolidBrush(xDoAnimColor3)
      If Not xhBrush = 0& Then
        For xLong2 = xLong1 + 5& To (xLong1 + xStepperA)
          xType1.Left = 2& + (xLong2 Mod xStepperA) * 6&
          If xType1.Left < xADRDMaxLeft Then
            xType1.Right = xType1.Left + 4&
            Call FillRect(xSharedDC, xType1, xhBrush)
            End If
          Next
        Call DeleteObject(xhBrush)
        End If
      If xLong1 < 5& Or xLong1 > xStepperA - 6& Then
        xhBrush = CreateSolidBrush(xDoAnimColor2)
        If Not xhBrush = 0& Then
          xType1.Left = 2& + ((xLong1 + 1&) Mod xStepperA) * 6&
          If xType1.Left < xADRDMaxLeft Then
            xType1.Right = xType1.Left + 4&
            Call FillRect(xSharedDC, xType1, xhBrush)
            End If
          xType1.Left = 2& + ((xLong1 + 5&) Mod xStepperA) * 6&
          If xType1.Left < xADRDMaxLeft Then
            xType1.Right = xType1.Left + 4&
            Call FillRect(xSharedDC, xType1, xhBrush)
            End If
          Call DeleteObject(xhBrush)
          End If
        End If
      If xLong1 < 4& Or xLong1 > xStepperA - 5& Then
        xhBrush = CreateSolidBrush(xDoAnimColor1)
        If Not xhBrush = 0& Then
          xType1.Left = 2& + ((xLong1 + 2&) Mod xStepperA) * 6&
          If xType1.Left < xADRDMaxLeft Then
            xType1.Right = xType1.Left + 4&
            Call FillRect(xSharedDC, xType1, xhBrush)
            End If
          xType1.Left = 2& + ((xLong1 + 4&) Mod xStepperA) * 6&
          If xType1.Left < xADRDMaxLeft Then
            xType1.Right = xType1.Left + 4&
            Call FillRect(xSharedDC, xType1, xhBrush)
            End If
          Call DeleteObject(xhBrush)
          End If
        End If
      xType1.Left = 2& + ((xLong1 + 3&) Mod xStepperA) * 6&
      If xType1.Left < xADRDMaxLeft Then
        xhBrush = CreateSolidBrush(FLineColor)
        If Not xhBrush = 0& Then
          xType1.Right = xType1.Left + 4&
          Call FillRect(xSharedDC, xType1, xhBrush)
          Call DeleteObject(xhBrush)
          End If
        End If
      Else
      xhBrush = CreateSolidBrush(xDoAnimColor3)
      If Not xhBrush = 0& Then
        For xLong2 = 0& To 4&
          xType1.Left = 2& + xLong2 * 6&
          If xType1.Left < xADRDMaxLeft Then
            xType1.Right = xType1.Left + 4&
            Call FillRect(xSharedDC, xType1, xhBrush)
            End If
          Next
        Call DeleteObject(xhBrush)
        End If
      End If
    xLong1 = (xLong1 + xStep) Mod xStepperA
    Call SelectObject(xSharedDC, xBmpOld)
    
    Call SendMessage(xStaticIconsHWnd(xStaticIcons_Anim), &H172&, 0&, xBmp)
    If Not xStaticIconsBMP(xStaticIcons_Anim) = 0& Then
      DeleteObject xStaticIconsBMP(xStaticIcons_Anim)
      End If
    xStaticIconsBMP(xStaticIcons_Anim) = xBmp
    End If
  End Sub
  


Public Sub DoAnimateSetIcon(ByVal IconID As Long)
  If Not OldAnimIcon = 0& Then DestroyIcon OldAnimIcon
  
  If IconID = -1& Then
    OldAnimIcon = 0&
    Call ShowWindow(xStaticIconsHWnd(xStaticIcons_Anim), 0&)
    If CurShownToolTip = xStaticIcons_Anim Then
      CurShownToolTip = -1&
      If ToolTipInitTime = -1& Then ShowWindow xStaticIconsHWnd(xStaticIcons_ToolTip), 0&
      End If
    Else
    OldAnimIcon = LoadResEx_Icon(IconID, 32&)
    Call DoAnimateReadDir(0&)
    Call ShowWindow(xStaticIconsHWnd(xStaticIcons_Anim), 1&)
    End If
  End Sub

