コード例 #1
0
    public List <UbimonIcon> Fit(List <Ubimon> list, Ubimon toAdd = null)
    {
        List <UbimonIcon> result = SortedIcons(list, toAdd);

        var heap = new Heap();

        heap.Push(view);
        for (int i = 0; i < result.Count; ++i)
        {
            UbimonIconCanvas canvas = result[i].canvas;

            // Gets the largest available region...
            UbimonIconCanvas r = heap.Pop();
            if (!r.Fits(canvas.width, canvas.height))
            {
                return(null);
            }

            // Uses this region's position...
            canvas.x = r.x;
            canvas.y = r.y;

            // Splits the largest region in remaining spaces...
            heap.Push(new UbimonIconCanvas(r.x + canvas.width, r.y, r.width - canvas.width, r.height));
            heap.Push(new UbimonIconCanvas(r.x, r.y + canvas.height, canvas.width, r.height - canvas.height));
        }

        return(result);
    }
コード例 #2
0
 public UbimonIconCanvas Pop()
 {
     if (heap.Count > 0)
     {
         UbimonIconCanvas c = heap[0];
         heap[0] = heap[heap.Count - 1];
         heap.RemoveAt(heap.Count - 1);
         Heapify(0);
         return(c);
     }
     return(null);
 }
コード例 #3
0
        public void Push(UbimonIconCanvas canvas)
        {
            int i = heap.Count, parent;

            heap.Add(canvas);

            while ((i > 0) && (heap[parent = ((i - 1) >> 1)].area < heap[i].area))
            {
                var aux = heap[parent];
                heap[parent] = heap[i];
                heap[i]      = aux;
                i            = parent;
            }
        }
コード例 #4
0
 public UbimonContainer(int x, int y, int width, int height)
 {
     view = new UbimonIconCanvas(x, y, width, height);
 }