'
' *   EZ GL2D Fonts Example
' *   Source is provided "as is" without express or implied warranty of any kind.
' * 
'

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports EZGL2D

Namespace EZGL2DexampleFont
	Friend Class FontGL

		Private fontSet() As GL2D.SpriteGL
		Private charWidth As Integer = 16
		Private charHeight As Integer = 16

		Public Sub New()
		End Sub

		' loads our fontset
		Public Sub loadFont(ByVal filename As String, ByVal charWidth As Integer, ByVal charHeight As Integer, ByVal filtermode As Integer)

			Me.charWidth = charWidth
			Me.charHeight = charHeight

			fontSet = GL2D.LoadTileSet(filename, charWidth, charHeight, filtermode) ' Nearest for oldskool effect

		End Sub

		' Prints a string on the screen
		Public Sub print(ByVal x As Integer, ByVal y As Integer, ByVal text As String)
			Dim len As Integer = text.Length
			For i As Integer = 0 To len - 1
				Dim index As Integer = AscW(text.Chars(i)) - 32 ' offset the index by spacebar(32)
				   GL2D.Sprite(x, y, GL2D.SpriteGL.FLIP_NONE, fontSet(index)) ' sprite
				x += charWidth ' next location
			Next i

		End Sub


		' Centers a string on the screen
		Public Sub printCenter(ByVal x As Integer, ByVal y As Integer, ByVal text As String, ByVal screenWidth As Integer)

			Dim len As Integer = text.Length
			x = (screenWidth - (len * charWidth)) \ 2
			print(x,y,text)

		End Sub

		' Prints a string on the screen in a wave pattern
		Public Sub printSine(ByVal x As Integer, ByVal y As Integer, ByVal text As String, ByVal height As Integer, ByVal cycles As Integer, ByVal startAngle As Integer)
			Dim len As Integer = text.Length
			Dim angleInc As Integer = (360\len)*cycles
			For i As Integer = 0 To len - 1
				Dim index As Integer = AscW(text.Chars(i)) - 32 ' offset the index by spacebar(32)
				   Dim ySine As Single = CSng(Math.Sin(startAngle * Math.PI/180.0)) * height
				GL2D.Sprite(x, CInt(Math.Truncate(ySine)) + y, GL2D.SpriteGL.FLIP_NONE, fontSet(index)) ' sprite
				x += charWidth ' next location
				startAngle += angleInc
			Next i

		End Sub

		' Centgers a string on the screen in a wave pattern
		Public Sub printCenterSine(ByVal x As Integer, ByVal y As Integer, ByVal text As String, ByVal screenWidth As Integer, ByVal height As Integer, ByVal cycles As Integer, ByVal startAngle As Integer)
			Dim len As Integer = text.Length
			x = (screenWidth - (len * charWidth)) \ 2
			printSine(x, y, text, height, cycles, startAngle)
		End Sub

	End Class
End Namespace
