Beispiel #1
0
        public static void nk_rp_pack_rects(nk_rp_context *context, nk_rp_rect *rects, int num_rects)
        {
            int i;

            for (i = (int)(0); (i) < (num_rects); ++i)
            {
                rects[i].was_packed = (int)(i);
            }
            nk_rp_qsort(rects, (uint)(num_rects), nk_rect_height_compare);
            for (i = (int)(0); (i) < (num_rects); ++i)
            {
                nk_rp__findresult fr =
                    (nk_rp__findresult)(nk_rp__skyline_pack_rectangle(context, (int)(rects[i].w), (int)(rects[i].h)));
                if ((fr.prev_link) != null)
                {
                    rects[i].x = ((ushort)(fr.x));
                    rects[i].y = ((ushort)(fr.y));
                }
                else
                {
                    rects[i].x = (ushort)(rects[i].y = (ushort)(0xffff));
                }
            }
            nk_rp_qsort(rects, (uint)(num_rects), nk_rect_original_order);
            for (i = (int)(0); (i) < (num_rects); ++i)
            {
                rects[i].was_packed = (int)((((rects[i].x) == (0xffff)) && ((rects[i].y) == (0xffff))) ? 0 : 1);
            }
        }
Beispiel #2
0
        public static nk_rp__findresult nk_rp__skyline_pack_rectangle(nk_rp_context *context, int width, int height)
        {
            nk_rp__findresult res = (nk_rp__findresult)(nk_rp__skyline_find_best_pos(context, (int)(width), (int)(height)));
            nk_rp_node *      node;
            nk_rp_node *      cur;

            if ((((res.prev_link) == (null)) || ((res.y + height) > (context->height))) || ((context->free_head) == (null)))
            {
                res.prev_link = null;
                return((nk_rp__findresult)(res));
            }

            node               = context->free_head;
            node->x            = ((ushort)(res.x));
            node->y            = ((ushort)(res.y + height));
            context->free_head = node->next;
            cur = *res.prev_link;
            if ((cur->x) < (res.x))
            {
                nk_rp_node *next = cur->next;
                cur->next = node;
                cur       = next;
            }
            else
            {
                *res.prev_link = node;
            }

            while (((cur->next) != null) && (cur->next->x <= res.x + width))
            {
                nk_rp_node *next = cur->next;
                cur->next          = context->free_head;
                context->free_head = cur;
                cur = next;
            }
            node->next = cur;
            if ((cur->x) < (res.x + width))
            {
                cur->x = ((ushort)(res.x + width));
            }
            return((nk_rp__findresult)(res));
        }
Beispiel #3
0
        public static nk_rp__findresult nk_rp__skyline_find_best_pos(nk_rp_context *c, int width, int height)
        {
            int best_waste = (int)(1 << 30);
            int best_x;
            int best_y           = (int)(1 << 30);
            nk_rp__findresult fr = new nk_rp__findresult();
            nk_rp_node **     prev;
            nk_rp_node *      node;
            nk_rp_node *      tail;
            nk_rp_node **     best = null;

            width  = (int)(width + c->align - 1);
            width -= (int)(width % c->align);
            node   = c->active_head;
            prev   = &c->active_head;
            while (node->x + width <= c->width)
            {
                int y;
                int waste;
                y = (int)(nk_rp__skyline_find_min_y(c, node, (int)(node->x), (int)(width), &waste));
                if ((c->heuristic) == (NK_RP_HEURISTIC_Skyline_BL_sortHeight))
                {
                    if ((y) < (best_y))
                    {
                        best_y = (int)(y);
                        best   = prev;
                    }
                }
                else
                {
                    if (y + height <= c->height)
                    {
                        if (((y) < (best_y)) || (((y) == (best_y)) && ((waste) < (best_waste))))
                        {
                            best_y     = (int)(y);
                            best_waste = (int)(waste);
                            best       = prev;
                        }
                    }
                }
                prev = &node->next;
                node = node->next;
            }
            best_x = (int)(((best) == (null)) ? 0 : (*best)->x);
            if ((c->heuristic) == (NK_RP_HEURISTIC_Skyline_BF_sortHeight))
            {
                tail = c->active_head;
                node = c->active_head;
                prev = &c->active_head;
                while ((tail->x) < (width))
                {
                    tail = tail->next;
                }
                while ((tail) != null)
                {
                    int xpos = (int)(tail->x - width);
                    int y;
                    int waste;
                    while (node->next->x <= xpos)
                    {
                        prev = &node->next;
                        node = node->next;
                    }
                    y = (int)(nk_rp__skyline_find_min_y(c, node, (int)(xpos), (int)(width), &waste));
                    if ((y + height) < (c->height))
                    {
                        if (y <= best_y)
                        {
                            if ((((y) < (best_y)) || ((waste) < (best_waste))) || (((waste) == (best_waste)) && ((xpos) < (best_x))))
                            {
                                best_x     = (int)(xpos);
                                best_y     = (int)(y);
                                best_waste = (int)(waste);
                                best       = prev;
                            }
                        }
                    }
                    tail = tail->next;
                }
            }

            fr.prev_link = best;
            fr.x         = (int)(best_x);
            fr.y         = (int)(best_y);
            return((nk_rp__findresult)(fr));
        }