EnableExplicit

#RenderMainInfoMySelf = 0
#MaxTick = $20000

#DataBlockLen = 32;

Macro DimColorASMPrepared()
  FLD X1
  MOV eax, X2

      XOR ecx, ecx
      PUSH ecx
      MOV edx, esp
      PUSH eax
      MOV eax, edx
      DEC eax
      MOV [eax], cl
      DEC eax
      FILD word [eax]
      FMUL st, st1
      FISTP word [edx]
      MOV [eax], byte cl
      DEC eax
      INC edx
      
      FILD word [eax]
      FMUL st, st1
      FISTP word [edx]
      MOV [eax], byte cl
      DEC eax
      INC edx
      
      FILD word [eax]
      FMUL st, st1
      FISTP word [edx]
      MOV eax, [eax + 3]
      BSWAP eax
      ADD esp, 8
      MOV X2, eax
      FSTP ST0
  EndMacro


; Copyright (C) 2007-2011 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





; Wavedata To spectrum Data conversation is based on a free Visual Basic 6
; example by Ulli "Mühlenweg" <umgedv@yahoo.com>, which can be found at
; http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=65007&lngWId=1




Global Dim TextRenderPtrData.l(50)
Global Dim TextRenderColor.l(50)
Global Dim TextRenderFontSize.l(50)
Global TextRenderCount.l
;Global ExcludeBottomP.l
;Global ExcludeTopM.l

Procedure InitMe()
  Define.l xLong1
  Define.l xLong2

;  Color, PosX, PosY, FadeOutTicks, LenLine, ptrLine

  For xLong1 = ?CodeLinesBegin To ?CodeLinesEnd - #DataBlockLen Step #DataBlockLen
    xLong2 = PeekL(xLong1 + 28)
    If xLong2
      PokeL(xLong1 + 24, lstrlen_(xLong2))
      EndIf
    Next
  EndProcedure

InitMe()


Global Dim hFontCode.l(49)
#HideText = 0 ; not very optimized!!! - for testing
#AnimPlugin = 2
#RenderSelf = 2
#PSFMode = 0
#FixedUse = 0 ; 1
#SpectrumArraySize = 3
#MMonitor = 1
#WarnMsg = 0
#HAlign = 1
#StereoBMP = 1
#OnPicRender = 0



CompilerIf #MaxTick
Declare RenderSelf(SkipFrame.l, xElapsedTicks.l)
CompilerElse
Declare RenderSelf(SkipFrame.l)
CompilerEndIf

Declare ResizedSelf()

Global xWinRect.RECT
Global xWinRect2.RECT

Global MaxInit.l
MaxInit = 5

#MaxTickAND = #MaxTick - 1
#MaxTickExp = #MaxTick * #MaxTick / 100

IncludeFile "LSDemo.pb"





Procedure RenderSelfPart(SkipFrame.l, xElapsedTicks.l)
  Global xMyTicks
  Global Inited
  
  Define.l xLong1
  Define.f X1
  Define.f X3
  Define.l xLong2
  #TicksToNextLine = $400
  #TicksToFadedOut = $800
  #TicksToFadedIn = $200

  If Not Inited
    xElapsedTicks = 0
    Inited = #True
    EndIf
    

  
  Define.l myMaxTicks = (?CodeLinesEnd - ?CodeLinesBegin) / #DataBlockLen
  myMaxTicks * #TicksToNextLine
  xMyTicks = (xMyTicks + xElapsedTicks) % myMaxTicks



  For xLong1 = ?CodeLinesBegin To ?CodeLinesEnd - #DataBlockLen Step #DataBlockLen


;  Color, PosX, PosY, FadeOutTicks, HeightPX, ptrLine
    xLong2 = (xLong1 - ?CodeLinesBegin) / #DataBlockLen * #TicksToNextLine

;If xLong1 = ?CodeLinesBegin + #DataBlockLen
;Debug Str(xLong2) + " / " + Str(xMyTicks) + " / " + Str(MyMaxTicks)
;EndIf


    xLong2 = xMyTicks - xLong2
    If xLong2 < 0
      xLong2 = xLong2 + myMaxTicks
      EndIf
    
    If xLong2 > myMaxTicks / 2
      xLong2 = myMaxTicks  - xLong2
      X1 = (#TicksToFadedIn - xLong2) / #TicksToFadedIn
      X3 = -(1-X1)
      Else
      X1 = (#TicksToFadedOut - xLong2) / #TicksToFadedOut
      X3 = (1-X1)
      EndIf
    If X1 > 0
      ;Define.f X1 = xLong2 / #TicksToFadedOut
      Define.l X2 = $ffffff
      DimColorASMPrepared()
      TextRenderPtrData(TextRenderCount) = xLong1
      TextRenderColor(TextRenderCount) = X2
      
      xLong2 = (PeekL(xLong1 + 4) + 5) * xWinRect\Right / 110 + xWinRect\Right * X3 / 5
      X2 = PeekL(xLong1 + 8)
      ;X3 = 0
      If X2 < 50
        X2 = (X2 + 5)  * ExcludeTop / 60 + X3 * ExcludeTop / 30
        Else
        X2 = (X2 - 45) * ExcludeTop / 60 + X3 * ExcludeTop / 30 + ExcludeBottom
        EndIf
      Debug X3
      If X3 < 0
        X3 = -X3
        EndIf
      TextRenderFontSize(TextRenderCount) = 49 - (X3 * 48)
      PokeL(xLong1 + 12, xLong2)
      PokeL(xLong1 + 16, X2)
      TextRenderCount + 1
      EndIf
    Next
  EndProcedure













CompilerIf #MaxTick
Procedure RenderSelf(SkipFrame.l, xElapsedTicks.l)
CompilerElse
Procedure RenderSelf(SkipFrame.l)
CompilerEndIf
  Define.l xLong1
;  Define.l hBrush
  Define.l xLong2
  Define.l xOldFont
  CompilerIf #MaxTick
    CompilerElse
    Static OldTick.l
    CompilerEndIf

  If SkipFrame
    If Not MaxInit = 100
      MaxInit + 5
      EndIf
    EndIf

  xLong1 = (GetTickCount_() & #MaxTickAND)


  CompilerIf #MaxTick
    RenderSelfPart(SkipFrame, xElapsedTicks)
    CompilerElse
    RenderSelfPart(SkipFrame, (xLong1 + #MaxTick - OldTick) & #MaxTickAND)
    OldTick = xLong1
    CompilerEndIf

    
  If hBrush
    FillRect_(xMainDC, @xWinRect, hBrush)
    FillRect_(xMainDC, @xWinRect2, hBrush)
;    DeleteObject_(hBrush)
    EndIf

  If TextRenderCount
    TextRenderCount - 1
  ;  Me.Cls
  
    xLong1 = 0
    xOldFont = GetCurrentObject_(xMainDC, #OBJ_FONT)
    If xOldFont
      For xLong1 = 0 To TextRenderCount
        If SelectObject_(xMainDC, hFontCode(TextRenderFontSize(xLong1)))
          If SetTextColor_(xMainDC, TextRenderColor(xLong1))
            xLong2 = TextRenderPtrData(xLong1)
;  Color, PosX, PosY, FadeOutTicks, LenLine, ptrLine
            TextOut_(xMainDC, PeekL(xLong2 + 12), PeekL(xLong2 + 16), PeekL(xLong2 + 28), PeekL(xLong2 + 24))
            EndIf
          EndIf
        Next
      SelectObject_(xMainDC, xOldFont)
      EndIf
    EndIf
;hBmpInfoSelfBkNow =
  TextRenderCount = 0
  EndProcedure

Procedure ResizedSelf()
  ;Define.RECT xType1
  Define.LOGFONT xType1
  Define.l xLong1

  GetClientRect_(xMainHWnd, @xWinRect)

  FillRect_(xMainDC, @xWinRect, hBrush)

  xWinRect\Right = xWinRect\Right - xWinRect\Left
  xWinRect\Bottom = xWinRect\Bottom - xWinRect\Top
  xWinRect\Left = 0
  xWinRect\Top = 0
 

  ;ExcludeBottomP = ExcludeBottom + 1
  ;ExcludeTopM.l = ExcludeTop - 1

  xWinRect2\Bottom = xWinRect\Bottom
  xWinRect2\Right = xWinRect\Right
  xWinRect\Bottom = ExcludeTop + #BorderForImage
  xWinRect2\Top = ExcludeBottom - #BorderForImage


  xType1\lfWeight = 450
  xType1\lfQuality = #PROOF_QUALITY
  PokeS(@xType1\lfFaceName, LoadResStringA(15), 32)
  For xLong1 = 1 To 49
    If hFontCode(xLong1)
      DeleteObject_(hFontCode(xLong1))
      EndIf
    xType1\lfHeight = -xLong1
    hFontCode(xLong1) = CreateFontIndirect_(@xType1)
    Next
  ;StretchSimple = MaxSize / 480 * 3
  EndProcedure


EnableASM

DataSection
;  Color, PosX, PosY, OutX, OutY, FadeOutTicks, LenLine, ptrLine
  CodeLinesBegin:
  !DD 0, 0, 0, 0, 0, 0, 0, 0
  !DD $ff00ff, 20, 00, 0, 0, 0, 0, Line111
  !DD $ff00ff, 30, 16, 0, 0, 0, 0, Line112
  !DD $ff00ff, 20, 32, 0, 0, 0, 0, Line121
  !DD $ff00ff, 30, 48, 0, 0, 0, 0, Line122
  !DD $ff00ff, 20, 50, 0, 0, 0, 0, Line131
  !DD $ff00ff, 30, 66, 0, 0, 0, 0, Line132
  !DD $ff00ff, 20, 82, 0, 0, 0, 0, Line141
  !DD $ff00ff, 30, 98, 0, 0, 0, 0, Line142
  !DD 0, 0, 0, 0, 0, 0, 0, 0
  !DD 0, 0, 0, 0, 0, 0, 0, 0
  !DD $ff00ff, 20, 00, 0, 0, 0, 0, Line211
  !DD $ff00ff, 30, 16, 0, 0, 0, 0, Line212
  !DD $ff00ff, 20, 32, 0, 0, 0, 0, Line221
  !DD $ff00ff, 30, 48, 0, 0, 0, 0, Line222
  !DD $ff00ff, 20, 50, 0, 0, 0, 0, Line231
  !DD $ff00ff, 30, 66, 0, 0, 0, 0, Line232
  !DD $ff00ff, 20, 82, 0, 0, 0, 0, Line241
  !DD $ff00ff, 30, 98, 0, 0, 0, 0, Line242
  !DD 0, 0, 0, 0, 0, 0, 0, 0
  !DD 0, 0, 0, 0, 0, 0, 0, 0
  !DD $ff00ff, 20, 00, 0, 0, 0, 0, Line311
  !DD $ff00ff, 30, 16, 0, 0, 0, 0, Line312
  !DD $ff00ff, 20, 32, 0, 0, 0, 0, Line321
  !DD $ff00ff, 30, 48, 0, 0, 0, 0, Line322
  !DD $ff00ff, 20, 50, 0, 0, 0, 0, Line331
  !DD $ff00ff, 30, 66, 0, 0, 0, 0, Line332
  !DD $ff00ff, 20, 82, 0, 0, 0, 0, Line341
  !DD $ff00ff, 30, 98, 0, 0, 0, 0, Line342
  !DD 0, 0, 0, 0, 0, 0, 0, 0
  CodeLinesEnd:
EndDataSection

DataSection
  !Line111 DB 'Innocent', 0
  !Line112 DB 'I walk in the night', 0
  !Line121 DB 'patient, calm', 0
  !Line122 DB 'and out of your sight', 0
  !Line131 DB 'a stranger', 0
  !Line132 DB 'engrossed in deep thought', 0
  !Line141 DB 'in doubt of', 0
  !Line142 DB 'all things he', 39, 's been taught', 0

  !Line211 DB 'Drops of rain', 0
  !Line212 DB 'like tears on my skin', 0
  !Line221 DB 'reflecting', 0
  !Line222 DB 'the sadness I', 39, 'm in', 0
  !Line231 DB 'from chances', 0
  !Line232 DB 'where I looked away', 0
  !Line241 DB 'and choices', 0
  !Line242 DB "that haunt me each day", 0
  
  !Line311 DB 'My reasons', 0
  !Line312 DB 'are beyond your mind', 0
  !Line321 DB 'with true lies', 0
  !Line322 DB 'your vision I blind', 0
  !Line331 DB 'your fortune', 0
  !Line332 DB 'I shape selflessly', 0
  !Line341 DB 'a future', 0
  !Line342 DB "that you cannot see", 0
  EndDataSection
; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 161
; FirstLine = 158
; Folding = --
; EnableAsm
; EnableXP
; AddResource = LSDemo (CodingTxt).rc