1
1
// [DEAR IMGUI]
2
- // This is a slightly modified version of stb_rect_pack.h 1.00.
3
- // Those changes would need to be pushed into nothings/stb:
4
- // - Added STBRP__CDECL
2
+ // This is a slightly modified version of stb_rect_pack.h 1.01.
5
3
// Grep for [DEAR IMGUI] to find the changes.
6
-
7
- // stb_rect_pack.h - v1.00 - public domain - rectangle packing
4
+ //
5
+ // stb_rect_pack.h - v1.01 - public domain - rectangle packing
8
6
// Sean Barrett 2014
9
7
//
10
8
// Useful for e.g. packing rectangular textures into an atlas.
11
9
// Does not do rotation.
12
10
//
11
+ // Before #including,
12
+ //
13
+ // #define STB_RECT_PACK_IMPLEMENTATION
14
+ //
15
+ // in the file that you want to have the implementation.
16
+ //
13
17
// Not necessarily the awesomest packing method, but better than
14
18
// the totally naive one in stb_truetype (which is primarily what
15
19
// this is meant to replace).
41
45
//
42
46
// Version history:
43
47
//
48
+ // 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
44
49
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
45
50
// 0.99 (2019-02-07) warning fixes
46
51
// 0.11 (2017-03-03) return packing success/fail result
@@ -81,11 +86,10 @@ typedef struct stbrp_context stbrp_context;
81
86
typedef struct stbrp_node stbrp_node ;
82
87
typedef struct stbrp_rect stbrp_rect ;
83
88
84
- #ifdef STBRP_LARGE_RECTS
85
89
typedef int stbrp_coord ;
86
- #else
87
- typedef unsigned short stbrp_coord ;
88
- #endif
90
+
91
+ #define STBRP__MAXVAL 0x7fffffff
92
+ // Mostly for internal use, but this is the maximum supported coordinate value.
89
93
90
94
STBRP_DEF int stbrp_pack_rects (stbrp_context * context , stbrp_rect * rects , int num_rects );
91
95
// Assign packed locations to rectangles. The rectangles are of type
@@ -213,10 +217,9 @@ struct stbrp_context
213
217
#define STBRP_ASSERT assert
214
218
#endif
215
219
216
- // [DEAR IMGUI] Added STBRP__CDECL
217
220
#ifdef _MSC_VER
218
221
#define STBRP__NOTUSED (v ) (void)(v)
219
- #define STBRP__CDECL __cdecl
222
+ #define STBRP__CDECL __cdecl
220
223
#else
221
224
#define STBRP__NOTUSED (v ) (void)sizeof(v)
222
225
#define STBRP__CDECL
@@ -262,9 +265,6 @@ STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_ou
262
265
STBRP_DEF void stbrp_init_target (stbrp_context * context , int width , int height , stbrp_node * nodes , int num_nodes )
263
266
{
264
267
int i ;
265
- #ifndef STBRP_LARGE_RECTS
266
- STBRP_ASSERT (width <= 0xffff && height <= 0xffff );
267
- #endif
268
268
269
269
for (i = 0 ; i < num_nodes - 1 ; ++ i )
270
270
nodes [i ].next = & nodes [i + 1 ];
@@ -283,11 +283,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
283
283
context -> extra [0 ].y = 0 ;
284
284
context -> extra [0 ].next = & context -> extra [1 ];
285
285
context -> extra [1 ].x = (stbrp_coord ) width ;
286
- #ifdef STBRP_LARGE_RECTS
287
286
context -> extra [1 ].y = (1 <<30 );
288
- #else
289
- context -> extra [1 ].y = 65535 ;
290
- #endif
291
287
context -> extra [1 ].next = NULL ;
292
288
}
293
289
@@ -433,7 +429,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
433
429
if (y <= best_y ) {
434
430
if (y < best_y || waste < best_waste || (waste == best_waste && xpos < best_x )) {
435
431
best_x = xpos ;
436
- STBRP_ASSERT (y <= best_y );
432
+ // STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
437
433
best_y = y ;
438
434
best_waste = waste ;
439
435
best = prev ;
@@ -529,7 +525,6 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
529
525
return res ;
530
526
}
531
527
532
- // [DEAR IMGUI] Added STBRP__CDECL
533
528
static int STBRP__CDECL rect_height_compare (const void * a , const void * b )
534
529
{
535
530
const stbrp_rect * p = (const stbrp_rect * ) a ;
@@ -541,20 +536,13 @@ static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
541
536
return (p -> w > q -> w ) ? -1 : (p -> w < q -> w );
542
537
}
543
538
544
- // [DEAR IMGUI] Added STBRP__CDECL
545
539
static int STBRP__CDECL rect_original_order (const void * a , const void * b )
546
540
{
547
541
const stbrp_rect * p = (const stbrp_rect * ) a ;
548
542
const stbrp_rect * q = (const stbrp_rect * ) b ;
549
543
return (p -> was_packed < q -> was_packed ) ? -1 : (p -> was_packed > q -> was_packed );
550
544
}
551
545
552
- #ifdef STBRP_LARGE_RECTS
553
- #define STBRP__MAXVAL 0xffffffff
554
- #else
555
- #define STBRP__MAXVAL 0xffff
556
- #endif
557
-
558
546
STBRP_DEF int stbrp_pack_rects (stbrp_context * context , stbrp_rect * rects , int num_rects )
559
547
{
560
548
int i , all_rects_packed = 1 ;
0 commit comments