public void setText(MonoGameGameFontCache fontCache) { if (_caches.ContainsKey(fontCache.cacheId) && _caches[fontCache.cacheId] != null) { //TODO: Implement some way to clear old texture regions _gc.Add(_caches[fontCache.cacheId]); _caches.Remove(fontCache.cacheId); } Rectangle rect = determineRequiredArea(fontCache); if (!allocateTextureRegionXY(fontCache.cacheId, ref rect)) { clear(); setText(fontCache); return; } begin(); for (int i = 0; i < fontCache._previousDrawingOperations.Count; i++) { MonoGameGameFontCacheDrawingOperation operation = fontCache._previousDrawingOperations[i]; fontCache._gameFont.draw(_spriteBatch, operation.text, operation.targetWidth, operation.horizontalAlign, operation.wrap, new Vector2(rect.X + operation.x, rect.Y + operation.y), operation.color * operation.alpha); } end(); _caches[fontCache.cacheId] = new MonoGameTextureRegion(_texture, rect.X, rect.Y, rect.Width, rect.Height); }
public void draw(Org.Mini2Dx.Core._Graphics g, MonoGameGameFontCache fontCache, Vector2 position) { int cacheId = fontCache.cacheId; if (fontCache._previousDrawingOperations.Count == 0) { return; } if (!_caches.ContainsKey(cacheId) || _caches[cacheId] == null) { setText(fontCache); } MonoGameTextureRegion textureRegion = _caches[cacheId]; g.drawTextureRegion(textureRegion, position.X, position.Y); }
private Rectangle determineRequiredArea(MonoGameGameFontCache cache) { int maxX = 0; int maxY = 0; for (int i = 0; i < cache._previousDrawingOperations.Count; i++) { int currentMaxX = MathUtils.round(cache._previousDrawingOperations[i].x + cache._previousDrawingOperations[i].targetWidth); int currentMaxY = MathUtils.round(cache._previousDrawingOperations[i].y + cache._previousDrawingOperations[i].targetHeight); maxX = Math.Max(maxX, currentMaxX); maxY = Math.Max(maxY, currentMaxY); } return(new Rectangle(0, 0, maxX, maxY)); }