Attribute VB_Name = "modul_Calaym_Animations"
' Copyright (C) 2006-2010 Jan Vorel
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.

' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

' If you have any questions, suggestions or bug reports about this product,
' contact me: info@ctuser.net; Do not contact me about general B.A.S.I.C.
' language or A.P.I. issues

' This modul contains public functions, variables and callback functions.

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

Public Sub DoAnimateReadDir(ByVal xStep As Long)
  Static xLong1 As Long
  Dim xLong2 As Long
  'Dim xLong3 As Long
  Dim xType1 As RECT
  Dim xhBrush As Long
  Const xADRDMaxLeft = 33
  Const xStepperA = 10&
  Dim xBmp As Long
  Dim xBmpOld As Long
  
  xType1.Bottom = 41&
  xType1.Right = 33&
  
  xBmp = CreateCompatibleBitmapX(32&, 40&)
  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
      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&)
    DoAnimateReadDir 0&
    Call ShowWindow(xStaticIconsHWnd(xStaticIcons_Anim), 1&)
    End If
  End Sub

