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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZGL2D;

namespace EZGL2DexampleFont
{
    class FontGL
    {

        private GL2D.SpriteGL[] fontSet;
        int charWidth = 16;
	    int charHeight = 16;

        public FontGL()
	    {
	    }

        // loads our fontset
        public void loadFont( string filename, int charWidth, int charHeight, int filtermode )
        {

            this.charWidth = charWidth;
            this.charHeight = charHeight;

            fontSet = GL2D.LoadTileSet(filename,
                                        charWidth, charHeight, filtermode);   // Nearest for oldskool effect
 
        }
	    
        // Prints a string on the screen
	    public void print(int x, int y, String text)
	    {
		    int len = text.Length;
		    for (int i = 0; i < len; i++)
		    {
			    int index = text[i] - 32; // offset the index by spacebar(32)
			   	GL2D.Sprite(x, y, GL2D.SpriteGL.FLIP_NONE, fontSet[index]);													    // sprite
			    x += charWidth; // next location
		    }

	    }

        
	    // Centers a string on the screen
	    public void printCenter(int x, int y, String text, int screenWidth )
	    {

		    int len = text.Length;
		    x = (screenWidth - (len * charWidth)) / 2;
		    print(x,y,text);
            
	    }

        // Prints a string on the screen in a wave pattern
	    public void printSine(int x, int y, String text, int height, int cycles, int startAngle )
	    {
		    int len = text.Length;
		    int angleInc = (360/len)*cycles;	
            for (int i = 0; i < len; i++)
		    {
			    int index = text[i] - 32; // offset the index by spacebar(32)
			   	float ySine = (float)Math.Sin(startAngle * Math.PI/180.0) * height;  
			    GL2D.Sprite(x, (int)ySine + y, GL2D.SpriteGL.FLIP_NONE, fontSet[index]);													    // sprite
			    x += charWidth; // next location
                startAngle += angleInc;
		    }

	    }

        // Centgers a string on the screen in a wave pattern
        public void printCenterSine(int x, int y, String text, int screenWidth, int height, int cycles, int startAngle)
	    {
		    int len = text.Length;
		    x = (screenWidth - (len * charWidth)) / 2;
            printSine(x, y, text, height, cycles, startAngle);
	    }
    	
    }
}
