'=============================================================== 
' A F l i b   I I I   F o n t s h e e t   E x a m p l e 
'=============================================================== 
'In this test, we take here a custom 144x144 .BMP fontsheet that
'has all 256 characters in a custom 6x8 font!!  Then, we set
'ourselves up to do some fast, optimized printouts of that very
'font indeed, using proper spacing!!!  A wonderful example for
'you to set up and implement your own fonts in your own games
'and projects using AFlib III, you know that?  ^_-=b !
' 
'I sure hope you get a lot of enjoyment out of this one,
'folks!!!  :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_Miscellaneous.bi"
#include "AFlib3_Constants.bi"
#include "AFlib3_Screen.bi"
#include "AFlib3_Resize2X.bi"

Dim Shared as Integer BitDepth, Fontwidth, Charset, CharColumn
Dim As Any Ptr Font_6x8, ImagePic


Declare Sub ShadowPrintSP ( 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 spacing as Single, Byval chara_id as Integer ) 



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

ScreenRes 424, 96 , , 0
Windowtitle "AFlib III -- 144x144 .BMP Font Sheet 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

SetMouse , , 0

AFlibIII_ClearDisplay 0
AFlibIII_CaptureScreen 1

Font_6x8 = imagecreate( 144, 144 )
bload "AF3_6x8_fontsheet.bmp", Font_6x8

Put (0, 0), Font_6x8, pset
AFlibIII_OptimizeFontSet 0, 0, 1

Fontwidth = 6  '<--- Since the width of our custom font is 6 pixels long,
               '     6 is the magic number that we aim for here!  ^-^

Locate 20, 1: ? "To begin this fontsheet example, this"
Locate 21, 1: ? "character set taken from a 144x144 .BMP"
Locate 22, 1: ? "file is required right here."

AFlibIII_UpdateScreen_half_size 1
AFlibIII_ClearDisplay 0

AFlibIII_BlitScreen 0, 0, 1
AFlibIII_Resize2X_640x480
AFlibIII_ClearKeyBuffer
Sleep 10000
imagedestroy ( Font_6x8 )

ImagePic = imagecreate( 320, 240 )
bload "AF3_bg1.bmp", ImagePic
ScreenSet 1, 0

AFlibIII_ClearDisplay 0
Put (0, 0), ImagePic, pset

ShadowPrintSP "This is a test of the custom use of a 144x144 .BMP", 0, 0, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
ShadowPrintSP "character sheet in the new AFlib III!!!", 0, 8, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1

ShadowPrintSP "This time, we involve here a 6x8 font extracted from", 0, 24, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
ShadowPrintSP "that very character sheet indeed!!", 0, 32, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1

ShadowPrintSP "How cool is that, huh?  ^-^=b !", 0, 48, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1

ShadowPrintSP "Press any key.......", 0, 232, rgb(0, 255, 0), 1, 1, rgb(0,15,0), Fontwidth, 1

AFlibIII_LowRes2X
AFlibIII_ClearKeyBuffer
ScreenCopy 1, 0
Sleep

AFlibIII_ClearDisplay 0
Put (0, 0), ImagePic, pset

ScreenSet 1, 2
ShadowPrintSP "Here comes the full character set of this in typing!!", 0, 0, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
AFlibIII_UpdateScreen_half_size 1

For CharColumn = 0 to 7
  For Charset = 0 to 31
    ScreenSet 1, 0
    AFlibIII_ClearDisplay 0
    AFlibIII_BlitScreen 0, 0, 1
    ShadowPrintSP Chr$(Charset + (CharColumn * 32)), 32 + (Charset * Fontwidth), 48 + (CharColumn * 8), rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
    AFlibIII_UpdateScreen_half_size 1
    AFlibIII_CustomSync fps70
    AFlibIII_LowRes2X
    ScreenCopy 1, 0
  Next
Next

ScreenSet 1, 0

AFlibIII_ClearDisplay 0
AFlibIII_BlitScreen 0, 0, 1
AFlibIII_UpdateScreen_half_size 1
ShadowPrintSP "Press any key.......", 0, 232, rgb(0, 255, 0), 1, 1, rgb(0,15,0), Fontwidth, 1

AFlibIII_LowRes2X
ScreenCopy 1, 0
AFlibIII_ClearKeyBuffer
Sleep

ScreenSet 1, 0

AFlibIII_ClearDisplay 0
Put (0, 0), ImagePic, pset

ShadowPrintSP "And this is just a wonderful sample of what to expect", 0, 0, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
ShadowPrintSP "in Aura Flow Library 3, the most truly advanced 2D", 0, 8, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
ShadowPrintSP "15-, 16-, 24-, and 32-bit game library for use with", 0, 16, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
ShadowPrintSP "Angelo Mottola's GFXlib2 for FreeBASIC!!!", 0, 24, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1

ShadowPrintSP "I *sure* hope you enjoyed this little demo, and thank", 0, 40, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1
ShadowPrintSP "you so very much!!!  (^_-)v !", 0, 48, rgb(255, 255, 255), 1, 1, rgb(15,15,15), Fontwidth, 1

ShadowPrintSP chr$(153) + " 2005-2016 Adigun Azikiwe Polack/Aura Flow.", 0, 208, rgb(255, 207, 255), 1, 1, rgb(15,7,15), Fontwidth, 1
ShadowPrintSP "All Rights Reserved.", 0, 216, rgb(255, 207, 255), 1, 1, rgb(15,7,15), Fontwidth, 1
ShadowPrintSP "Press any key to end, please.", 0, 232, rgb(0, 255, 0), 1, 1, rgb(0,15,0), Fontwidth, 1

AFlibIII_LowRes_vert
AFlibIII_LowRes_horiz
AFlibIII_ClearKeyBuffer
ScreenCopy 1, 0
Sleep

imagedestroy ( ImagePic )
AFlibIII_RemoveFontSet 1
AFlibIII_RemoveScreen 1

AFlibIII_EndProgram


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




'__________________________________________________________________________ 
Sub ShadowPrintSP ( 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 spacing as Single, Byval chara_id as Integer ) 

AFlibIII_OptimizedPrintSP_color text, x + sh_x, y + sh_y, spacing, chara_id, 0, sh_col
AFlibIII_OptimizedPrintSP_color text, x, y, spacing, chara_id, 0, col

End Sub