57 #ifndef STB_INCLUDE_STB_RECT_PACK_H 58 #define STB_INCLUDE_STB_RECT_PACK_H 60 #define STB_RECT_PACK_VERSION 1 63 #define STBRP_DEF static 65 #define STBRP_DEF extern 76 #ifdef STBRP_LARGE_RECTS 197 #ifdef STB_RECT_PACK_IMPLEMENTATION 200 #define STBRP_SORT qsort 205 #define STBRP_ASSERT assert 209 #define STBRP__NOTUSED(v) (void)(v) 210 #define STBRP__CDECL __cdecl 212 #define STBRP__NOTUSED(v) (void)sizeof(v) 218 STBRP__INIT_skyline = 1
224 case STBRP__INIT_skyline:
235 if (allow_out_of_mem)
256 #ifndef STBRP_LARGE_RECTS 260 for (i=0; i < num_nodes-1; ++i)
261 nodes[i].next = &nodes[i+1];
262 nodes[i].
next = NULL;
263 context->
init_mode = STBRP__INIT_skyline;
277 #ifdef STBRP_LARGE_RECTS 278 context->
extra[1].
y = (1<<30);
280 context->
extra[1].
y = 65535;
290 int min_y, visited_width, waste_area;
298 while (node->
next->
x <= x0)
309 while (node->
x < x1) {
310 if (node->
y > min_y) {
314 waste_area += visited_width * (node->
y - min_y);
318 visited_width += node->
next->
x - x0;
320 visited_width += node->
next->
x - node->
x;
323 int under_width = node->
next->
x - node->
x;
324 if (under_width + visited_width > width)
325 under_width = width - visited_width;
326 waste_area += under_width * (min_y - node->
y);
327 visited_width += under_width;
332 *pwaste = waste_area;
344 int best_waste = (1<<30), best_x, best_y = (1 << 30);
345 stbrp__findresult fr;
346 stbrp_node **prev, *node, *tail, **best = NULL;
357 y = stbrp__skyline_find_min_y(c, node, node->
x, width, &waste);
368 if (y < best_y || (y == best_y && waste < best_waste)) {
379 best_x = (best == NULL) ? 0 : (*best)->
x;
403 while (tail->
x < width)
406 int xpos = tail->
x -
width;
410 while (node->
next->
x <= xpos) {
415 y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
418 if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
440 stbrp__findresult res = stbrp__skyline_find_best_pos(context,
width, height);
447 if (res.prev_link == NULL || res.y + height > context->
height || context->
free_head == NULL) {
448 res.prev_link = NULL;
463 cur = *res.prev_link;
464 if (cur->
x < res.x) {
470 *res.prev_link = node;
486 if (cur->
x < res.x +
width)
491 while (cur->
x < context->
width) {
516 static int STBRP__CDECL rect_height_compare(
const void *a,
const void *b)
524 return (p->
w > q->
w) ? -1 : (p->
w < q->
w);
527 static int STBRP__CDECL rect_original_order(
const void *a,
const void *b)
534 #ifdef STBRP_LARGE_RECTS 535 #define STBRP__MAXVAL 0xffffffff 537 #define STBRP__MAXVAL 0xffff 542 int i, all_rects_packed = 1;
545 for (i=0; i < num_rects; ++i) {
547 #ifndef STBRP_LARGE_RECTS 553 STBRP_SORT(rects, num_rects,
sizeof(rects[0]), rect_height_compare);
555 for (i=0; i < num_rects; ++i) {
556 if (rects[i].
w == 0 || rects[i].
h == 0) {
557 rects[i].
x = rects[i].
y = 0;
559 stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].
w, rects[i].
h);
564 rects[i].
x = rects[i].
y = STBRP__MAXVAL;
570 STBRP_SORT(rects, num_rects,
sizeof(rects[0]), rect_original_order);
573 for (i=0; i < num_rects; ++i) {
574 rects[i].
was_packed = !(rects[i].
x == STBRP__MAXVAL && rects[i].
y == STBRP__MAXVAL);
576 all_rects_packed = 0;
580 return all_rects_packed;
stbrp_node extra[2]
Definition: stb_rect_pack.h:183
int int int int height
Definition: wglext.h:61
int height
Definition: stb_rect_pack.h:176
Definition: stb_rect_pack.h:107
Definition: stb_rect_pack.h:167
int int int width
Definition: wglext.h:61
#define STBRP_DEF
Definition: stb_rect_pack.h:65
unsigned short stbrp_coord
Definition: stb_rect_pack.h:79
stbrp_coord y
Definition: stb_rect_pack.h:169
void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
stbrp_coord y
Definition: stb_rect_pack.h:116
#define STBRP_ASSERT(x)
Definition: imgui_draw.cpp:101
int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
Definition: stb_rect_pack.h:157
int was_packed
Definition: stb_rect_pack.h:117
stbrp_node * next
Definition: stb_rect_pack.h:170
stbrp_coord x
Definition: stb_rect_pack.h:116
stbrp_node * free_head
Definition: stb_rect_pack.h:182
int align
Definition: stb_rect_pack.h:177
int init_mode
Definition: stb_rect_pack.h:178
Definition: stb_rect_pack.h:156
Definition: stb_rect_pack.h:158
stbrp_coord w
Definition: stb_rect_pack.h:113
int heuristic
Definition: stb_rect_pack.h:179
stbrp_node * active_head
Definition: stb_rect_pack.h:181
Definition: stb_rect_pack.h:173
int width
Definition: stb_rect_pack.h:175
stbrp_coord x
Definition: stb_rect_pack.h:169
stbrp_coord h
Definition: stb_rect_pack.h:113
int num_nodes
Definition: stb_rect_pack.h:180
int id
Definition: stb_rect_pack.h:110
void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
const HANDLE const LPVOID const DWORD UINT count
Definition: wglext.h:590