diff --git a/src/dlangui/graphics/colors.d b/src/dlangui/graphics/colors.d index 91701999..1cc7fa8e 100644 --- a/src/dlangui/graphics/colors.d +++ b/src/dlangui/graphics/colors.d @@ -204,7 +204,7 @@ uint decodeHexColor(string s, uint defValue = 0) { if (s[0] != '#') return defValue; uint value = 0; - for (int i = 1; i < s.length; i++) { + foreach(i; 1 .. s.length) { uint digit = decodeHexDigit(s[i]); if (digit == uint.max) return defValue; diff --git a/src/dlangui/graphics/drawbuf.d b/src/dlangui/graphics/drawbuf.d index 17d0b557..37273f8b 100644 --- a/src/dlangui/graphics/drawbuf.d +++ b/src/dlangui/graphics/drawbuf.d @@ -328,14 +328,14 @@ class DrawBuf : RefCountedObject { if (isFullyTransparentColor(color1) && isFullyTransparentColor(color2)) return; // draw horizontal lines - for (int x = rc.left; x < rc.right; x++) { + foreach(int x; rc.left .. rc.right) { if ((x ^ rc.top) & 1) fillRect(Rect(x, rc.top, x + 1, rc.top + 1), color1); if ((x ^ (rc.bottom - 1)) & 1) fillRect(Rect(x, rc.bottom - 1, x + 1, rc.bottom), color2); } // draw vertical lines - for (int y = rc.top + 1; y < rc.bottom - 1; y++) { + foreach(int y; rc.top + 1 .. rc.bottom - 1) { uint color = color1 == color2 ? color1 : blendARGB(color2, color1, 255 / (rc.bottom - rc.top)); if ((y ^ rc.left) & 1) fillRect(Rect(rc.left, y, rc.left + 1, y + 1), color); @@ -440,12 +440,12 @@ class ColorDrawBufBase : DrawBuf { int dy = srcrect.height; ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src; if (colorDrawBuf !is null) { - for (int yy = 0; yy < dy; yy++) { + foreach(yy; 0 .. dy) { uint * srcrow = colorDrawBuf.scanLine(srcrect.top + yy) + srcrect.left; uint * dstrow = scanLine(dstrect.top + yy) + dstrect.left; if (!_alpha) { // simplified version - no alpha blending - for (int i = 0; i < dx; i++) { + foreach(i; 0 .. dx) { uint pixel = srcrow[i]; uint alpha = pixel >> 24; if (!alpha) @@ -457,7 +457,7 @@ class ColorDrawBufBase : DrawBuf { } } else { // combine two alphas - for (int i = 0; i < dx; i++) { + foreach(i; 0 .. dx) { uint pixel = srcrow[i]; uint alpha = blendAlpha(_alpha, pixel >> 24); if (!alpha) @@ -480,7 +480,7 @@ class ColorDrawBufBase : DrawBuf { int dd = dst1 - dst0; int sd = src1 - src0; int[] res = new int[dd]; - for (int i = 0; i < dd; i++) + foreach(int i; 0 .. dd) res[i] = src0 + i * sd / dd; return res; } @@ -499,12 +499,12 @@ class ColorDrawBufBase : DrawBuf { int dy = dstrect.height; ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src; if (colorDrawBuf !is null) { - for (int y = 0; y < dy; y++) { + foreach(y; 0 .. dy) { uint * srcrow = colorDrawBuf.scanLine(ymap[y]); uint * dstrow = scanLine(dstrect.top + y) + dstrect.left; if (!_alpha) { // simplified alpha calculation - for (int x = 0; x < dx; x++) { + foreach(x; 0 .. dx) { uint srcpixel = srcrow[xmap[x]]; uint dstpixel = dstrow[x]; uint alpha = srcpixel >> 24; @@ -517,7 +517,7 @@ class ColorDrawBufBase : DrawBuf { } } else { // blending two alphas - for (int x = 0; x < dx; x++) { + foreach(x; 0 .. dx) { uint srcpixel = srcrow[xmap[x]]; uint dstpixel = dstrow[x]; uint srca = srcpixel >> 24; @@ -541,7 +541,7 @@ class ColorDrawBufBase : DrawBuf { bool foundUsed = false; x0 = 0; x1 = 0; - for (int x = 1; x < _dx - 1; x++) { + foreach(int x; 1 .. _dx - 1) { if (isBlackPixel(line[x])) { // opaque black pixel if (!foundUsed) { x0 = x; @@ -570,7 +570,7 @@ class ColorDrawBufBase : DrawBuf { bool foundUsed = false; y0 = 0; y1 = 0; - for (int y = 1; y < _dy - 1; y++) { + foreach(int y; 1 .. _dy - 1) { uint * line = scanLine(y); if (isBlackPixel(line[x])) { // opaque black pixel if (!foundUsed) { @@ -615,7 +615,7 @@ class ColorDrawBufBase : DrawBuf { bool clipping = true; //!_clipRect.empty(); color = applyAlpha(color); bool subpixel = glyph.subpixelMode != SubpixelRenderingMode.None; - for (int yy = 0; yy < srcdy; yy++) { + foreach(int yy; 0 .. srcdy) { int liney = y + yy; if (clipping && (liney < _clipRect.top || liney >= _clipRect.bottom)) continue; @@ -623,7 +623,7 @@ class ColorDrawBufBase : DrawBuf { continue; uint * row = scanLine(liney); ubyte * srcrow = src.ptr + yy * srcdx; - for (int xx = 0; xx < srcdx; xx++) { + foreach(int xx; 0 .. srcdx) { int colx = x + (subpixel ? xx / 3 : xx); if (clipping && (colx < _clipRect.left || colx >= _clipRect.right)) continue; @@ -657,7 +657,7 @@ class ColorDrawBufBase : DrawBuf { int srcdx = glyph.blackBoxX; int srcdy = glyph.blackBoxY; bool subpixel = glyph.subpixelMode != SubpixelRenderingMode.None; - for (int yy = 0; yy < srcdy; yy++) { + foreach(int yy; 0 .. srcdy) { int liney = y + yy; uint * row = scanLine(liney); ubyte * srcrow = src.ptr + yy * srcdx; @@ -684,13 +684,13 @@ class ColorDrawBufBase : DrawBuf { override void fillRect(Rect rc, uint color) { if (applyClipping(rc)) { - for (int y = rc.top; y < rc.bottom; y++) { + foreach(y; rc.top .. rc.bottom) { uint * row = scanLine(y); uint alpha = color >> 24; if (!alpha) { row[rc.left .. rc.right] = color; } else if (alpha < 254) { - for (int x = rc.left; x < rc.right; x++) { + foreach(x; rc.left .. rc.right) { // apply blending row[x] = blendARGB(row[x], color, alpha); } @@ -749,7 +749,7 @@ class GrayDrawBuf : DrawBuf { int len = _dx * _dy; ubyte * p = _buf.ptr; ubyte cl = rgbToGray(color); - for (int i = 0; i < len; i++) + foreach(i; 0 .. len) p[i] = cl; } @@ -762,10 +762,10 @@ class GrayDrawBuf : DrawBuf { int dy = srcrect.height; GrayDrawBuf grayDrawBuf = cast (GrayDrawBuf) src; if (grayDrawBuf !is null) { - for (int yy = 0; yy < dy; yy++) { + foreach(yy; 0 .. dy) { ubyte * srcrow = grayDrawBuf.scanLine(srcrect.top + yy) + srcrect.left; ubyte * dstrow = scanLine(dstrect.top + yy) + dstrect.left; - for (int i = 0; i < dx; i++) { + foreach(i; 0 .. dx) { ubyte pixel = srcrow[i]; dstrow[i] = pixel; } @@ -780,7 +780,7 @@ class GrayDrawBuf : DrawBuf { int dd = dst1 - dst0; int sd = src1 - src0; int[] res = new int[dd]; - for (int i = 0; i < dd; i++) + foreach(int i; 0 .. dd) res[i] = src0 + i * sd / dd; return res; } @@ -794,10 +794,10 @@ class GrayDrawBuf : DrawBuf { int dy = dstrect.height; GrayDrawBuf grayDrawBuf = cast (GrayDrawBuf) src; if (grayDrawBuf !is null) { - for (int y = 0; y < dy; y++) { + foreach(y; 0 .. dy) { ubyte * srcrow = grayDrawBuf.scanLine(ymap[y]); ubyte * dstrow = scanLine(dstrect.top + y) + dstrect.left; - for (int x = 0; x < dx; x++) { + foreach(x; 0 .. dx) { ubyte srcpixel = srcrow[xmap[x]]; ubyte dstpixel = dstrow[x]; dstrow[x] = srcpixel; @@ -813,7 +813,7 @@ class GrayDrawBuf : DrawBuf { bool foundUsed = false; x0 = 0; x1 = 0; - for (int x = 1; x < _dx - 1; x++) { + foreach(int x; 1 .. _dx - 1) { if (line[x] == 0x00000000) { // opaque black pixel if (!foundUsed) { x0 = x; @@ -830,7 +830,7 @@ class GrayDrawBuf : DrawBuf { bool foundUsed = false; y0 = 0; y1 = 0; - for (int y = 1; y < _dy - 1; y++) { + foreach(int y; 1 .. _dy - 1) { ubyte * line = scanLine(y); if (line[x] == 0x00000000) { // opaque black pixel if (!foundUsed) { @@ -871,7 +871,7 @@ class GrayDrawBuf : DrawBuf { int srcdx = glyph.blackBoxX; int srcdy = glyph.blackBoxY; bool clipping = true; //!_clipRect.empty(); - for (int yy = 0; yy < srcdy; yy++) { + foreach(int yy; 0 .. srcdy) { int liney = y + yy; if (clipping && (liney < _clipRect.top || liney >= _clipRect.bottom)) continue; @@ -879,7 +879,7 @@ class GrayDrawBuf : DrawBuf { continue; ubyte * row = scanLine(liney); ubyte * srcrow = src.ptr + yy * srcdx; - for (int xx = 0; xx < srcdx; xx++) { + foreach(int xx; 0 .. srcdx) { int colx = xx + x; if (clipping && (colx < _clipRect.left || colx >= _clipRect.right)) continue; @@ -902,9 +902,9 @@ class GrayDrawBuf : DrawBuf { if (applyClipping(rc)) { uint alpha = color >> 24; ubyte cl = rgbToGray(color); - for (int y = rc.top; y < rc.bottom; y++) { + foreach(y; rc.top .. rc.bottom) { ubyte * row = scanLine(y); - for (int x = rc.left; x < rc.right; x++) { + foreach(x; rc.left .. rc.right) { if (!alpha) row[x] = cl; else if (alpha < 255) { @@ -943,7 +943,7 @@ class ColorDrawBuf : ColorDrawBufBase { this(ColorDrawBuf v) { this(v.width, v.height); //_buf.length = v._buf.length; - for (int i = 0; i < _buf.length; i++) + foreach(i; 0 .. _buf.length) _buf[i] = v._buf[i]; } /// create resized copy of ColorDrawBuf @@ -983,7 +983,7 @@ class ColorDrawBuf : ColorDrawBufBase { } int len = _dx * _dy; uint * p = _buf.ptr; - for (int i = 0; i < len; i++) + foreach(i; 0 .. len) p[i] = color; } override DrawBuf transformColors(ref ColorTransform transform) { @@ -996,11 +996,11 @@ class ColorDrawBuf : ColorDrawBufBase { *p = *_ninePatch; res.ninePatch = p; } - for (int y = 0; y < _dy; y++) { + foreach(int y; 0 .. _dy) { uint * srcline = scanLine(y); uint * dstline = res.scanLine(y); bool allowTransformY = !skipFrame || (y !=0 && y != _dy - 1); - for (int x = 0; x < _dx; x++) { + foreach(int x; 0 .. _dx) { bool allowTransformX = !skipFrame || (x !=0 && x != _dx - 1); if (!allowTransformX || !allowTransformY) dstline[x] = srcline[x]; diff --git a/src/dlangui/graphics/fonts.d b/src/dlangui/graphics/fonts.d index c6508757..2de46889 100644 --- a/src/dlangui/graphics/fonts.d +++ b/src/dlangui/graphics/fonts.d @@ -220,7 +220,7 @@ class Font : RefCountedObject { tabOffset = tabOffset % tabWidth; if (tabOffset < 0) tabOffset += tabWidth; - for (int i = 0; i < len; i++) { + foreach(int i; 0 .. len) { //auto measureStart = std.datetime.Clock.currAppTick; dchar ch = pstr[i]; if (ch == '\t') { @@ -308,7 +308,7 @@ class Font : RefCountedObject { bool underline = (textFlags & TextFlag.Underline) != 0; int underlineHeight = 1; int underlineY = y + _baseline + underlineHeight * 2; - for (int i = 0; i < charsMeasured; i++) { + foreach(int i; 0 .. charsMeasured) { dchar ch = text[i]; if (ch == '&' && (textFlags & (TextFlag.UnderlineHotKeys | TextFlag.HotKeys | TextFlag.UnderlineHotKeysWhenAltPressed))) { if (textFlags & (TextFlag.UnderlineHotKeys | TextFlag.UnderlineHotKeysWhenAltPressed)) @@ -377,7 +377,7 @@ class Font : RefCountedObject { bool underline = (customizedTextFlags & TextFlag.Underline) != 0; int underlineHeight = 1; int underlineY = y + _baseline + underlineHeight * 2; - for (int i = 0; i < charsMeasured; i++) { + foreach(int i; 0 .. charsMeasured) { dchar ch = text[i]; uint color = i < charProps.length ? charProps[i].color : charProps[$ - 1].color; customizedTextFlags = (i < charProps.length ? charProps[i].textFlags : charProps[$ - 1].textFlags) | textFlags; @@ -478,7 +478,7 @@ struct SimpleTextFormatter { int lastWordEnd = 0; int lastWordEndX = 0; dchar prevChar = 0; - for (int i = 0; i <= charsMeasured; i++) { + foreach(int i; 0 .. charsMeasured + 1) { dchar ch = i < charsMeasured ? text[i] : 0; if (ch == '\n' || i == charsMeasured) { // split by EOL char or at end of text @@ -547,9 +547,8 @@ struct SimpleTextFormatter { /// draw formatted text void draw(DrawBuf buf, int x, int y, FontRef fnt, uint color) { int lineHeight = fnt.height; - for (int i = 0; i < _lines.length; i++) { - dstring line = _lines[i]; - fnt.drawText(buf, x, y, line, color, _tabSize, _tabOffset, _textFlags); + foreach(line; _lines) { + fnt.drawText(buf, x, y, line, color, _tabSize, _tabOffset, _textFlags); y += lineHeight; } } @@ -569,7 +568,7 @@ struct FontList { } void clear() { - for (uint i = 0; i < _len; i++) { + foreach(i; 0 .. _len) { _list[i].clear(); _list[i] = null; } @@ -581,7 +580,7 @@ struct FontList { } // find by a set of parameters - returns index of found item, -1 if not found int find(int size, int weight, bool italic, FontFamily family, string face) { - for (int i = 0; i < _len; i++) { + foreach(int i; 0 .. _len) { Font item = _list[i].get; if (item.family != family) continue; @@ -597,7 +596,7 @@ struct FontList { } // find by size only - returns index of found item, -1 if not found int find(int size) { - for (int i = 0; i < _len; i++) { + foreach(int i; 0 .. _len) { Font item = _list[i].get; if (item.size != size) continue; @@ -616,27 +615,27 @@ struct FontList { } // remove unused items - with reference == 1 void cleanup() { - for (int i = 0; i < _len; i++) + foreach(i; 0 .. _len) if (_list[i].refCount <= 1) _list[i].clear(); - int dst = 0; - for (int i = 0; i < _len; i++) { + uint dst = 0; + foreach(i; 0 .. _len) { if (!_list[i].isNull) if (i != dst) _list[dst++] = _list[i]; } _len = dst; - for (int i = 0; i < _len; i++) + foreach(i; 0 .. _len) _list[i].cleanup(); } void checkpoint() { - for (int i = 0; i < _len; i++) + foreach(i; 0 .. _len) _list[i].checkpoint(); } /// clears glyph cache void clearGlyphCache() { - for (int i = 0; i < _len; i++) - _list[i].clearGlyphCache(); + foreach(i; 0 .. _len) + _list[i].clearGlyphCache(); } } @@ -865,7 +864,7 @@ struct glyph_gamma_table(int maxv = 65) @property double gamma() { return _gamma; } @property void gamma(double g) { _gamma = g; - for(int i = 0; i < maxv; i++) + foreach(int i; 0 .. maxv) { double v = (maxv - 1.0 - i) / maxv; v = pow(v, g); diff --git a/src/dlangui/graphics/ftfonts.d b/src/dlangui/graphics/ftfonts.d index 63af8938..c3aaec89 100644 --- a/src/dlangui/graphics/ftfonts.d +++ b/src/dlangui/graphics/ftfonts.d @@ -301,10 +301,10 @@ class FreeTypeFontFile { ubyte mask = 0x80; ubyte * ptr = bitmap.buffer; ubyte * dst = glyph.glyph.ptr; - for ( int y=0; y>= 1; if ( !mask && x != w-1) { @@ -317,8 +317,8 @@ class FreeTypeFontFile { } else { // antialiased - for (uint y = 0; y < h; y++) { - for (uint x = 0; x < w; x++) { + foreach(y; 0 .. h) { + foreach(x; 0 .. w) { glyph.glyph[y * w + x] = _gamma256.correct(bitmap.buffer[y * bitmap.pitch + x]); } } @@ -516,7 +516,7 @@ class FreeTypeFontManager : FontManager { int score = 0; int bestFaceMatch = 0; if (faces && face.length) { - for (int i = 0; i < faces.length; i++) { + foreach(i; 0 .. faces.length) { string f = faces[i].strip; if (f.icmp(item.def.face) == 0) { score += 3000 - i; @@ -695,7 +695,7 @@ bool registerFontConfigFonts(FreeTypeFontManager fontMan) { // load fonts from file //CRLog::debug("FONTCONFIG: %d font files found", fontset->nfont); - for(int i = 0; i < fontset.nfont; i++) { + foreach(i; 0 .. fontset.nfont) { const (FcChar8) *s = "".toStringz; const (FcChar8) *family = "".toStringz; const (FcChar8) *style = "".toStringz; diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 1d284bdf..6b2c008b 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -471,7 +471,7 @@ private class GLImageCache { private void removePage(GLImageCachePage page) { if (_activePage == page) _activePage = null; - for (int i = 0; i < _pages.length; i++) + foreach(i; 0 .. _pages.length) if (_pages[i] == page) { _pages.remove(i); break; @@ -526,7 +526,7 @@ private class GLImageCache { } /// clears cache void clear() { - for (int i = 0; i < _pages.length; i++) { + foreach(i; 0 .. _pages.length) { destroy(_pages[i]); _pages[i] = null; } @@ -565,7 +565,7 @@ private class GLImageCache { if (item._deleted) list ~= item._objectId; } - for (int i = 0 ; i < list.length; i++) { + foreach(i; 0 .. list.length) { onCachedObjectDeleted(list[i]); } } @@ -767,7 +767,7 @@ private class GLGlyphCache { void removePage(GLGlyphCachePage page) { if (_activePage == page) _activePage = null; - for (int i = 0; i < _pages.length; i++) + foreach(i; 0 .. _pages.length) if (_pages[i] == page) { _pages.remove(i); break; @@ -811,7 +811,7 @@ private class GLGlyphCache { _map[glyph.id] = res; } void clear() { - for (int i = 0; i < _pages.length; i++) { + foreach(i; 0 .. _pages.length) { destroy(_pages[i]); _pages[i] = null; } @@ -849,7 +849,7 @@ private class GLGlyphCache { if (item._deleted) list ~= item._objectId; } - for (int i = 0 ; i < list.length; i++) { + foreach(i; 0 .. list.length) { onCachedObjectDeleted(list[i]); } } diff --git a/src/dlangui/graphics/images.d b/src/dlangui/graphics/images.d index 7d2164b5..ae41781c 100644 --- a/src/dlangui/graphics/images.d +++ b/src/dlangui/graphics/images.d @@ -88,9 +88,9 @@ ColorDrawBuf loadImage(immutable ubyte[] data, string filename) { ColorDrawBuf buf = new ColorDrawBuf(w, h); Color_RGBA[] pixels = image.rgba.allPixels; int index = 0; - for (int y = 0; y < h; y++) { + foreach(y; 0 .. h) { uint * dstLine = buf.scanLine(y); - for (int x = 0; x < w; x++) { + foreach(x; 0 .. w) { Color_RGBA * pixel = &pixels[index + x]; dstLine[x] = makeRGBA(pixel.r_ubyte, pixel.g_ubyte, pixel.b_ubyte, pixel.a_ubyte); } @@ -182,9 +182,9 @@ version (USE_DLIBIMAGE) { int w = image.width; int h = image.height; ColorDrawBuf buf = new ColorDrawBuf(w, h); - for (int y = 0; y < h; y++) { + foreach(y; 0 .. h) { uint * dstLine = buf.scanLine(y); - for (int x = 0; x < w; x++) { + foreach(x; 0 .. w) { auto pixel = image[x, y].convert(8); dstLine[x] = makeRGBA(pixel.r, pixel.g, pixel.b, 255 - pixel.a); } @@ -198,9 +198,9 @@ version (USE_DIMAGE) { int w = image.width; int h = image.height; ColorDrawBuf buf = new ColorDrawBuf(w, h); - for (int y = 0; y < h; y++) { + foreach(y; 0 .. h) { uint * dstLine = buf.scanLine(y); - for (int x = 0; x < w; x++) { + foreach(x; 0 .. w) { uint pixel = image[x, y]; dstLine[x] = pixel ^ 0xFF000000; } diff --git a/src/dlangui/graphics/resources.d b/src/dlangui/graphics/resources.d index 7fcbf97e..b05ca84d 100644 --- a/src/dlangui/graphics/resources.d +++ b/src/dlangui/graphics/resources.d @@ -701,7 +701,7 @@ class StateDrawable : Drawable { uint[4] nn; if (!parseList4!float(value, n)) return COLOR_TRANSFORM_MULTIPLY_NONE; - for(int i = 0; i < 4; i++) { + foreach(i; 0 .. 4) { int res = cast(int)(n[i] * 0x40); if (res < 0) res = 0; diff --git a/src/dlangui/graphics/xpm/reader.d b/src/dlangui/graphics/xpm/reader.d index 6807a06d..f4c3eaed 100644 --- a/src/dlangui/graphics/xpm/reader.d +++ b/src/dlangui/graphics/xpm/reader.d @@ -135,7 +135,7 @@ ColorDrawBuf parseXPM(const(ubyte)[] data) uint* dstLine = colorBuf.scanLine(y); if (str.length) { enforce(str.length >= w*cpp, "Invalid pixel line"); - for (int x=0; x < w; x++) { + foreach(int x; 0 .. w) { auto pixelStr = str[x*cpp..(x+1)*cpp]; auto colorPtr = xpmHash(pixelStr) in colorMap; enforce(colorPtr, "Unknown pixel : '" ~ str ~ "'");