Example #1
0
 private TextNode(Font font, Vector2 position, double scale)
 {
     this.Position = position;
     this.Font = font;
     lines = new List<TextLine>();
     this.scale = scale;
 }
Example #2
0
        public Game()
        {
            state = new BootState(this);

            window = new GameWindow(960, 540);
            window.Load += Window_Load;
            window.RenderFrame += Window_RenderFrame;
            window.UpdateFrame += Window_UpdateFrame;
            window.Closing += Window_Closing;
            window.Closed += Window_Closed;
            window.Resize += Window_Resize;
            window.FocusedChanged += Window_FocusedChanged;

            Console.WriteLine("OpenGL: {0}", GL.GetString(StringName.Version));

            keyHandler = new KeyHandler(window);

            Canvas = new SceneCanvas(keyHandler);
            shaderManager = new ShaderManager();

            shader = new StaticShader();
            shaderManager.Add(shader);

            fontShader = new FontShader();

            fontManager = new FontManager(fontShader);
            fontShader.Compile();
            font = FontParser.ParseFNT(@"Fonts/Verdana.fnt");
            fontManager.Add(font);

            lastMousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
        }
Example #3
0
 public UIText(Font.Font font, string value, double pointScale, Vector2 position, Vector3 color)
 {
     this.font = font;
     this.value = value;
     this.pointScale = pointScale;
     this.Position = position;
     this.color = color;
 }
Example #4
0
 public TextNode(Font font, string value, Vector2 postion, double scale)
     : this(font, postion, scale)
 {
     string[] textLines = value.Split('\n');
     foreach(string line in textLines)
     {
         AddLine(line);
     }
 }
Example #5
0
        public UIButton(Font.Font font, Vector2 position, Vector2 size, string buttonText, double pointScale)
        {
            this.font = font;
            this.Position = position;
            this.size = size;
            this.pointScale = pointScale;
            this.text = buttonText;
            // Build the button.

            renderer = new TriangleStripRender(buildButton(), 2);
        }
Example #6
0
        public static Font ParseFNT(string fontFile)
        {
            // We should parse the Hiero v3.1 font files here.

            Font result = null;

            string fileContents = System.IO.File.ReadAllText(fontFile);

            string[] fileLines = fileContents.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string[] lineData;

            string[] equalsSplit = new string[2];

            string pageFile = "";
            int parsePage = -1;
            int characterCount = 0;
            int curCharIndex = 0;

            for (int i = 0; i < fileLines.Length; i++)
            {
                lineData = fileLines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                switch (lineData[0].ToLower())
                {
                    case "info":

                        string fontFace = "";
                        short fontSize = 0;
                        int[] padding = new int[4];
                        int[] spacing = new int[2];
                        string[] colSplit;

                        // Parse font info.
                        for (int j = 1; j < lineData.Length; j++)
                        {
                            equalsSplit = lineData[j].Split('=');

                            switch (equalsSplit[0].ToLower())
                            {
                                case "face":
                                    fontFace = equalsSplit[1].Replace("\"", "");
                                    break;

                                case "size":
                                    fontSize = short.Parse(equalsSplit[1]);
                                    break;

                                case "padding":

                                    colSplit = equalsSplit[1].Split(',');

                                    for (int k = 0; k < colSplit.Length; k++)
                                    {
                                        padding[k] = int.Parse(colSplit[k]);
                                    }

                                    break;

                                case "spacing":

                                    colSplit = equalsSplit[1].Split(',');

                                    for (int k = 0; k < colSplit.Length; k++)
                                    {
                                        spacing[k] = int.Parse(colSplit[k]);
                                    }

                                    break;

                                default:
                                    // Skip this for now.
                                    break;

                            }
                        }

                        // Create font information object.
                        result = new Font(fontFace, fontSize, padding, spacing);
                        result.SetTexture(AssetsLoader.LoadTexture(@"Fonts\" + fontFace + ".png"));

                        break;

                    case "common":

                        int lineHeight = 0, baseValue = 0, scaleW = 0, scaleH = 0, pages = 0;

                        // Parse common data.
                        for (int j = 1; j < lineData.Length; j++)
                        {
                            equalsSplit = lineData[j].Split('=');

                            switch (equalsSplit[0].ToLower())
                            {

                                case "lineheight":
                                    lineHeight = int.Parse(equalsSplit[1]);
                                    break;

                                case "base":
                                    baseValue = int.Parse(equalsSplit[1]);
                                    break;

                                case "scalew":
                                    scaleW = int.Parse(equalsSplit[1]);
                                    break;

                                case "scaleh":
                                    scaleH = int.Parse(equalsSplit[1]);
                                    break;

                                case "pages":
                                    pages = int.Parse(equalsSplit[1]);
                                    break;

                                default:
                                    // Skip this for now.
                                    break;

                            }
                        }

                        // Set the common data of the font.
                        result.SetCommonData(lineHeight, baseValue, scaleW, scaleH, pages);

                        break;

                    case "page":

                        // Parse page.
                        if (lineData[1].StartsWith("id") && lineData[2].StartsWith("file"))
                        {
                            parsePage = int.Parse(lineData[1].Split('=')[1]);
                            pageFile = lineData[2].Split('=')[1].Replace("\"", "");

                            if (parsePage >= 0)
                            {
                                result.AddPage(new FontPage(parsePage, pageFile));
                            }
                            else
                            {
                                break; // -> Shouldn't be here. WTF HACKER.
                            }
                        }

                        break;

                    case "chars":

                        if (lineData[1].StartsWith("count"))
                        {
                            characterCount = int.Parse(lineData[1].Split('=')[1]);
                            result.CharactersCount = characterCount;
                        }

                        break;

                    case "char":

                        curCharIndex++; // Counting is fun :)

                        // char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=83    xadvance=29     page=0  chnl=0
                        ushort charId = 0;
                        int x = 0, y = 0, width = 0, height = 0, xoffset = 0, yoffset = 0;
                        short xadvance = 0;
                        byte page = 0, channel = 0;

                        for (int j = 1; j < lineData.Length; j++)
                        {
                            equalsSplit = lineData[j].Split('=');

                            switch (equalsSplit[0].ToLower())
                            {

                                case "id":
                                    charId = ushort.Parse(equalsSplit[1]);
                                    break;

                                case "x":
                                    x = int.Parse(equalsSplit[1]);
                                    break;

                                case "y":
                                    y = int.Parse(equalsSplit[1]);
                                    break;

                                case "width":
                                    width = int.Parse(equalsSplit[1]);
                                    break;

                                case "height":
                                    height = int.Parse(equalsSplit[1]);
                                    break;

                                case "xoffset":
                                    xoffset = int.Parse(equalsSplit[1]);
                                    break;

                                case "yoffset":
                                    yoffset = int.Parse(equalsSplit[1]);
                                    break;

                                case "xadvance":
                                    xadvance = short.Parse(equalsSplit[1]);
                                    break;

                                case "page":
                                    page = byte.Parse(equalsSplit[1]);
                                    break;

                                case "chnl":
                                    channel = byte.Parse(equalsSplit[1]);
                                    break;

                                default:
                                    // Skip this for now.
                                    break;

                            }
                        }

                        // Save character to it's page.
                        if (result.FontPages.ContainsKey(page))
                        {
                            result.Add(new Glyph(charId, page, new Vector2(x, y), new Vector2(width, height), new Vector2(xoffset, yoffset), xadvance, channel));
                        }

                        break;

                    default:

                        break;
                }

            }

            return result;
        }