Example #1
0
 internal AtlasChar(AtlasFont font, char chr, int adv, AtlasImage img)
 {
     Font    = font;
     Char    = chr;
     Advance = adv;
     Image   = img;
 }
Example #2
0
        public AtlasImage AddImage(ref string name, int width, int height, int offsetX, int offsetY, int trimW, int trimH, ref Rectangle uvRect, bool rotate90)
        {
            if (images.ContainsKey(name))
            {
                throw new Exception($"Atlas already has image with name: \"{name}\"");
            }

            var image = new AtlasImage(this, ref name, width, height, offsetX, offsetY, trimW, trimH, ref uvRect, rotate90);

            images.Add(name, image);
            return(image);
        }
Example #3
0
        public void SetTile(int x, int y, AtlasImage tile)
        {
            if (tile.Width != TileWidth)
            {
                throw new Exception("Tile width mismatch.");
            }
            if (tile.Height != TileHeight)
            {
                throw new Exception("Tile height mismatch.");
            }

            tiles[y * Cols + x] = tile;
        }
Example #4
0
        public void DrawImageWashed(AtlasImage image, Vector2 position, Color4 color)
        {
            SetTexture(image.Atlas.Texture);

            var pos = new Vector2(position.X + image.OffsetX, position.Y + image.OffsetY);

            w0.Pos = modelMatrix.TransformPoint(pos);
            w1.Pos = modelMatrix.TransformPoint(pos.X + image.TrimWidth, pos.Y);
            w2.Pos = modelMatrix.TransformPoint(pos.X + image.TrimWidth, pos.Y + image.TrimHeight);
            w3.Pos = modelMatrix.TransformPoint(pos.X, pos.Y + image.TrimHeight);

            image.GetUVs(out w0.Tex, out w1.Tex, out w2.Tex, out w3.Tex);
            w0.Col = w1.Col = w2.Col = w3.Col = color;

            mesh.AddQuad(ref w0, ref w1, ref w2, ref w3);
        }
Example #5
0
        public AtlasChar AddChar(char chr, int width, int height, int advance, int offsetX, int offsetY, Rectangle uvRect, bool rotate90)
        {
            if (chars.ContainsKey(chr))
            {
                throw new Exception(string.Format("Font already has character: '{0}' (U+{1:X4})", chr, (UInt16)chr));
            }

            var name = chr.ToString();

            AtlasImage image = null;

            if (width > 0)
            {
                image = new AtlasImage(Atlas, ref name, width, height, offsetX, offsetY, width, height, ref uvRect, rotate90);
            }

            var result = new AtlasChar(this, chr, advance, image);

            chars.Add(chr, result);

            return(result);
        }
Example #6
0
 public bool TryGetImage(string name, out AtlasImage result)
 {
     return(images.TryGetValue(name, out result));
 }