linear gradients - GL implementation, vertical only

This commit is contained in:
gazer 2017-10-12 02:09:44 +03:00
parent 955d241fac
commit a03f8cf22e
4 changed files with 44 additions and 1 deletions

View File

@ -288,6 +288,8 @@ class DrawBuf : RefCountedObject {
abstract void fill(uint color); abstract void fill(uint color);
/// fill rectangle with solid color (clipping is applied) /// fill rectangle with solid color (clipping is applied)
abstract void fillRect(Rect rc, uint color); 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 /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted
void fillRectPattern(Rect rc, uint color, int pattern) { void fillRectPattern(Rect rc, uint color, int pattern) {
// default implementation: does not support patterns // 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 /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted
override void fillRectPattern(Rect rc, uint color, int pattern) { override void fillRectPattern(Rect rc, uint color, int pattern) {
uint alpha = color >> 24; 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 /// draw pixel at (x, y) with specified color
override void drawPixel(int x, int y, uint color) { override void drawPixel(int x, int y, uint color) {
if (!_clipRect.isPointInside(x, y)) if (!_clipRect.isPointInside(x, y))

View File

@ -114,6 +114,15 @@ class GLDrawBuf : DrawBuf, GLConfigCallback {
_scene.add(new SolidRectSceneItem(rc, color)); _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 /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted
override void fillRectPattern(Rect rc, uint color, int pattern) { override void fillRectPattern(Rect rc, uint color, int pattern) {
if (pattern == PatternType.solid) 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 class PatternRectSceneItem : SceneItem {
private: private:
Rect _rc; Rect _rc;

View File

@ -337,7 +337,7 @@ class GradientDrawable : Drawable {
_color2 = color2; _color2 = color2;
} }
override void drawTo(DrawBuf buf, Rect rc, uint state = 0, int tilex0 = 0, int tiley0 = 0) { 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 width() { return 1; }
@property override int height() { return 1; } @property override int height() { return 1; }

View File

@ -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 /// fill rectangle with solid color and pattern (clipping is applied) 0=solid fill, 1 = dotted
override void fillRectPattern(Rect rc, uint color, int pattern) { override void fillRectPattern(Rect rc, uint color, int pattern) {
// default implementation: does not support patterns // default implementation: does not support patterns