void InitializeGui() { GuiRenderer = new GwenRenderer(); var textureName = "DefaultSkin.png"; var defaultFont = new Flood.GUI.Font("Vera.ttf", 16); var resMan = FloodEngine.GetEngine().ResourceManager; var options = new ResourceLoadOptions {Name = textureName, AsynchronousLoad = false}; var imageHandle = resMan.LoadResource<Image>(options); if (imageHandle.Id == 0) return; var skin = new TexturedSkin(GuiRenderer, imageHandle, defaultFont); Canvas = new Canvas(skin); var container = new Container(Canvas); var paneGroup = new PaneGroup(container); container.InsertPanel(paneGroup); paneGroup.AddPane(new Pane { Title = "PANE1" }); paneGroup.AddPane(new Pane { Title = "PANE2" }); Input = new GwenInput(FloodEngine.GetEngine().InputManager); Input.Initialize(Canvas); }
public static Vector2 MeasureText(System.String text, Flood.GUI.Font font) { float curX = 0; var ttfont = font.EngineFont.Resolve(); for (var i = 0; i < text.Length; i++) { var c = text[i]; Glyph glyph; var foundGlyph = ttfont.GetGlyphInfo(c, font.Size, out glyph); if (!foundGlyph) { Log.Warn("Glyph not found for character " + c); continue; } curX += glyph.Advance; if (i < text.Length - 1) { curX += ttfont.GetKerning(text[i], text[i + 1], font.Size).X; } } return(new Vector2(curX, font.Size));; }
public bool TryGetGlyphImage(Font font, int codepoint, out SubTexture texture, out ResourceHandle<Material> material) { material = textMaterial; var glyphId = new GlyphId(font, codepoint); if (glyphSubTextures.TryGetValue(glyphId, out texture)) return true; var nativeFont = font.EngineFont.Resolve(); var imageHandle = nativeFont.CreateGlyphImage(codepoint, font.Size); if (imageHandle.Id == ResourceHandle<Resource>.Invalid) return false; if (!textureAtlas.AddImage(imageHandle)) { throw new Exception("Atlas full"); } if (!textureAtlas.GetImageSubTexture(imageHandle, out texture)) return false; glyphSubTextures.Add(glyphId, texture); return true; }
public static bool GetPositionTextIndex(string text, Flood.GUI.Font font, float x, out int index) { float curX = 0; var ttfont = font.EngineFont.Resolve(); for (var i = 0; i < text.Length; i++) { var c = text[i]; Glyph glyph; var foundGlyph = ttfont.GetGlyphInfo(c, font.Size, out glyph); if (!foundGlyph) { Log.Warn("Glyph not found for character " + c); continue; } curX += glyph.Advance; if (i < text.Length - 1) { curX += ttfont.GetKerning(text[i], text[i + 1], font.Size).X; } if (curX >= x) { index = i; return(true); } } index = 0; return(false); }
public bool TryGetGlyph(Font font, char c, out SubTexture subTexture) { var glyphHash = GlyphHash(font, c); if (glyphs.TryGetValue(glyphHash, out subTexture)) return true; subTexture = default(SubTexture); return false; }
public bool TryGetGlyphInfo(Font font,int codepoint, out Glyph glyph) { var glyphId = new GlyphId(font, codepoint); if (glyphInfos.TryGetValue(glyphId, out glyph)) return true; var nativeFont = font.EngineFont.Resolve(); if (!nativeFont.GetGlyphInfo(codepoint, font.Size, out glyph)) return false; glyphInfos[glyphId] = glyph; return true; }
void InitializeGui() { GuiRenderer = new GwenRenderer(); var textureName = "DefaultSkin.png"; var defaultFont = new Font("Vera.ttf", 16); var resMan = Engine.GetEngine().ResourceManager; var options = new ResourceLoadOptions {Name = textureName, AsynchronousLoad = false}; var imageHandle = resMan.LoadResource<Image>(options); if (imageHandle.Id == 0) throw new Exception("Could not load GUI texture: " + textureName); Skin = new TexturedSkin(GuiRenderer, imageHandle, defaultFont); Canvas = new Canvas(Skin); Input = new GwenInput(Engine.GetEngine().InputManager); Input.Initialize(Canvas); }
public static bool GetPositionTextIndex(string text, Font font, float x, out int index) { float curX = 0; for(var i = 0; i < text.Length; i++) { var c = text[i]; Glyph glyph; if (!glyphManager.TryGetGlyphInfo(font, c, out glyph)) { Log.Warn("Glyph not found for character " + c); continue; } curX += glyph.Advance; if(i < text.Length - 1) curX += glyphManager.GetKerning(font, text[i], text[i + 1]).X; if(curX >= x) { index = i; return true; } } index = 0; return false; }
public override void RenderText(Font font, Vector2i position, string text) { position = Translate(position); TextRenderer.DrawText(_guiBuffer, font, new Vector2(position.X,position.Y), text, DrawColor); }
public override Vector2 MeasureText(Font font, string text) { return TextRenderer.MeasureText(text,font); }
/// <summary> /// Duplicates font data (except renderer data which must be reinitialized). /// </summary> /// <returns></returns> public Font Copy() { Font f = new Font(m_Renderer, FaceName); f.Size = Size; f.RealSize = RealSize; f.RendererData = null; // must be reinitialized //f.Bold = Bold; //f.DropShadow = DropShadow; return f; }
private static int GlyphHash(Font font, char c) { return CombineHashCodes(CombineHashCodes(font.FaceName.GetHashCode(), c.GetHashCode()), font.Size.GetHashCode()); }
public static Vector2 MeasureText(System.String text, Font font) { float curX = 0; for(var i = 0; i < text.Length; i++) { var c = text[i]; Glyph glyph; if (!glyphManager.TryGetGlyphInfo(font, c, out glyph)) { Log.Warn("Glyph not found for character " + c); continue; } curX += glyph.Advance; if(i < text.Length - 1) curX += glyphManager.GetKerning(font, text[i], text[i + 1]).X; } return new Vector2(curX,font.Size);; }
public Vector2 GetKerning(Font font, int c1, int c2) { var nativeFont = font.EngineFont.Resolve(); return nativeFont.GetKerning(c1, c2, font.Size); }
public GlyphId(Font font, int codepoint) { FontName = font.FaceName; Size = font.Size; Codepoint = codepoint; }
public override void RenderText(Flood.GUI.Font font, Vector2i position, string text) { position = Translate(position); TextRenderer.DrawText(_guiBuffer, font, new Vector2(position.X, position.Y), text, DrawColor); }
public override Vector2 MeasureText(Flood.GUI.Font font, string text) { return(TextRenderer.MeasureText(text, font)); }
internal static void DrawText(GUIGeometryBuffer geometryBuffer, Flood.GUI.Font font, Vector2 position, String text, Color color) { var ttfont = font.EngineFont.Resolve(); for (var i = 0; i < text.Length; i++) { char c = text[i]; Glyph glyph; var foundGlyph = ttfont.GetGlyphInfo(c, font.Size, out glyph); if (!foundGlyph) { Log.Warn("Glyph not found for character " + c); continue; } bool drawSubtexture = true; SubTexture subTexture; if (!glyphCache.TryGetGlyph(font, c, out subTexture)) { var imageHandle = ttfont.CreateGlyphImage(c, font.Size); if (imageHandle.Id == ResourceHandle <Resource> .Invalid) { drawSubtexture = false; } else { var subTextureFound = textureAtlas.GetImageSubTexture(imageHandle, out subTexture); if (!subTextureFound) { textureAtlas.AddImage(imageHandle); subTextureFound = textureAtlas.GetImageSubTexture(imageHandle, out subTexture); if (subTextureFound) { glyphCache.AddGlyph(font, c, subTexture); } else { Log.Warn("subTexture not Found\n"); continue; } } } } if (drawSubtexture) { var renderRect = new RectangleF( position.X + glyph.XOffset, position.Y + glyph.BaseLineOffset, glyph.Width, glyph.Height); geometryBuffer.AddRectangle(renderRect, subTexture.LeftTopUV, subTexture.RightTopUV, subTexture.RightBottomUV, subTexture.LeftBottomUV, textMaterial, color); } if (i < text.Length - 1) { var kern = ttfont.GetKerning(text[i], text[i + 1], font.Size); position.X += glyph.Advance + kern.X; position.Y += kern.Y; } } }
internal static void DrawText(GUIGeometryBuffer geometryBuffer, Font font, Vector2 position, String text, Color color) { for(var i = 0; i < text.Length; i++) { char c = text[i]; Glyph glyph; if (!glyphManager.TryGetGlyphInfo(font, c, out glyph)) { Log.Warn("Glyph not found for character " + c); continue; } SubTexture subTexture; ResourceHandle<Material> material; if (glyphManager.TryGetGlyphImage(font, c, out subTexture, out material)) { var renderRect = new RectangleF( position.X + glyph.XOffset, position.Y + glyph.BaseLineOffset, glyph.Width, glyph.Height); geometryBuffer.AddRectangle(renderRect, subTexture.LeftTopUV, subTexture.RightTopUV, subTexture.RightBottomUV, subTexture.LeftBottomUV, material, color); } if (i < text.Length-1){ var kern = glyphManager.GetKerning(font, text[i], text[i+1]); position.X += glyph.Advance + kern.X; position.Y += kern.Y; } } }
public void AddGlyph(Font font, char c, SubTexture subTexture) { var glyphHash = GlyphHash(font, c); glyphs.Add(glyphHash,subTexture); }