@@ -506,6 +506,8 @@ class FontAtlas {
506506
507507 if (cursor <= MouseCursor .None || cursor >= MouseCursor .Count ) return false
508508
509+ if (flags has Flags .NoMouseCursors ) return false
510+
509511 val r = customRects[customRectIds[0 ]]
510512 assert (r.id == DefaultTexData .id)
511513 val pos = DefaultTexData .cursorDatas[cursor.i][0 ] + Vec2 (r.x, r.y)
@@ -526,6 +528,20 @@ class FontAtlas {
526528 // Members
527529 // -------------------------------------------
528530
531+ enum class Flags {
532+ /* * Don't round the height to next power of two */
533+ NoPowerOfTwoHeight ,
534+ /* * Don't build software mouse cursors into the atlas */
535+ NoMouseCursors ;
536+
537+ val i = 1 shl ordinal
538+ }
539+
540+ infix fun Int.has (flag : Flags ) = and (flag.i) != 0
541+ infix fun Int.hasnt (flag : Flags ) = and (flag.i) == 0
542+
543+ /* * Build flags (see ImFontAtlasFlags_) */
544+ var flags = 0
529545 /* * User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you
530546 during rendering via the DrawCmd structure. */
531547 var texId = - 1
@@ -608,7 +624,7 @@ class FontAtlas {
608624 // Start packing
609625 val maxTexHeight = 1024 * 32
610626 val spc = STBTTPackContext .create()
611- if (! stbtt_PackBegin(spc, null , texSize.x, maxTexHeight, 0 , texGlyphPadding, MemoryUtil .NULL ))
627+ if (! stbtt_PackBegin(spc, null , texSize.x, maxTexHeight, 0 , texGlyphPadding, MemoryUtil .NULL ))
612628 return false
613629
614630 /* Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have
@@ -698,7 +714,7 @@ class FontAtlas {
698714 assert (bufRangesN == totalRangesCount)
699715
700716 // Create texture
701- texSize.y = texSize.y.upperPowerOfTwo
717+ texSize.y = if (flags has Flags . NoPowerOfTwoHeight ) texSize.y + 1 else texSize.y.upperPowerOfTwo
702718 texUvScale = 1f / Vec2 (texSize)
703719 texPixelsAlpha8 = bufferBig(texSize.x * texSize.y)
704720 spc.pixels = texPixelsAlpha8!!
@@ -768,8 +784,11 @@ class FontAtlas {
768784 }
769785
770786 fun buildRegisterDefaultCustomRects () {
771- if (customRectIds[0 ] < 0 )
772- customRectIds[0 ] = addCustomRectRegular(DefaultTexData .id, DefaultTexData .wHalf * 2 + 1 , DefaultTexData .h)
787+ if (customRectIds[0 ] >= 0 ) return
788+ customRectIds[0 ] = when {
789+ flags hasnt Flags .NoMouseCursors -> addCustomRectRegular(DefaultTexData .id, DefaultTexData .wHalf * 2 + 1 , DefaultTexData .h)
790+ else -> addCustomRectRegular(DefaultTexData .id, 2 , 2 )
791+ }
773792 }
774793
775794 fun buildSetupFont (font : Font , fontConfig : FontConfig , ascent : Float , descent : Float ) {
@@ -828,21 +847,34 @@ class FontAtlas {
828847
829848 fun buildRenderDefaultTexData () {
830849
850+ assert (customRectIds[0 ] >= 0 && texPixelsAlpha8 != null )
831851 val r = customRects[customRectIds[0 ]]
832- assert (r.width == DefaultTexData .wHalf * 2 + 1 && r.height == DefaultTexData .h)
833- assert (r.isPacked && texPixelsAlpha8 != null )
834-
835- // Render/copy pixels
836- var n = 0
837- for (y in 0 until DefaultTexData .h)
838- for (x in 0 until DefaultTexData .wHalf) {
839- val offset0 = r.x + x + (r.y + y) * texSize.x
840- val offset1 = offset0 + DefaultTexData .wHalf + 1
841- texPixelsAlpha8!! [offset0] = if (DefaultTexData .pixels[n] == ' .' ) 0xFF .b else 0x00 .b
842- texPixelsAlpha8!! [offset1] = if (DefaultTexData .pixels[n] == ' X' ) 0xFF .b else 0x00 .b
843- n++
852+ assert (r.id == DefaultTexData .id && r.isPacked)
853+
854+ val w = texSize.x
855+ if (flags hasnt Flags .NoMouseCursors ) {
856+ // Render/copy pixels
857+ assert (r.width == DefaultTexData .wHalf * 2 + 1 && r.height == DefaultTexData .h)
858+ var n = 0
859+ for (y in 0 until DefaultTexData .h)
860+ for (x in 0 until DefaultTexData .wHalf) {
861+ val offset0 = r.x + x + (r.y + y) * w
862+ val offset1 = offset0 + DefaultTexData .wHalf + 1
863+ texPixelsAlpha8!! [offset0] = if (DefaultTexData .pixels[n] == ' .' ) 0xFF .b else 0x00 .b
864+ texPixelsAlpha8!! [offset1] = if (DefaultTexData .pixels[n] == ' X' ) 0xFF .b else 0x00 .b
865+ n++
866+ }
867+ } else {
868+ assert (r.width == 2 && r.height == 2 )
869+ val offset = r.x.i + r.y.i * w
870+ with (texPixelsAlpha8!! ) {
871+ put(offset + w + 1 , 0xFF .b)
872+ put(offset + w, 0xFF .b)
873+ put(offset + 1 , 0xFF .b)
874+ put(offset, 0xFF .b)
844875 }
845- texUvWhitePixel = (r.x + 0.5f ) * texUvScale
876+ }
877+ texUvWhitePixel = (Vec2 (r.x, r.y) + 0.5f ) * texUvScale
846878 }
847879
848880 fun buildMultiplyCalcLookupTable (inBrightenFactor : Float ) = CharArray (256 , {
0 commit comments