From 34e5daa2fddd40120a79edba9de586e0948c6cf1 Mon Sep 17 00:00:00 2001 From: tfabretti Date: Mon, 27 Mar 2023 12:36:32 +0200 Subject: [PATCH 1/3] [Style] Addition of the support of background-image-repeat --- haxe/ui/backend/heaps/StyleHelper.hx | 183 ++++++++++++++++++++++++--- 1 file changed, 163 insertions(+), 20 deletions(-) diff --git a/haxe/ui/backend/heaps/StyleHelper.hx b/haxe/ui/backend/heaps/StyleHelper.hx index adb64ff..950d84f 100644 --- a/haxe/ui/backend/heaps/StyleHelper.hx +++ b/haxe/ui/backend/heaps/StyleHelper.hx @@ -125,36 +125,89 @@ class StyleHelper { style.backgroundImageSliceRight - style.backgroundImageSliceLeft, style.backgroundImageSliceBottom - style.backgroundImageSliceTop); } - + if (trc != null) { tile = tile.sub(trc.left, trc.top, trc.width, trc.height); } + if (slice != null) { var rects:Slice9Rects = Slice9.buildRects(w, h, trc.width, trc.height, slice); var srcRects:Array = rects.src; var dstRects:Array = rects.dst; - paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); - paintTile(bgImageGraphics, tile, srcRects[1], dstRects[1]); - paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); - - srcRects[3].bottom--; - paintTile(bgImageGraphics, tile, srcRects[3], dstRects[3]); - - srcRects[4].bottom--; - paintTile(bgImageGraphics, tile, srcRects[4], dstRects[4]); + if (style.backgroundImageRepeat == "repeat") { + // The image is slightly scaled down to make sure there is no visible clip one the sides + var scaleX = dstRects[4].width / ( srcRects[4].width * Math.ceil(dstRects[4].width / srcRects[4].width) ); + var scaleY = dstRects[4].height / ( srcRects[4].height * Math.ceil(dstRects[4].height / srcRects[4].height) ); + + paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); + paintTileRepeat(bgImageGraphics, tile, srcRects[1], scaleX, 1, dstRects[1]); + paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); + + srcRects[3].bottom--; + paintTileRepeat(bgImageGraphics, tile, srcRects[3], 1, scaleY, dstRects[3]); + + srcRects[4].bottom--; + paintTileRepeat(bgImageGraphics, tile, srcRects[4], scaleX, scaleY, dstRects[4]); + + srcRects[5].bottom--; + paintTileRepeat(bgImageGraphics, tile, srcRects[5], 1, scaleY, dstRects[5]); + + dstRects[6].bottom++; + paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); + dstRects[7].bottom++; + paintTileRepeat(bgImageGraphics, tile, srcRects[7], scaleX, 1, dstRects[7]); + dstRects[8].bottom++; + paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); + } + else { + paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); + paintTile(bgImageGraphics, tile, srcRects[1], dstRects[1]); + paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); + + srcRects[3].bottom--; + paintTile(bgImageGraphics, tile, srcRects[3], dstRects[3]); + + srcRects[4].bottom--; + paintTile(bgImageGraphics, tile, srcRects[4], dstRects[4]); + + srcRects[5].bottom--; + paintTile(bgImageGraphics, tile, srcRects[5], dstRects[5]); + + dstRects[6].bottom++; + paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); + dstRects[7].bottom++; + paintTile(bgImageGraphics, tile, srcRects[7], dstRects[7]); + dstRects[8].bottom++; + paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); + } + } else { + var scaleX:Float = 1; + var scaleY:Float = 1; - srcRects[5].bottom--; - paintTile(bgImageGraphics, tile, srcRects[5], dstRects[5]); + if (style.backgroundImageRepeat == null || style.backgroundImageRepeat == "stretch") { + scaleX = w / trc.width; + scaleY = h / trc.height; + } + else { + if (style.backgroundWidth != null) { + scaleX = style.backgroundWidth / trc.width; + } else if (style.backgroundWidthPercent != null) { + scaleX = ((w / trc.width) * style.backgroundWidthPercent) / 100; + } + if (style.backgroundHeight != null) { + scaleY = style.backgroundHeight / trc.height; + } else if (style.backgroundHeightPercent != null) { + scaleY = ((h / trc.height) * style.backgroundHeightPercent) / 100; + } + } - dstRects[6].bottom++; - paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); - dstRects[7].bottom++; - paintTile(bgImageGraphics, tile, srcRects[7], dstRects[7]); - dstRects[8].bottom++; - paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); - } else { - paintTile(bgImageGraphics, tile, trc, new Rectangle(0, 0, w, h)); + if (style.backgroundImageRepeat == "repeat") { + paintTileRepeat(bgImageGraphics, tile, trc, scaleX, scaleY, new Rectangle(0, 0, w, h)); + } + else { + paintTile(bgImageGraphics, tile, trc, new Rectangle(0, 0, trc.width * scaleX, trc.height * scaleY)); + } } }); } @@ -223,4 +276,94 @@ class StyleHelper { g.drawRect(dst.left, dst.top, dst.width, dst.height); g.endFill(); } + + // Used to repeat part (src) of an image (tile) with a given scale (srcScaleX, srcScaleY) inside a target (dst) + private static function paintTileRepeat(g:Graphics, tile:Tile, src:Rectangle, srcScaleX:Float, srcScaleY:Float, dst:Rectangle) { + var scaledw = srcScaleX * src.width; + var scaledh = srcScaleY * src.height; + var wCount = dst.width / scaledw; + var hCount = dst.height / scaledh; + + var iwCount = Math.ceil(wCount); + var ihCount = Math.ceil(hCount); + + var lastw = iwCount - 1; + var lasth = ihCount - 1; + + // Full images + for (iwCurr in 0...lastw) { + for (ihCurr in 0...lasth) { + paintTile(g, tile, src, new Rectangle(dst.left + iwCurr * scaledw, dst.top + ihCurr * scaledh, scaledw, scaledh)); + } + } + + var localRect = src.copy(); + // Images clipped in width + var clippedw = (wCount - lastw) * scaledw; + localRect.width = (wCount - lastw) * src.width; + for (ihCurr in 0...lasth) { + paintTile(g, tile, localRect, new Rectangle(dst.left + lastw * scaledw, dst.top + ihCurr * scaledh, clippedw, scaledh)); + } + + // Images clipped in height + var clippedh = (hCount - lasth) * scaledh; + localRect.width = src.width; + localRect.height = (hCount - lasth) * src.height; + for (iwCurr in 0...lastw) { + paintTile(g, tile, localRect, new Rectangle(dst.left + iwCurr * scaledw, dst.top + lasth * scaledh, scaledw, clippedh)); + } + + // Image clipped in both + localRect.width = (wCount - lastw) * src.width; + if (localRect.width > 1 && localRect.height > 1) { + paintTile(g, tile, localRect, new Rectangle(dst.left + lastw * scaledw, dst.top + lasth * scaledh, clippedw, clippedh)); + } + } + + // copy of draw round rect without lines as it seems to misdraw (at different scales - strange) + public static function drawRoundedRect(gfx:Graphics, x : Float, y : Float, w : Float, h : Float, radius : Float, nsegments = 0 ) { + if (radius <= 0) { + gfx.drawRect(x, y, w, h); + return false; + } + var returnVal = true; + if (w == h && radius >= w / 2) { + radius = (w / 2) + 1; + returnVal = false; + } + x += radius; + y += radius; + w -= radius * 2; + h -= radius * 2; + @:privateAccess gfx.flush(); + if( nsegments == 0 ) + nsegments = Math.ceil(Math.abs(radius * hxd.Math.degToRad(90) / 4)); + if ( nsegments < 3 ) nsegments = 3; + var angle = hxd.Math.degToRad(90) / (nsegments - 1); + inline function corner(x, y, angleStart) { + for ( i in 0...nsegments) { + var a = i * angle + hxd.Math.degToRad(angleStart); + gfx.lineTo(x + Math.cos(a) * radius, y + Math.sin(a) * radius); + } + } + if (Toolkit.scale == 1 && returnVal == true) { + gfx.lineTo(x, y - radius); + gfx.lineTo(x + w, y - radius); + } + corner(x + w, y, 270); + if (Toolkit.scale == 1 && returnVal == true) { + gfx.lineTo(x + w + radius, y + h); + } + corner(x + w, y + h, 0); + if (Toolkit.scale == 1 && returnVal == true) { + gfx.lineTo(x, y + h + radius); + } + corner(x, y + h, 90); + if (Toolkit.scale == 1 && returnVal == true) { + gfx.lineTo(x - radius, y); + } + corner(x, y, 180); + @:privateAccess gfx.flush(); + return returnVal; + } } \ No newline at end of file From 3de295169a2e923d91c526f26a717f61a28d663a Mon Sep 17 00:00:00 2001 From: tfabretti Date: Mon, 27 Mar 2023 18:40:25 +0200 Subject: [PATCH 2/3] Revert "[Style] Addition of the support of background-image-repeat" This reverts commit 34e5daa2fddd40120a79edba9de586e0948c6cf1. --- haxe/ui/backend/heaps/StyleHelper.hx | 183 +++------------------------ 1 file changed, 20 insertions(+), 163 deletions(-) diff --git a/haxe/ui/backend/heaps/StyleHelper.hx b/haxe/ui/backend/heaps/StyleHelper.hx index 950d84f..adb64ff 100644 --- a/haxe/ui/backend/heaps/StyleHelper.hx +++ b/haxe/ui/backend/heaps/StyleHelper.hx @@ -125,89 +125,36 @@ class StyleHelper { style.backgroundImageSliceRight - style.backgroundImageSliceLeft, style.backgroundImageSliceBottom - style.backgroundImageSliceTop); } - + if (trc != null) { tile = tile.sub(trc.left, trc.top, trc.width, trc.height); } - if (slice != null) { var rects:Slice9Rects = Slice9.buildRects(w, h, trc.width, trc.height, slice); var srcRects:Array = rects.src; var dstRects:Array = rects.dst; - if (style.backgroundImageRepeat == "repeat") { - // The image is slightly scaled down to make sure there is no visible clip one the sides - var scaleX = dstRects[4].width / ( srcRects[4].width * Math.ceil(dstRects[4].width / srcRects[4].width) ); - var scaleY = dstRects[4].height / ( srcRects[4].height * Math.ceil(dstRects[4].height / srcRects[4].height) ); - - paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); - paintTileRepeat(bgImageGraphics, tile, srcRects[1], scaleX, 1, dstRects[1]); - paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); - - srcRects[3].bottom--; - paintTileRepeat(bgImageGraphics, tile, srcRects[3], 1, scaleY, dstRects[3]); - - srcRects[4].bottom--; - paintTileRepeat(bgImageGraphics, tile, srcRects[4], scaleX, scaleY, dstRects[4]); - - srcRects[5].bottom--; - paintTileRepeat(bgImageGraphics, tile, srcRects[5], 1, scaleY, dstRects[5]); - - dstRects[6].bottom++; - paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); - dstRects[7].bottom++; - paintTileRepeat(bgImageGraphics, tile, srcRects[7], scaleX, 1, dstRects[7]); - dstRects[8].bottom++; - paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); - } - else { - paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); - paintTile(bgImageGraphics, tile, srcRects[1], dstRects[1]); - paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); - - srcRects[3].bottom--; - paintTile(bgImageGraphics, tile, srcRects[3], dstRects[3]); - - srcRects[4].bottom--; - paintTile(bgImageGraphics, tile, srcRects[4], dstRects[4]); - - srcRects[5].bottom--; - paintTile(bgImageGraphics, tile, srcRects[5], dstRects[5]); - - dstRects[6].bottom++; - paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); - dstRects[7].bottom++; - paintTile(bgImageGraphics, tile, srcRects[7], dstRects[7]); - dstRects[8].bottom++; - paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); - } - } else { - var scaleX:Float = 1; - var scaleY:Float = 1; + paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); + paintTile(bgImageGraphics, tile, srcRects[1], dstRects[1]); + paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); - if (style.backgroundImageRepeat == null || style.backgroundImageRepeat == "stretch") { - scaleX = w / trc.width; - scaleY = h / trc.height; - } - else { - if (style.backgroundWidth != null) { - scaleX = style.backgroundWidth / trc.width; - } else if (style.backgroundWidthPercent != null) { - scaleX = ((w / trc.width) * style.backgroundWidthPercent) / 100; - } - if (style.backgroundHeight != null) { - scaleY = style.backgroundHeight / trc.height; - } else if (style.backgroundHeightPercent != null) { - scaleY = ((h / trc.height) * style.backgroundHeightPercent) / 100; - } - } + srcRects[3].bottom--; + paintTile(bgImageGraphics, tile, srcRects[3], dstRects[3]); + + srcRects[4].bottom--; + paintTile(bgImageGraphics, tile, srcRects[4], dstRects[4]); - if (style.backgroundImageRepeat == "repeat") { - paintTileRepeat(bgImageGraphics, tile, trc, scaleX, scaleY, new Rectangle(0, 0, w, h)); - } - else { - paintTile(bgImageGraphics, tile, trc, new Rectangle(0, 0, trc.width * scaleX, trc.height * scaleY)); - } + srcRects[5].bottom--; + paintTile(bgImageGraphics, tile, srcRects[5], dstRects[5]); + + dstRects[6].bottom++; + paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); + dstRects[7].bottom++; + paintTile(bgImageGraphics, tile, srcRects[7], dstRects[7]); + dstRects[8].bottom++; + paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); + } else { + paintTile(bgImageGraphics, tile, trc, new Rectangle(0, 0, w, h)); } }); } @@ -276,94 +223,4 @@ class StyleHelper { g.drawRect(dst.left, dst.top, dst.width, dst.height); g.endFill(); } - - // Used to repeat part (src) of an image (tile) with a given scale (srcScaleX, srcScaleY) inside a target (dst) - private static function paintTileRepeat(g:Graphics, tile:Tile, src:Rectangle, srcScaleX:Float, srcScaleY:Float, dst:Rectangle) { - var scaledw = srcScaleX * src.width; - var scaledh = srcScaleY * src.height; - var wCount = dst.width / scaledw; - var hCount = dst.height / scaledh; - - var iwCount = Math.ceil(wCount); - var ihCount = Math.ceil(hCount); - - var lastw = iwCount - 1; - var lasth = ihCount - 1; - - // Full images - for (iwCurr in 0...lastw) { - for (ihCurr in 0...lasth) { - paintTile(g, tile, src, new Rectangle(dst.left + iwCurr * scaledw, dst.top + ihCurr * scaledh, scaledw, scaledh)); - } - } - - var localRect = src.copy(); - // Images clipped in width - var clippedw = (wCount - lastw) * scaledw; - localRect.width = (wCount - lastw) * src.width; - for (ihCurr in 0...lasth) { - paintTile(g, tile, localRect, new Rectangle(dst.left + lastw * scaledw, dst.top + ihCurr * scaledh, clippedw, scaledh)); - } - - // Images clipped in height - var clippedh = (hCount - lasth) * scaledh; - localRect.width = src.width; - localRect.height = (hCount - lasth) * src.height; - for (iwCurr in 0...lastw) { - paintTile(g, tile, localRect, new Rectangle(dst.left + iwCurr * scaledw, dst.top + lasth * scaledh, scaledw, clippedh)); - } - - // Image clipped in both - localRect.width = (wCount - lastw) * src.width; - if (localRect.width > 1 && localRect.height > 1) { - paintTile(g, tile, localRect, new Rectangle(dst.left + lastw * scaledw, dst.top + lasth * scaledh, clippedw, clippedh)); - } - } - - // copy of draw round rect without lines as it seems to misdraw (at different scales - strange) - public static function drawRoundedRect(gfx:Graphics, x : Float, y : Float, w : Float, h : Float, radius : Float, nsegments = 0 ) { - if (radius <= 0) { - gfx.drawRect(x, y, w, h); - return false; - } - var returnVal = true; - if (w == h && radius >= w / 2) { - radius = (w / 2) + 1; - returnVal = false; - } - x += radius; - y += radius; - w -= radius * 2; - h -= radius * 2; - @:privateAccess gfx.flush(); - if( nsegments == 0 ) - nsegments = Math.ceil(Math.abs(radius * hxd.Math.degToRad(90) / 4)); - if ( nsegments < 3 ) nsegments = 3; - var angle = hxd.Math.degToRad(90) / (nsegments - 1); - inline function corner(x, y, angleStart) { - for ( i in 0...nsegments) { - var a = i * angle + hxd.Math.degToRad(angleStart); - gfx.lineTo(x + Math.cos(a) * radius, y + Math.sin(a) * radius); - } - } - if (Toolkit.scale == 1 && returnVal == true) { - gfx.lineTo(x, y - radius); - gfx.lineTo(x + w, y - radius); - } - corner(x + w, y, 270); - if (Toolkit.scale == 1 && returnVal == true) { - gfx.lineTo(x + w + radius, y + h); - } - corner(x + w, y + h, 0); - if (Toolkit.scale == 1 && returnVal == true) { - gfx.lineTo(x, y + h + radius); - } - corner(x, y + h, 90); - if (Toolkit.scale == 1 && returnVal == true) { - gfx.lineTo(x - radius, y); - } - corner(x, y, 180); - @:privateAccess gfx.flush(); - return returnVal; - } } \ No newline at end of file From 4fe23a3bb0cf68b0bc702c9f561279ea260e6b2c Mon Sep 17 00:00:00 2001 From: tfabretti Date: Mon, 27 Mar 2023 18:43:54 +0200 Subject: [PATCH 3/3] [Style] Addition of the support of background-image-repeat - merge fix --- haxe/ui/backend/heaps/StyleHelper.hx | 133 +++++++++++++++++++++++---- 1 file changed, 114 insertions(+), 19 deletions(-) diff --git a/haxe/ui/backend/heaps/StyleHelper.hx b/haxe/ui/backend/heaps/StyleHelper.hx index adb64ff..4e11eed 100644 --- a/haxe/ui/backend/heaps/StyleHelper.hx +++ b/haxe/ui/backend/heaps/StyleHelper.hx @@ -134,27 +134,79 @@ class StyleHelper { var srcRects:Array = rects.src; var dstRects:Array = rects.dst; - paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); - paintTile(bgImageGraphics, tile, srcRects[1], dstRects[1]); - paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); - - srcRects[3].bottom--; - paintTile(bgImageGraphics, tile, srcRects[3], dstRects[3]); - - srcRects[4].bottom--; - paintTile(bgImageGraphics, tile, srcRects[4], dstRects[4]); + if (style.backgroundImageRepeat == "repeat") { + // The image is slightly scaled down to make sure there is no visible clip one the sides + var scaleX = dstRects[4].width / ( srcRects[4].width * Math.ceil(dstRects[4].width / srcRects[4].width) ); + var scaleY = dstRects[4].height / ( srcRects[4].height * Math.ceil(dstRects[4].height / srcRects[4].height) ); + + paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); + paintTileRepeat(bgImageGraphics, tile, srcRects[1], scaleX, 1, dstRects[1]); + paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); + + srcRects[3].bottom--; + paintTileRepeat(bgImageGraphics, tile, srcRects[3], 1, scaleY, dstRects[3]); + + srcRects[4].bottom--; + paintTileRepeat(bgImageGraphics, tile, srcRects[4], scaleX, scaleY, dstRects[4]); + + srcRects[5].bottom--; + paintTileRepeat(bgImageGraphics, tile, srcRects[5], 1, scaleY, dstRects[5]); + + dstRects[6].bottom++; + paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); + dstRects[7].bottom++; + paintTileRepeat(bgImageGraphics, tile, srcRects[7], scaleX, 1, dstRects[7]); + dstRects[8].bottom++; + paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); + } + else { + paintTile(bgImageGraphics, tile, srcRects[0], dstRects[0]); + paintTile(bgImageGraphics, tile, srcRects[1], dstRects[1]); + paintTile(bgImageGraphics, tile, srcRects[2], dstRects[2]); + + srcRects[3].bottom--; + paintTile(bgImageGraphics, tile, srcRects[3], dstRects[3]); + + srcRects[4].bottom--; + paintTile(bgImageGraphics, tile, srcRects[4], dstRects[4]); + + srcRects[5].bottom--; + paintTile(bgImageGraphics, tile, srcRects[5], dstRects[5]); + + dstRects[6].bottom++; + paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); + dstRects[7].bottom++; + paintTile(bgImageGraphics, tile, srcRects[7], dstRects[7]); + dstRects[8].bottom++; + paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); + } + } else { + var scaleX:Float = 1; + var scaleY:Float = 1; - srcRects[5].bottom--; - paintTile(bgImageGraphics, tile, srcRects[5], dstRects[5]); + if (style.backgroundImageRepeat == null || style.backgroundImageRepeat == "stretch") { + scaleX = w / trc.width; + scaleY = h / trc.height; + } + else { + if (style.backgroundWidth != null) { + scaleX = style.backgroundWidth / trc.width; + } else if (style.backgroundWidthPercent != null) { + scaleX = ((w / trc.width) * style.backgroundWidthPercent) / 100; + } + if (style.backgroundHeight != null) { + scaleY = style.backgroundHeight / trc.height; + } else if (style.backgroundHeightPercent != null) { + scaleY = ((h / trc.height) * style.backgroundHeightPercent) / 100; + } + } - dstRects[6].bottom++; - paintTile(bgImageGraphics, tile, srcRects[6], dstRects[6]); - dstRects[7].bottom++; - paintTile(bgImageGraphics, tile, srcRects[7], dstRects[7]); - dstRects[8].bottom++; - paintTile(bgImageGraphics, tile, srcRects[8], dstRects[8]); - } else { - paintTile(bgImageGraphics, tile, trc, new Rectangle(0, 0, w, h)); + if (style.backgroundImageRepeat == "repeat") { + paintTileRepeat(bgImageGraphics, tile, trc, scaleX, scaleY, new Rectangle(0, 0, w, h)); + } + else { + paintTile(bgImageGraphics, tile, trc, new Rectangle(0, 0, trc.width * scaleX, trc.height * scaleY)); + } } }); } @@ -223,4 +275,47 @@ class StyleHelper { g.drawRect(dst.left, dst.top, dst.width, dst.height); g.endFill(); } + + // Used to repeat part (src) of an image (tile) with a given scale (srcScaleX, srcScaleY) inside a target (dst) + private static function paintTileRepeat(g:Graphics, tile:Tile, src:Rectangle, srcScaleX:Float, srcScaleY:Float, dst:Rectangle) { + var scaledw = srcScaleX * src.width; + var scaledh = srcScaleY * src.height; + var wCount = dst.width / scaledw; + var hCount = dst.height / scaledh; + + var iwCount = Math.ceil(wCount); + var ihCount = Math.ceil(hCount); + + var lastw = iwCount - 1; + var lasth = ihCount - 1; + + // Full images + for (iwCurr in 0...lastw) { + for (ihCurr in 0...lasth) { + paintTile(g, tile, src, new Rectangle(dst.left + iwCurr * scaledw, dst.top + ihCurr * scaledh, scaledw, scaledh)); + } + } + + var localRect = src.copy(); + // Images clipped in width + var clippedw = (wCount - lastw) * scaledw; + localRect.width = (wCount - lastw) * src.width; + for (ihCurr in 0...lasth) { + paintTile(g, tile, localRect, new Rectangle(dst.left + lastw * scaledw, dst.top + ihCurr * scaledh, clippedw, scaledh)); + } + + // Images clipped in height + var clippedh = (hCount - lasth) * scaledh; + localRect.width = src.width; + localRect.height = (hCount - lasth) * src.height; + for (iwCurr in 0...lastw) { + paintTile(g, tile, localRect, new Rectangle(dst.left + iwCurr * scaledw, dst.top + lasth * scaledh, scaledw, clippedh)); + } + + // Image clipped in both + localRect.width = (wCount - lastw) * src.width; + if (localRect.width > 1 && localRect.height > 1) { + paintTile(g, tile, localRect, new Rectangle(dst.left + lastw * scaledw, dst.top + lasth * scaledh, clippedw, clippedh)); + } + } } \ No newline at end of file