Exemplo n.º 1
0
        //--------------------
        internal void WriteAtlasItems(Dictionary <ushort, AtlasItem> items)
        {
            //total number
            int totalNum = items.Count;

#if DEBUG
            if (totalNum >= ushort.MaxValue)
            {
                throw new NotSupportedException();
            }
#endif

            _writer.Write((ushort)ObjectKind.GlyphList);
            //count
            _writer.Write((ushort)totalNum);
            //
            foreach (var kp in items)
            {
                ushort    uniqueName = kp.Key;
                AtlasItem g          = kp.Value;
                //1. unique uint16 name
                _writer.Write((ushort)uniqueName);

                //2. area, left,top,width,height
                _writer.Write((ushort)g.Left);
                _writer.Write((ushort)g.Top);
                _writer.Write((ushort)g.Width);
                _writer.Write((ushort)g.Height);

                //3. texture offset
                _writer.Write((short)g.TextureXOffset); //short
                _writer.Write((short)g.TextureYOffset); //short
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// try get atlas item by unique name
 /// </summary>
 /// <param name="uniqueUint16Name"></param>
 /// <param name="atlasItem"></param>
 /// <returns></returns>
 public bool TryGetItem(ushort uniqueUint16Name, out AtlasItem atlasItem)
 {
     if (!_atlasItems.TryGetValue(uniqueUint16Name, out atlasItem))
     {
         atlasItem = null;
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
 /// <summary>
 /// try get atlas item by unique name
 /// </summary>
 /// <param name="itemName"></param>
 /// <param name="atlasItem"></param>
 /// <returns></returns>
 public bool TryGetItem(string itemName, out AtlasItem atlasItem)
 {
     //get img item by unique name
     if (ImgUrlDict != null &&
         ImgUrlDict.TryGetValue(itemName, out ushort foundIndex) &&
         _atlasItems.TryGetValue(foundIndex, out atlasItem))
     {
         return(true);
     }
     atlasItem = null;
     return(false);
 }
Exemplo n.º 4
0
        public static Dictionary <ushort, AtlasItem> CloneLocationWithOffset(SimpleBitmapAtlas org, int dx, int dy)
        {
            Dictionary <ushort, AtlasItem> cloneDic = new Dictionary <ushort, AtlasItem>();

            foreach (var kp in org._atlasItems)
            {
                AtlasItem orgMapData = kp.Value;
                cloneDic.Add(kp.Key, new AtlasItem(orgMapData.UniqueUint16Name)
                {
                    Left = orgMapData.Left + dx,
                    Top  = orgMapData.Top + dy,
                    //
                    Width          = orgMapData.Width,
                    Height         = orgMapData.Height,
                    TextureXOffset = orgMapData.TextureXOffset,
                    TextureYOffset = orgMapData.TextureYOffset
                });
            }
            return(cloneDic);
        }
Exemplo n.º 5
0
        void ReadAtlasItems(BinaryReader reader)
        {
            ushort itemCount = reader.ReadUInt16();

            for (int i = 0; i < itemCount; ++i)
            {
                //read each glyph map info

                var item = new AtlasItem(reader.ReadUInt16());

                //2. area
                item.Left   = reader.ReadUInt16();
                item.Top    = reader.ReadUInt16();
                item.Width  = reader.ReadUInt16();
                item.Height = reader.ReadUInt16();

                //3. texture offset
                item.TextureXOffset = reader.ReadInt16();
                item.TextureYOffset = reader.ReadInt16();

                _atlas.AddAtlasItem(item);
            }
        }
Exemplo n.º 6
0
 internal void AddAtlasItem(AtlasItem item)
 {
     _atlasItems.Add(item.UniqueUint16Name, item);
 }
Exemplo n.º 7
0
 /// <summary>
 /// try get atlas item by unique name
 /// </summary>
 /// <param name="uniqueUint16Name"></param>
 /// <param name="atlasItem"></param>
 /// <returns></returns>
 public bool TryGetItem(ushort uniqueUint16Name, out AtlasItem atlasItem) => _atlasItems.TryGetValue(uniqueUint16Name, out atlasItem);