issue #64 - draw points

This commit is contained in:
Vadim Lopatin 2015-03-24 20:47:54 +03:00
parent 5eec0f91cf
commit ca58769a91
2 changed files with 47 additions and 3 deletions

View File

@ -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 {

View File

@ -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);