'=============================================================== 
' A F l i b   I I I   S c a l e / R o t a t e
'                       S c r e e n   B l i t   E x a m p l e 
'=============================================================== 
'This example for AFlib III shows you how to blit, scale, and
'rotate any captured screen with ease!!  I mean, think about it
'now!  ;)
'
'And BEST OF ALL, if you are working in a 24- or 32-bit graphics
'mode, you can even do alpha-blending effects with your scaled/
'rotated captured screens, from 0-255!!!  How phenomenally damn
'AWESOME is that!?  \(^-^)/ !!
'
'Just imagine doing all of this in your project, graphics demo,
'or game in FreeBASIC like never before!!!  One look, and you
'will find out why!!  ^-^=b !
'
'Do enjoy this one richly indeed, and God bless you now!!!  :D 
' 
' 
'                                        - Adigun Azikiwe Polack 
'                               One of the Founders of Aura Flow 
'                                       Developer of "AFlib III"
'---------------------------------------------------------------


#include "AFlib3_Sprite.bi"
#include "AFlib3_Font.bi"
#include "AFlib3_Primitives.bi"
#include "AFlib3_Screen.bi"
#include "AFlib3_Miscellaneous.bi"
#include "AFlib3_Constants.bi"

Declare Sub ShadowPrint ( Byref text as String, _ 
                          Byval x as Integer, Byval y as Integer, _ 
                          Byval col as Integer, Byval sh_x as Integer, _ 
                          Byval sh_y as Integer, Byval sh_col as Integer, _ 
                          Byval chara_id as Integer ) 

Declare Sub Scaler
Declare Sub Rotator
Declare Sub TranslucentFader
Declare Sub ClearScaleAndRotator
  

'========================================================================== 
'/////// S T A R T   O F   M A I N   P O R T I O N 
'========================================================================== 

Dim as Integer GFX_x, GFX_y
Dim as Integer BitDepth
Dim Shared as Single Rotate, ScaleX, ScaleY, FlipX, FlipY
Dim Shared as Integer ScaleX_ctrl, ScaleY_ctrl, BlitMul, BlitType
Dim Shared as Integer Transluce, Transluce_ctrl
Dim as any ptr CustomBuffer, AF3Sprite

ScreenRes 424, 96 , , 0
Windowtitle "AFlib III -- Screen Scaling/Rotation Test"
Color 15, 1: ? "          Please select your color depth!!!          "
Locate 4: Color 15, 0
Locate , 17: Color 10: ? "[1] ";: Color 14: ? "- 15-bit color": ?
Locate , 17: Color 10: ? "[2] ";: Color 14: ? "- 16-bit color": ?
Locate , 17: Color 10: ? "[3] ";: Color 14: ? "- 24-bit color": ?
Locate , 17: Color 10: ? "[4] ";: Color 14: ? "- 32-bit color"

Do
  Select case Inkey$
    Case "1": BitDepth = 15: Exit Do
    Case "2": BitDepth = 16: Exit Do
    Case "3": BitDepth = 24: Exit Do
    Case "4": BitDepth = 32: Exit Do
  End Select
Loop

ScreenRes 640, 480, BitDepth, 2, 0, 60
ScreenInfo GFX_x, GFX_y

SetMouse , , 0

'---------------------------------------------------- 
ScreenSet 1, 0 
AF3Sprite = imagecreate( 480, 178 )
bload "AF3_logo512x384.bmp", AF3Sprite

AFlibIII_PrepareCharTrans 0, 0
AFlibIII_DisplayAllChars 0, 0, 0, &hffffff, 0, 4 
AFlibIII_OptimizeFontSet 0, 0, 1 
ScreenSet 0, 0 
'---------------------------------------------------- 

CustomBuffer = imagecreate( GFX_x - 45, GFX_y - 45 )

AFlibIII_PrepareScreenTrans '<--- This command automatically fills the main screen up with our main transparent
                            '     color -- RGB (255, 0, 255) -- for 15-, 16-, 24-, and 32-bit modes!!!

If BitDepth >= 24 then
  For BlitMul = 0 to 240 step 1
    AFlibIII_Line 0, (BlitMul), GFX_x, (BlitMul), rgba(255 - Blitmul, 255 - Blitmul, 255 - Blitmul, 255 - Blitmul)
    AFlibIII_Line 0, (GFX_y - BlitMul), GFX_x, (GFX_y - BlitMul), rgba(255 - Blitmul, 255 - Blitmul, 255 - Blitmul, 255 - Blitmul)
  Next
End if

For BlitMul = 0 to 70
  AFlibIII_Globe int(rnd(1) * GFX_x) + 1, int(rnd(1) * GFX_y) + 1, (int(rnd(1) * 50) + 1) / 10, int(rnd(1) * 70) + 30, int(rnd(1) * &hffffff) + 1, int(rnd(1) * &hffffff) + 1, int(rnd(1) * 80) + 1, 255
Next

AFlibIII_CaptureScreen 1
ShadowPrint "Captured our screen now for this test!!", 0, 0, rgb(255,255,255), 1, 1, rgb(128,128,128), 1

Sleep 6000
AFlibIII_ClearDisplay RGB(0, 0, 0)
ScreenSet 1, 0

AFlibIII_ClearKeyBuffer


For BlitType = 0 to 1
  ClearScaleAndRotator

  Do
    If BlitType = 1 then
      AFlibIII_ClearDisplay rgb(0, 0, 35)
      AFlibIII_ClearDisplay rgb(0,0,144), CustomBuffer
      Line CustomBuffer, (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite, CustomBuffer
      AFlibIII_BlitScreen_rotate 0, 0, 1, Rotate, FlipX, FlipY, Transluce, , CustomBuffer
      Put (30, 30), CustomBuffer, pset
      ShadowPrint "(Blitting to a custom buffer here!!)", 0, 24, rgb(36,255,145), 1, 1, rgb(4,28,12), 1
    else
      AFlibIII_ClearDisplay rgb(0,0,144)
      Line (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite
      AFlibIII_BlitScreen_rotate 0, 0, 1, Rotate, FlipX, FlipY, Transluce
    end if

    Rotator
    TranslucentFader
    ShadowPrint "Now testing", 0, 0, rgb(255,255,255), 1, 1, rgb(128,128,128), 1
    ShadowPrint "AFlibIII_BlitScreen_rotate...", 24, 8, rgb(255,255,182), 1, 1, rgb(85,85,16), 1
    AFlibIII_CustomSync fps_OPTIMAL
    ScreenCopy
  Loop while inkey$ = ""

  ClearScaleAndRotator

  Do
    If BlitType = 1 then
      AFlibIII_ClearDisplay rgb(0, 0, 35)
      AFlibIII_ClearDisplay rgb(0,0,144), CustomBuffer
      Line CustomBuffer, (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite, CustomBuffer
      AFlibIII_BlitScreen_rotate_solid 0, 0, 1, Rotate, FlipX, FlipY, Transluce, CustomBuffer
      Put (30, 30), CustomBuffer, pset
      ShadowPrint "(Blitting to a custom buffer here!!)", 0, 24, rgb(36,255,145), 1, 1, rgb(4,28,12), 1
    else
      AFlibIII_ClearDisplay rgb(0,0,144)
      Line (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite
      AFlibIII_BlitScreen_rotate_solid 0, 0, 1, Rotate, FlipX, FlipY, Transluce
    end if

    Rotator
    TranslucentFader
    ShadowPrint "Now testing", 0, 0, rgb(255,255,255), 1, 1, rgb(128,128,128), 1
    ShadowPrint "AFlibIII_BlitScreen_rotate_solid...", 24, 8, rgb(255,255,182), 1, 1, rgb(85,85,16), 1
    AFlibIII_CustomSync fps_OPTIMAL
    ScreenCopy
  Loop while inkey$ = ""

  ClearScaleAndRotator

  Do
    If BlitType = 1 then
      AFlibIII_ClearDisplay rgb(0, 0, 35)
      AFlibIII_ClearDisplay rgb(0,0,144), CustomBuffer
      Line CustomBuffer, (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite, CustomBuffer
      AFlibIII_BlitScreen_scale 0, 0, 1, ScaleX, ScaleY, FlipX, FlipY, Transluce, , CustomBuffer
      Put (30, 30), CustomBuffer, pset
      ShadowPrint "(Blitting to a custom buffer here!!)", 0, 24, rgb(36,255,145), 1, 1, rgb(4,28,12), 1
    else
      AFlibIII_ClearDisplay rgb(0,0,144)
      Line (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite
      AFlibIII_BlitScreen_scale 0, 0, 1, ScaleX, ScaleY, FlipX, FlipY, Transluce
    end if

    Scaler
    TranslucentFader
    ShadowPrint "Now testing", 0, 0, rgb(255,255,255), 1, 1, rgb(128,128,128), 1
    ShadowPrint "AFlibIII_BlitScreen_scale...", 24, 8, rgb(255,255,182), 1, 1, rgb(85,85,16), 1
    AFlibIII_CustomSync fps_OPTIMAL
    ScreenCopy
  Loop while inkey$ = ""

  ClearScaleAndRotator

  Do
    If BlitType = 1 then
      AFlibIII_ClearDisplay rgb(0, 0, 35)
      AFlibIII_ClearDisplay rgb(0,0,144), CustomBuffer
      Line CustomBuffer, (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite, CustomBuffer
      AFlibIII_BlitScreen_scale_solid 0, 0, 1, ScaleX, ScaleY, FlipX, FlipY, Transluce, CustomBuffer
      Put (30, 30), CustomBuffer, pset
      ShadowPrint "(Blitting to a custom buffer here!!)", 0, 24, rgb(36,255,145), 1, 1, rgb(4,28,12), 1
    else
      AFlibIII_ClearDisplay rgb(0,0,144)
      Line (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite
      AFlibIII_BlitScreen_scale_solid 0, 0, 1, ScaleX, ScaleY, FlipX, FlipY, Transluce
    end if

    Scaler
    TranslucentFader
    ShadowPrint "Now testing", 0, 0, rgb(255,255,255), 1, 1, rgb(128,128,128), 1
    ShadowPrint "AFlibIII_BlitScreen_scale_solid...", 24, 8, rgb(255,255,182), 1, 1, rgb(85,85,16), 1
    AFlibIII_CustomSync fps_OPTIMAL
    ScreenCopy
  Loop while inkey$ = ""

  ClearScaleAndRotator

  Do
    If BlitType = 1 then
      AFlibIII_ClearDisplay rgb(0, 0, 35)
      AFlibIII_ClearDisplay rgb(0,0,144), CustomBuffer
      Line CustomBuffer, (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite, CustomBuffer
      AFlibIII_BlitScreen_scalerotate 0, 0, 1, ScaleX, ScaleY, Rotate, FlipX, FlipY, Transluce, , CustomBuffer
      Put (30, 30), CustomBuffer, pset
      ShadowPrint "(Blitting to a custom buffer here!!)", 0, 24, rgb(36,255,145), 1, 1, rgb(4,28,12), 1
    else
      AFlibIII_ClearDisplay rgb(0,0,144)
      Line (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite
      AFlibIII_BlitScreen_scalerotate 0, 0, 1, ScaleX, ScaleY, Rotate, FlipX, FlipY, Transluce
    end if

    Scaler
    Rotator
    TranslucentFader
    ShadowPrint "Now testing", 0, 0, rgb(255,255,255), 1, 1, rgb(128,128,128), 1
    ShadowPrint "AFlibIII_BlitScreen_scalerotate...", 24, 8, rgb(255,255,182), 1, 1, rgb(85,85,16), 1
    AFlibIII_CustomSync fps_OPTIMAL
    ScreenCopy
  Loop while inkey$ = ""

  ClearScaleAndRotator

  Do
    If BlitType = 1 then
      AFlibIII_ClearDisplay rgb(0, 0, 35)
      AFlibIII_ClearDisplay rgb(0,0,144), CustomBuffer
      Line CustomBuffer, (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite, CustomBuffer
      AFlibIII_BlitScreen_scalerotate_solid 0, 0, 1, ScaleX, ScaleY, Rotate, FlipX, FlipY, Transluce, CustomBuffer
      Put (30, 30), CustomBuffer, pset
      ShadowPrint "(Blitting to a custom buffer here!!)", 0, 24, rgb(36,255,145), 1, 1, rgb(4,28,12), 1
    else
      AFlibIII_ClearDisplay rgb(0,0,144)
      Line (40, 40)-(GFX_x - 40, GFX_y - 40), rgb(0,25,25), bf
      AFlibIII_SprBlit_alpha 80, 160, 196, AF3Sprite
      AFlibIII_BlitScreen_scalerotate_solid 0, 0, 1, ScaleX, ScaleY, Rotate, FlipX, FlipY, Transluce
    end if

    Scaler
    Rotator
    TranslucentFader
    ShadowPrint "Now testing", 0, 0, rgb(255,255,255), 1, 1, rgb(128,128,128), 1
    ShadowPrint "AFlibIII_BlitScreen_scalerotate_solid...", 24, 8, rgb(255,255,182), 1, 1, rgb(85,85,16), 1
    AFlibIII_CustomSync fps_OPTIMAL
    ScreenCopy
  Loop while inkey$ = ""

Next

AFlibIII_RemoveScreen 1
AFlibIII_RemoveFontSet 1
ImageDestroy ( CustomBuffer )
ImageDestroy ( AF3Sprite )

AFlibIII_EndProgram




Sub Scaler ()
  If ScaleX_ctrl = 0 then 
    ScaleX += .038
    If ScaleX > 2.5 then ScaleX_ctrl = 1 
  else 
    ScaleX -= .038
    If ScaleX < 0.001 then
      ScaleX_ctrl = 0 
      FlipX += 1: If FlipX > 1 then FlipX = 0 
    end if
  End if 

  If ScaleY_ctrl = 0 then 
    ScaleY += .025
    If ScaleY > 2 then ScaleY_ctrl = 1 
  else 
    ScaleY -= .025
    If ScaleY < 0.001 then
      ScaleY_ctrl = 0 
      FlipY += 1: If FlipY > 1 then FlipY = 0 
    end if
  End if 
End Sub

Sub Rotator ()
  Rotate += 1: If Rotate > 359 then Rotate = 0 
End Sub

Sub TranslucentFader ()
  If Transluce_ctrl then
    Transluce += 1
    If Transluce > 255 then
      Transluce = 255
      Transluce_ctrl = 0
    End if
  else
    Transluce -= 1
    If Transluce < 0 then
      Transluce = 0
      Transluce_ctrl = 1
    End if
  End if
End Sub

Sub ClearScaleAndRotator ()
  Rotate = 0: ScaleX = 0: ScaleY = 0
  AFlibIII_ClearKeyBuffer
End Sub


'========================================================================== 
'/////// E N D   O F   M A I N   P O R T I O N 
'========================================================================== 




'__________________________________________________________________________ 
Sub ShadowPrint ( Byref text as String, _ 
                  Byval x as Integer, Byval y as Integer, _ 
                  Byval col as Integer, Byval sh_x as Integer, _ 
                  Byval sh_y as Integer, Byval sh_col as Integer, _ 
                  Byval chara_id as Integer ) 

AFlibIII_OptimizedPrint_color text, x + sh_x, y + sh_y, chara_id, 0, sh_col
AFlibIII_OptimizedPrint_color text, x, y, chara_id, 0, col

End Sub
