diff options
Diffstat (limited to 'gtk/PlatGTK.cxx')
-rw-r--r-- | gtk/PlatGTK.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 42db59903..0f5ea58d9 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -161,6 +161,7 @@ public: void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) override; void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, ColourDesired outline, int alphaOutline, int flags) override; + void GradientRectangle(PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) override; void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) override; void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back) override; void Copy(PRectangle rc, Point from, Surface &surfaceSource) override; @@ -545,6 +546,32 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fi } } +void SurfaceImpl::GradientRectangle(PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) { + if (context) { + cairo_pattern_t *pattern; + switch (options) { + case GradientOptions::leftToRight: + pattern = cairo_pattern_create_linear(rc.left, rc.top, rc.right, rc.top); + break; + case GradientOptions::topToBottom: + default: + pattern = cairo_pattern_create_linear(rc.left, rc.top, rc.left, rc.bottom); + break; + } + for (const ColourStop &stop : stops) { + cairo_pattern_add_color_stop_rgba(pattern, stop.position, + stop.colour.GetRedComponent(), + stop.colour.GetGreenComponent(), + stop.colour.GetBlueComponent(), + stop.colour.GetAlphaComponent()); + } + cairo_rectangle(context, rc.left, rc.top, rc.Width(), rc.Height()); + cairo_set_source(context, pattern); + cairo_fill(context); + cairo_pattern_destroy(pattern); + } +} + void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) { PLATFORM_ASSERT(context); if (rc.Width() > width) |