From ca58769a917af43a89d6fb0f6c1c7b716c705fdf Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 24 Mar 2015 20:47:54 +0300 Subject: [PATCH] issue #64 - draw points --- src/dlangui/graphics/drawbuf.d | 38 ++++++++++++++++++++++++++++++-- src/dlangui/graphics/gldrawbuf.d | 12 +++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/dlangui/graphics/drawbuf.d b/src/dlangui/graphics/drawbuf.d index 3fd046e2..2dbb349d 100644 --- a/src/dlangui/graphics/drawbuf.d +++ b/src/dlangui/graphics/drawbuf.d @@ -260,6 +260,8 @@ class DrawBuf : RefCountedObject { abstract void fill(uint color); /// fill rectangle with solid color (clipping is applied) abstract void fillRect(Rect rc, uint color); + /// draw pixel at (x, y) with specified color + abstract void drawPixel(int x, int y, uint color); /// draw 8bit alpha image - usually font glyph using specified color (clipping is applied) abstract void drawGlyph(int x, int y, Glyph * glyph, uint color); /// draw source buffer rectangle contents to destination buffer @@ -646,6 +648,22 @@ class ColorDrawBufBase : DrawBuf { } } } + + /// draw pixel at (x, y) with specified color + override void drawPixel(int x, int y, uint color) { + if (!_clipRect.isPointInside(x, y)) + return; + color = applyAlpha(color); + uint * row = scanLine(y); + uint alpha = color >> 24; + if (!alpha) { + row[x] = color; + } else if (alpha < 254) { + // apply blending + row[x] = blendARGB(row[x], color, alpha); + } + } + } class GrayDrawBuf : DrawBuf { @@ -828,11 +846,11 @@ class GrayDrawBuf : DrawBuf { } } override void fillRect(Rect rc, uint color) { - ubyte cl = rgbToGray(color); if (applyClipping(rc)) { + uint alpha = color >> 24; + ubyte cl = rgbToGray(color); for (int y = rc.top; y < rc.bottom; y++) { ubyte * row = scanLine(y); - uint alpha = color >> 24; for (int x = rc.left; x < rc.right; x++) { if (!alpha) row[x] = cl; @@ -844,6 +862,22 @@ class GrayDrawBuf : DrawBuf { } } } + + /// draw pixel at (x, y) with specified color + override void drawPixel(int x, int y, uint color) { + if (!_clipRect.isPointInside(x, y)) + return; + color = applyAlpha(color); + ubyte cl = rgbToGray(color); + ubyte * row = scanLine(y); + uint alpha = color >> 24; + if (!alpha) { + row[x] = cl; + } else if (alpha < 254) { + // apply blending + row[x] = blendGray(row[x], cl, alpha); + } + } } class ColorDrawBuf : ColorDrawBufBase { diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index ec294935..ee613c12 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -100,7 +100,17 @@ class GLDrawBuf : DrawBuf, GLConfigCallback { if (!isFullyTransparentColor(color) && applyClipping(rc)) _scene.add(new SolidRectSceneItem(rc, color)); } - /// draw 8bit alpha image - usually font glyph using specified color (clipping is applied) + /// draw pixel at (x, y) with specified color + override void drawPixel(int x, int y, uint color) { + assert(_scene !is null); + if (!_clipRect.isPointInside(x, y)) + return; + color = applyAlpha(color); + if (isFullyTransparentColor(color)) + return; + _scene.add(new SolidRectSceneItem(Rect(x, y, x + 1, y + 1), color)); + } + /// draw 8bit alpha image - usually font glyph using specified color (clipping is applied) override void drawGlyph(int x, int y, Glyph * glyph, uint color) { assert(_scene !is null); Rect dstrect = Rect(x,y, x + glyph.correctedBlackBoxX, y + glyph.blackBoxY);