diff --git a/src/dlangui/graphics/drawbuf.d b/src/dlangui/graphics/drawbuf.d index 0feb73f9..4610ebc6 100644 --- a/src/dlangui/graphics/drawbuf.d +++ b/src/dlangui/graphics/drawbuf.d @@ -288,6 +288,8 @@ class DrawBuf : RefCountedObject { abstract void fill(uint color); /// fill rectangle with solid color (clipping is applied) abstract void fillRect(Rect rc, uint color); + /// fill rectangle with a gradient (clipping is applied) + abstract void fillGradientRect(Rect rc, uint color1, uint color2); /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted void fillRectPattern(Rect rc, uint color, int pattern) { // default implementation: does not support patterns @@ -1161,6 +1163,11 @@ class ColorDrawBufBase : DrawBuf { } } + override void fillGradientRect(Rect rc, uint color1, uint color2) { + // TODO + fillRect(rc, color1); + } + /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted override void fillRectPattern(Rect rc, uint color, int pattern) { uint alpha = color >> 24; @@ -1406,6 +1413,11 @@ class GrayDrawBuf : DrawBuf { } } + override void fillGradientRect(Rect rc, uint color1, uint color2) { + // TODO + fillRect(rc, color1); + } + /// draw pixel at (x, y) with specified color override void drawPixel(int x, int y, uint color) { if (!_clipRect.isPointInside(x, y)) diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 2966ac9e..19165bc3 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -114,6 +114,15 @@ class GLDrawBuf : DrawBuf, GLConfigCallback { _scene.add(new SolidRectSceneItem(rc, color)); } + /// fill rectangle with a gradient (clipping is applied) + override void fillGradientRect(Rect rc, uint color1, uint color2) { + assert(_scene !is null); + color1 = applyAlpha(color1); + color2 = applyAlpha(color2); + if (!(isFullyTransparentColor(color1) && isFullyTransparentColor(color2)) && applyClipping(rc)) + _scene.add(new GradientRectSceneItem(rc, color1, color2)); + } + /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted override void fillRectPattern(Rect rc, uint color, int pattern) { if (pattern == PatternType.solid) @@ -749,6 +758,23 @@ public: } } +private class GradientRectSceneItem : SceneItem { +private: + Rect _rc; + uint _color1; + uint _color2; + +public: + this(Rect rc, uint color1, uint color2) { + _rc = rc; + _color1 = color1; + _color2 = color2; + } + override void draw() { + glSupport.queue.addGradientRect(_rc, _color1, _color2, _color1, _color2); + } +} + private class PatternRectSceneItem : SceneItem { private: Rect _rc; diff --git a/src/dlangui/graphics/resources.d b/src/dlangui/graphics/resources.d index 766fed92..81d84a34 100644 --- a/src/dlangui/graphics/resources.d +++ b/src/dlangui/graphics/resources.d @@ -337,7 +337,7 @@ class GradientDrawable : Drawable { _color2 = color2; } override void drawTo(DrawBuf buf, Rect rc, uint state = 0, int tilex0 = 0, int tiley0 = 0) { - buf.fillRect(rc, _color1); // stub + buf.fillGradientRect(rc, _color1, _color2); } @property override int width() { return 1; } @property override int height() { return 1; } diff --git a/src/dlangui/platforms/console/consoleapp.d b/src/dlangui/platforms/console/consoleapp.d index eb0c746c..c59edcb5 100644 --- a/src/dlangui/platforms/console/consoleapp.d +++ b/src/dlangui/platforms/console/consoleapp.d @@ -406,6 +406,11 @@ class ConsoleDrawBuf : DrawBuf { } } + override void fillGradientRect(Rect rc, uint color1, uint color2) { + // TODO + fillRect(rc, color1); + } + /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted override void fillRectPattern(Rect rc, uint color, int pattern) { // default implementation: does not support patterns