' Please have your graphics mode set to 24- or 32-bit color in order
' for the palette fading routines to work in AFlib III, as it will not
' work in any other color depth whatsoever.  Thanks so much!!!  ;)
'
'                                              - Adigun Azikiwe Polack


#include "AFlib3_Sprite.bi"
#include "AFlib3_Font.bi"
#include "AFlib3_Palette.bi"
#include "AFlib3_Primitives.bi"
#include "AFlib3_Screen.bi"
#include "AFlib3_Miscellaneous.bi"
#include "AFlib3_Constants.bi"
#include "AFlib3_GraphicsFilter.bi"
#include "AFlib3_Resize2X.bi"



const Scr_horiz = 640
const Scr_vert = 480

ScreenRes Scr_horiz, Scr_vert, 24, 2, 0
WindowTitle "AFlib III -- C64 Palette Fade-in/Fade-out Test"
SetMouse , , 0


Declare Sub C64_PaletteFadeIn (x as integer, y as integer, image as any ptr, _
                               resize_gfx as integer, LowRes_type as integer)
Declare Sub C64_PaletteFadeOut (x as integer, y as integer, image as any ptr, _
                                resize_gfx as integer, LowRes_type as integer)
                                
Declare Sub PressKey_Notice

Dim Shared as Integer PalColList_X, PalColList_Y, PalPos_X, PalPos_Y, Pal_Size, FadeCTRL
Dim Shared as Integer PicSetupNum
Dim as Any Ptr Scr_ColChanger
Dim as Any Ptr C64TestIma(1 to 64) 

For PicSetupNum = 1 to 64
  C64TestIma(PicSetupNum) = ImageCreate(320, 200)
  BLoad "AF3_PaletteC64_" + str(PicSetupNum) + ".bmp", C64TestIma(PicSetupNum)
Next


ScreenSet 1, 0

For PicSetupNum = 1 to 64
  C64_PaletteFadeIn 0, 19, C64TestIma(PicSetupNum), 1, 0
  PressKey_Notice
  Sleep
  C64_PaletteFadeOut 0, 19, C64TestIma(PicSetupNum), 1, 0
Next

For PicSetupNum = 1 to 64
  ImageDestroy C64TestIma(PicSetupNum)
Next

AFlibIII_EndProgram



Sub C64_PaletteFadeIn (x as integer, y as integer, image as any ptr, _
                       resize_gfx as integer, LowRes_type as integer)
  For FadeCTRL = -7 to 0 step 1
    AFlibIII_ClearDisplay RGB(1, 1, 1)
    
    AFlibIII_SprBlit x, y, image   
    
    If resize_gfx >= 1 then AFlibIII_Resize2X_640x480
    Select Case LowRes_type
      Case 1: AFlibIII_LowRes_vert
      Case 2: AFlibIII_LowRes_horiz
    End Select
    
    AFlibIII_FadeC64 , FadeCTRL
    AFlibIII_Scanlines_H
    
    AFlibIII_DisplayPal_16Col 7, 7, 1  '<---- Displays the 16-color Commodore 64 Palette.
    
    'AFlibIII_MakeMonochrome 
    ScreenCopy 1, 0
    AFlibIII_CustomSync fps5
  Next
  AFlibIII_ClearKeyBuffer
End Sub

Sub C64_PaletteFadeOut (x as integer, y as integer, image as any ptr, _
                        resize_gfx as integer, LowRes_type as integer)
  For FadeCTRL = 0 to -7 step -1
    AFlibIII_ClearDisplay RGB(1, 1, 1)
    
    AFlibIII_SprBlit x, y, image   
    
    If resize_gfx >= 1 then AFlibIII_Resize2X_640x480
    Select Case LowRes_type
      Case 1: AFlibIII_LowRes_vert
      Case 2: AFlibIII_LowRes_horiz
    End Select
    
    AFlibIII_FadeC64 , FadeCTRL
    AFlibIII_Scanlines_H

    AFlibIII_DisplayPal_16Col 7, 7, 1  '<---- Displays the 16-color Commodore 64 Palette.

    'AFlibIII_MakeMonochrome 
    ScreenCopy 1, 0
    AFlibIII_CustomSync fps5
  Next
  AFlibIII_ClearKeyBuffer
End Sub

Sub PressKey_Notice
  Dim SetMessage as String
  If PicSetupNum >= 64 then
    SetMessage = "Press any key to end."
  else
    SetMessage = "Press any key, please."
  End if
  
  AFlibIII_Print SetMessage, 1, 464, 1, 1, C64col(12), 0, 2, 7
  AFlibIII_Print SetMessage, 1, 465, 1, 1, C64col(12), 0, 2, 7
  AFlibIII_Print SetMessage, 0, 465, 1, 1, C64col(12), 0, 2, 7
  AFlibIII_Print SetMessage, 0, 464, 1, 1, C64col(1), 0, 2, 7
  ScreenCopy 1,0
End Sub