示例#1
0
        public static void DrawFont(float x, float y, float z, string text, float scalefactor = 1f, bool stat = false, uint font = 1)
        {
            int count = text.Length;
            //int xfactor = (int)(scalefactor * 0.0667); //Hitta på nån bra siffra!!? (Med Quad:ens storlek som SymbolWidth x SymboldHeight) (Texten blev avsmalad!)
            int xfactor = (int)(scalefactor * 20); //Hitta på nån bra siffra!!? (Med Quad:ens storlek som (SymbolHeight * 100) = 0.25 * 100 = 25 = 25x25) (SNABBARE)
            //int xfactor = (int)((scalefactor / 5) * GetFont(font).BaseScaleFactor); //Default: ((1 / 5) * 100) = (0.2 * 100) = 20  ||  Scale 2x: ((2 / 5) * 100) = (0.4 * 100) = 40
            int? inTemp;

            //System.Console.WriteLine("xfactor: " + xfactor);
            if(count > 0 && fonts_DicUIFon.Count >= font) {
                if(currentFont_Fon == null || ((currentFont_Fon != null) && (currentFont_Fon.FontID != font))) {
                    //fonCurrentFont = dicuifonFonts[font];
                    fonts_DicUIFon.TryGetValue(font, out currentFont_Fon);
                }

                if(currentFont_Fon != null) {
                    //qtTemp = fonCurrentFont.Quad;
                    temp_Q = currentFont_Fon.Quad;

                    if(VBOHandler.CurrentBuffer != temp_Q.VBO) { VBOHandler.ChangeBuffer(temp_Q.VBO); }
                    if(ShaderHandler.CurrentProg != temp_Q.ProgID) { ShaderHandler.ChangeProgram(temp_Q.ProgID); }
                    if(TextureHandler.CurrentTex != temp_Q.TextureID) { TextureHandler.SetTexture(temp_Q.TextureID); }
                    if(!ShaderHandler.CheckActiveAttribArray(temp_Q.VertAttribLoc)) { ShaderHandler.ActivateAttribArray(temp_Q.VertAttribLoc); }
                    if(!ShaderHandler.CheckActiveAttribArray(temp_Q.TextureCoordsAttrib)) { ShaderHandler.ActivateAttribArray(temp_Q.TextureCoordsAttrib); }
                    if(VBOHandler.LastVertDataPos != temp_Q.VertDataPosition) { VBOHandler.ChangeVertAttribPointer(temp_Q.VertAttribLoc, temp_Q.VertDataPosition); }
                    //System.Console.WriteLine("qnTemp.VertDataPosition = " + qnTemp.VertDataPosition.ToString());
                    //System.Console.WriteLine("qnTemp.TextureDataPosition = " + qnTemp.TextureDataPosition.ToString());
                    //System.Console.WriteLine("VBO: " + VBOHandler.CurrentBuffer.ToString() + " - Prog: " + ShaderHandler.CurrentProg.ToString() + " - Tex: " + TextureHandler.CurrentTex.ToString());

                    for(int i = 0; i < count; i++) {
                        inTemp = currentFont_Fon.GetSymbolPos(text[i]);
                        if(inTemp.HasValue) {
                            //qnTemp.X = (x + ((fonCurrentFont.SymbolWidth + 0f) * i)); //Ändra tillbaks till + 0f?
                            temp_Q.X = (x + ((currentFont_Fon.SymbolWidth + xfactor) * i));
                            temp_Q.Y = (y);
                            temp_Q.Z = (z);
                            temp_Q.TextureDataPosition = inTemp.Value;

                            temp_Q.Draw(scalefactor, 0.0f, 0.0f, 0.0f, stat, true);
                            //System.Console.WriteLine(inTemp.Value + " - " + qnTemp.TextureDataPosition.ToString() + " - " + VBOHandler.LastTexCoordDataPos.ToString());
                            //System.Console.WriteLine(qnTemp.Position.ToString());
                        }
                    }
                }
            }
        }
示例#2
0
        //Constructors
        public TextBox(float x, float y, float width, float height, string bordertex, string backgroundtex, Color backgroundcolor, uint fontid, int vbo = -1, int progid = -1)
        {
            fontID_UI = fontid;
            visible_B = true;

            text_LiS = new List<string>();
            border_Q = new Quad(new Vector3(x, y, 0), new Vector2(width, height), bordertex, null, vbo, progid);
            background_Q = new Quad(new Vector3(x, y, 0), new Vector2(width, height), backgroundcolor, backgroundtex);
            FontHandler.GetFontDimensions(fontID_UI, out symbolWidth_F, out symbolHeight_F);
            #if DEBUG
            System.Console.WriteLine("(TB) Font dimensions: W: " + symbolWidth_F.ToString() + " - H: " + symbolHeight_F.ToString());
            #endif
            //iLinesToDisplay = (int)(qnBorder.Height / fSymbolHeight); //Behövs en System.Math.Floor() här?
            linesToDisplay_I = (int)(border_Q.Height / FontHandler.GetFont(fontID_UI).Quad.Height); //Fixa in skalning också???

            #if DEBUG
            System.Console.WriteLine("---> Textbox ready! (Lines to display: " + linesToDisplay_I.ToString() + ") <---");
            #endif
        }
示例#3
0
        //Constructors
        public Font(uint fontid, string path, float symbolwidth, float symbolheight, int vbo, int progid, uint lines, float basescalefactor = 100f, bool flipped = true)
        {
            float fx, fy;
            VerticeArrayInfo vaitemp = null;

            fontID_UI = fontid;
            SymbolWidth_F = symbolwidth; SymbolHeight_F = symbolheight;
            BaseScaleFactor_F = basescalefactor;
            vBO_I = vbo;
            symbols_DICCI = new Dictionary<char, int>();

            texID_I = TextureHandler.LoadTexture(path);
            //qnQuad = new QuadNew(new OpenTK.Vector3(0f, 0f, 0f), new OpenTK.Vector2(fSymbolWidth, fSymbolHeight), "", null, vbo, progid, false, false);
            quad_Q = new Quad(new OpenTK.Vector3(0f, 0f, 0f), new OpenTK.Vector2((SymbolHeight_F * basescalefactor), (SymbolHeight_F * basescalefactor)), "", null, vbo, progid, false, false);
            //qnQuad = new QuadNew(new OpenTK.Vector3(0f, 0f, 0f), new OpenTK.Vector2(25, 25), "", null, vbo, progid, false, false);
            quad_Q.TextureID = texID_I;
            #if DEBUG
            System.Console.WriteLine("SymbolWidth: " + SymbolWidth_F.ToString() + " - SymbolHeight: " + SymbolHeight_F.ToString());
            #endif

            /*If flipped
             * Upper left = :
             * Else
             * Upper left = a
             */

            fy = 0f;
            for(uint ui = 1; ui <= lines; ui++) {
                fx = 0f;
                if((!flipped && ui == 1) || (flipped && ui == 4)) { //Lowercase
                    if(lines > 1) { //Use the default layout
                        for(char c = 'a'; c <= 'z'; c++) {
                            vaitemp = QuadVerticeHandler.GetTexCoordArray(fx, fy, symbolwidth, symbolheight, vbo, true);
                            if(!vaitemp.InVBO) {
                                vaitemp.VBO = vbo;
                                vaitemp.Position = VBOHandler.AddToVBO(vbo, vaitemp.Data).Value;
                                vaitemp.InVBO = true;
                            }
                            symbols_DICCI.Add(c, vaitemp.Position);
                            //System.Console.WriteLine("lowerc - letter: " + c + " - left: " + fx + " - top: " + fy + " - width: " + symbolwidth + " - height: " + symbolheight);
                            //System.Console.WriteLine(Misc.ArrayToString(vaitemp.Data, "Printing TexCoords Array:", 0, ArrayTypes.TexCoords));
                            fx += symbolwidth;
                        }
                    }
                    else if(lines == 1) { //Use single line layout (lowercase, uppercase, numbers, symbols)
                        //Fixa!!!

                    }
                }
                else if((!flipped && ui == 2) || (flipped && ui == 3)) { //Uppercase
                    for(char c = 'A'; c <= 'Z'; c++) {
                        vaitemp = QuadVerticeHandler.GetTexCoordArray(fx, fy, symbolwidth, symbolheight, vbo, true);
                        if(!vaitemp.InVBO) {
                            vaitemp.VBO = vbo;
                            vaitemp.Position = VBOHandler.AddToVBO(vbo, vaitemp.Data).Value;
                            vaitemp.InVBO = true;
                        }
                        symbols_DICCI.Add(c, vaitemp.Position);
                        //System.Console.WriteLine("upperc - letter: " + c + " - left: " + fx + " - top: " + fy + " - width: " + symbolwidth + " - height: " + symbolheight);
                        //System.Console.WriteLine(Misc.ArrayToString(vaitemp.Data, "Printing TexCoords Array:", 0, ArrayTypes.TexCoords));
                        fx += symbolwidth;
                    }
                }
                else if((!flipped && ui == 3) || (flipped && ui == 2)) { //Numbers + Symbols 1
                    for(char c = '0'; c <= '9'; c++) {
                        vaitemp = QuadVerticeHandler.GetTexCoordArray(fx, fy, symbolwidth, symbolheight, vbo, true);
                        if(!vaitemp.InVBO) {
                            vaitemp.VBO = vbo;
                            vaitemp.Position = VBOHandler.AddToVBO(vbo, vaitemp.Data).Value;
                            vaitemp.InVBO = true;
                        }
                        symbols_DICCI.Add(c, vaitemp.Position);
                        fx += symbolwidth;
                    }
                    for(char c = '!'; c <= '/'; c++) {
                        vaitemp = QuadVerticeHandler.GetTexCoordArray(fx, fy, symbolwidth, symbolheight, vbo, true);
                        if(!vaitemp.InVBO) {
                            vaitemp.VBO = vbo;
                            vaitemp.Position = VBOHandler.AddToVBO(vbo, vaitemp.Data).Value;
                            vaitemp.InVBO = true;
                        }
                        symbols_DICCI.Add(c, vaitemp.Position);
                        fx += symbolwidth;
                    }
                }
                else if((!flipped && ui == 4) || (flipped && ui == 1)) { //Symbols 2
                    for(char c = ':'; c <= '@'; c++) {
                        vaitemp = QuadVerticeHandler.GetTexCoordArray(fx, fy, symbolwidth, symbolheight, vbo, true);
                        if(!vaitemp.InVBO) {
                            vaitemp.VBO = vbo;
                            vaitemp.Position = VBOHandler.AddToVBO(vbo, vaitemp.Data).Value;
                            vaitemp.InVBO = true;
                        }
                        symbols_DICCI.Add(c, vaitemp.Position);
                        fx += symbolwidth;
                    }
                    for(char c = '['; c <= '_'; c++) {
                        vaitemp = QuadVerticeHandler.GetTexCoordArray(fx, fy, symbolwidth, symbolheight, vbo, true);
                        if(!vaitemp.InVBO) {
                            vaitemp.VBO = vbo;
                            vaitemp.Position = VBOHandler.AddToVBO(vbo, vaitemp.Data).Value;
                            vaitemp.InVBO = true;
                        }
                        symbols_DICCI.Add(c, vaitemp.Position);
                        fx += symbolwidth;
                    }
                    for(char c = '{'; c <= '~'; c++) {
                        vaitemp = QuadVerticeHandler.GetTexCoordArray(fx, fy, symbolwidth, symbolheight, vbo, true);
                        if(!vaitemp.InVBO) {
                            vaitemp.VBO = vbo;
                            vaitemp.Position = VBOHandler.AddToVBO(vbo, vaitemp.Data).Value;
                            vaitemp.InVBO = true;
                        }
                        symbols_DICCI.Add(c, vaitemp.Position);
                        fx += symbolwidth;
                    }

                }
                else {
                    //Fixa???
                }
                fy += symbolheight;
            }
        }