void RefreshGridPreview() { mImporterRefreshPreview = false; if (mFont.atlas == null) { for (int i = 0; i < kPreviewTextLength; i++) { mPreviewCoords[i] = new Rect(0, 0, 0, 0); mPreviewRects[i] = new Rect(0, 0, 0, 0); } return; } mPreviewRectWidth = kPreviewTextLength * mImporterCharWidth; mPreviewRectHeight = mImporterCharHeight; GiraffeSprite sprite = mFont.atlas.GetSprite(mFont.spriteName); float invWidth = 1.0f / mFont.atlas.texture.width; float invHeight = 1.0f / mFont.atlas.texture.height; sprite.Refresh(invWidth, invHeight); float cw = mImporterCharWidth * invWidth; float ch = mImporterCharHeight * invHeight; int charsPerLine = sprite.width / mImporterCharWidth; if (charsPerLine == 0) { for (int i = 0; i < kPreviewTextLength; i++) { mPreviewCoords[i] = new Rect(0, 0, mImporterCharWidth, mImporterCharHeight); mPreviewRects[i] = new Rect(0, 0, 0, 0); } return; } for (int i = 0; i < kPreviewTextLength; i++) { mPreviewCoords[i] = new Rect(i * mImporterCharWidth, 0, mImporterCharWidth, mImporterCharHeight); char c = kPreviewText[i]; int p = mImporterString.IndexOf(c); if (p == -1) { mPreviewRects[i] = new Rect(0, 0, 0, 0); continue; } int x = p % charsPerLine; int y = p / charsPerLine; float x0 = sprite.x0 + cw * x; float y0 = sprite.y1 - (ch * y) - ch; mPreviewRects[i] = new Rect(x0, y0, cw, ch); } }
GiraffeSprite ProcessSprite(GiraffeSprite sprite) { if (sprite.refreshNeeded) { float invTexWidth = 1.0f / texture.width; float invTexHeight = 1.0f / texture.height; sprite.Refresh(invTexWidth, invTexHeight); } return(sprite); }
void Initialise() { sprite = atlas.GetSprite(spriteName); float invTexWidth = 1.0f / atlas.texture.width; float invTexHeight = 1.0f / atlas.texture.height; characters = new Dictionary <char, GiraffeFontGlyph>(glyphs.Length); characterRangeMin = char.MaxValue; characterRangeMax = char.MinValue; for (int i = 0; i < glyphs.Length; i++) { GiraffeFontGlyph glyph = glyphs[i]; char c = (char)glyph.character; characters.Add(c, glyph); if (c < characterRangeMin) { characterRangeMin = c; } if (c > characterRangeMax) { characterRangeMax = c; } GiraffeSprite glyphSprite = new GiraffeSprite(); glyph.sprite = glyphSprite; glyphSprite.left = glyph.x + sprite.left; glyphSprite.top = glyph.y + sprite.top; glyphSprite.width = glyph.width; glyphSprite.height = glyph.height; glyphSprite.Refresh(invTexWidth, invTexHeight); } }