Beispiel #1
0
        public static yyRect Create(int _width, int _height)
        {
            yyRect yyRect = new yyRect(0, 0, _width, _height);

            yyRect.Children = new List <yyRect>();
            yyRect.Children.Add(yyRect);
            return(yyRect);
        }
Beispiel #2
0
        public bool Alloc(TexturePageEntry _entry, out int _X, out int _Y)
        {
            bool flag  = false;
            bool flag2 = false;

            _X = -1;
            _Y = -1;
            int num  = GridSizeX;
            int num2 = GridSizeY;
            int num3 = _entry.W;
            int num4 = _entry.H;

            if (_entry.OriginalRepeatBorder)
            {
                num  += _entry.RepeatX;
                num2 += _entry.RepeatY;
            }
            if (num3 < Bitmap.Width)
            {
                num3 += num;
                num3 += num;
                num3  = ((num3 + 3) & -4);
                flag  = true;
            }
            if (num4 < Bitmap.Height)
            {
                num4 += num2;
                num4 += num2;
                num4  = ((num4 + 3) & -4);
                flag2 = true;
            }
            _entry.RepeatBorder = _entry.OriginalRepeatBorder;
            if (!flag || !flag2)
            {
                _entry.RepeatBorder = false;
            }
            yyRect yyRect = TextureRects.Test(num3, num4);

            if (yyRect != null)
            {
                Point point = TextureRects.AddImage(yyRect, num3, num4);
                _X = point.X;
                _Y = point.Y;
                if (flag)
                {
                    _X += num;
                }
                if (flag2)
                {
                    _Y += num2;
                }
                AreaFree -= num3 * num4;
                return(true);
            }
            return(false);
        }
Beispiel #3
0
 public void Resize(int width, int height)
 {
     AreaFree = width * height;
     Bitmap   = new Bitmap(width, height, PixelFormat.Format32bppArgb);
     using (Graphics graphics = Graphics.FromImage(Bitmap))
     {
         graphics.Clear(Color.FromArgb(0));
     }
     TextureRects = yyRect.Create(width, height);
 }
Beispiel #4
0
        public Point AddImage(yyRect _rect, int _width, int _height)
        {
            if (_rect == null)
            {
                return(new Point(-1, -1));
            }
            bool          _full = false;
            List <yyRect> list  = _rect.AddImageEx(_width, _height, out _full);
            int           num   = _rect.x;
            int           num2  = _rect.y;

            if (_full || (list != null && list.Count != 0))
            {
                if (_rect != this)
                {
                    Children.Remove(_rect);
                }
                if (list != null && list.Count != 0)
                {
                    if (Children == null)
                    {
                        Children = new List <yyRect>(64);
                    }
                    AddRange(list);
                }
            }
            List <yyRect> list2 = new List <yyRect>(64);
            List <yyRect> list3 = new List <yyRect>(64);

            foreach (yyRect child in Children)
            {
                _full = false;
                list  = child.Clip(num, num2, _width, _height, out _full);
                if (_full || (list != null && list.Count != 0))
                {
                    list2.Add(child);
                    if (list != null && list.Count != 0)
                    {
                        list3.AddRange(list);
                    }
                }
            }
            foreach (yyRect item in list2)
            {
                Children.Remove(item);
            }
            if (list3.Count != 0)
            {
                AddRange(list3);
            }
            CompactList();
            return(new Point(num, num2));
        }
Beispiel #5
0
        public yyRect Test(int _width, int _height)
        {
            arealeft = 0;
            if (Children.Count == 0)
            {
                return(null);
            }
            yyRect result = null;

            foreach (yyRect child in Children)
            {
                foreach (yyRect child2 in Children)
                {
                    bool _full = false;
                    if (child2.width >= _width && child2.height >= _height)
                    {
                        List <yyRect> list = child.Clip(child2.x, child2.y, _width, _height, out _full);
                        if (list == null && _full)
                        {
                            arealeft = child.arealeft;
                            result   = child2;
                        }
                        else if (list != null && list.Count != 0)
                        {
                            foreach (yyRect item in list)
                            {
                                if (item != null && arealeft < item.arealeft)
                                {
                                    arealeft = item.arealeft;
                                    result   = child2;
                                }
                            }
                        }
                        else if (arealeft < child.arealeft)
                        {
                            arealeft = child.arealeft;
                            result   = child2;
                        }
                    }
                }
            }
            return(result);
        }