Skip to content

Commit 279db55

Browse files
committed
Updated stb_rect_pack.h from 1.00 to 1.01. (ocornut#5075)
(our STBRP__CDECL change was merged)
1 parent 3deb92c commit 279db55

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

docs/CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Other Changes:
6363
- Misc: Fixed IsAnyItemHovered() returning false when using navigation.
6464
- Misc: Added IMGUI_STB_SPRINTF_FILENAME to support custom path to stb_sprintf. (#5068, #2954) [@jakubtomsu]
6565
- Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan]
66+
- Misc: Updated stb_rect_pack.h from 1.00 to 1.01. (#5075)
6667
- Misc: binary_to_compressed_c tool: Added -nostatic option. (#5021) [@podsvirov]
6768
- ImVector: Fixed erase() with empty range. (#5009) [@thedmd]
6869
- Drawlist: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd]

imgui_draw.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2637,8 +2637,8 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opa
26372637
for (int i = 0; i < pack_rects.Size; i++)
26382638
if (pack_rects[i].was_packed)
26392639
{
2640-
user_rects[i].X = pack_rects[i].x;
2641-
user_rects[i].Y = pack_rects[i].y;
2640+
user_rects[i].X = (unsigned short)pack_rects[i].x;
2641+
user_rects[i].Y = (unsigned short)pack_rects[i].y;
26422642
IM_ASSERT(pack_rects[i].w == user_rects[i].Width && pack_rects[i].h == user_rects[i].Height);
26432643
atlas->TexHeight = ImMax(atlas->TexHeight, pack_rects[i].y + pack_rects[i].h);
26442644
}

imstb_rectpack.h

+15-27
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// [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.
53
// 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
86
// Sean Barrett 2014
97
//
108
// Useful for e.g. packing rectangular textures into an atlas.
119
// Does not do rotation.
1210
//
11+
// Before #including,
12+
//
13+
// #define STB_RECT_PACK_IMPLEMENTATION
14+
//
15+
// in the file that you want to have the implementation.
16+
//
1317
// Not necessarily the awesomest packing method, but better than
1418
// the totally naive one in stb_truetype (which is primarily what
1519
// this is meant to replace).
@@ -41,6 +45,7 @@
4145
//
4246
// Version history:
4347
//
48+
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
4449
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
4550
// 0.99 (2019-02-07) warning fixes
4651
// 0.11 (2017-03-03) return packing success/fail result
@@ -81,11 +86,10 @@ typedef struct stbrp_context stbrp_context;
8186
typedef struct stbrp_node stbrp_node;
8287
typedef struct stbrp_rect stbrp_rect;
8388

84-
#ifdef STBRP_LARGE_RECTS
8589
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.
8993

9094
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
9195
// Assign packed locations to rectangles. The rectangles are of type
@@ -213,10 +217,9 @@ struct stbrp_context
213217
#define STBRP_ASSERT assert
214218
#endif
215219

216-
// [DEAR IMGUI] Added STBRP__CDECL
217220
#ifdef _MSC_VER
218221
#define STBRP__NOTUSED(v) (void)(v)
219-
#define STBRP__CDECL __cdecl
222+
#define STBRP__CDECL __cdecl
220223
#else
221224
#define STBRP__NOTUSED(v) (void)sizeof(v)
222225
#define STBRP__CDECL
@@ -262,9 +265,6 @@ STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_ou
262265
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
263266
{
264267
int i;
265-
#ifndef STBRP_LARGE_RECTS
266-
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
267-
#endif
268268

269269
for (i=0; i < num_nodes-1; ++i)
270270
nodes[i].next = &nodes[i+1];
@@ -283,11 +283,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
283283
context->extra[0].y = 0;
284284
context->extra[0].next = &context->extra[1];
285285
context->extra[1].x = (stbrp_coord) width;
286-
#ifdef STBRP_LARGE_RECTS
287286
context->extra[1].y = (1<<30);
288-
#else
289-
context->extra[1].y = 65535;
290-
#endif
291287
context->extra[1].next = NULL;
292288
}
293289

@@ -433,7 +429,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
433429
if (y <= best_y) {
434430
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
435431
best_x = xpos;
436-
STBRP_ASSERT(y <= best_y);
432+
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
437433
best_y = y;
438434
best_waste = waste;
439435
best = prev;
@@ -529,7 +525,6 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
529525
return res;
530526
}
531527

532-
// [DEAR IMGUI] Added STBRP__CDECL
533528
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
534529
{
535530
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)
541536
return (p->w > q->w) ? -1 : (p->w < q->w);
542537
}
543538

544-
// [DEAR IMGUI] Added STBRP__CDECL
545539
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
546540
{
547541
const stbrp_rect *p = (const stbrp_rect *) a;
548542
const stbrp_rect *q = (const stbrp_rect *) b;
549543
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
550544
}
551545

552-
#ifdef STBRP_LARGE_RECTS
553-
#define STBRP__MAXVAL 0xffffffff
554-
#else
555-
#define STBRP__MAXVAL 0xffff
556-
#endif
557-
558546
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
559547
{
560548
int i, all_rects_packed = 1;

0 commit comments

Comments
 (0)