Skip to content

Commit

Permalink
Merge pull request #306 from rehans/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
scheffle authored Oct 7, 2023
2 parents 919bef4 + b64c305 commit da4e395
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
14 changes: 8 additions & 6 deletions vstgui/lib/platform/linux/cairogradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,24 @@ const PatternHandle& Gradient::getLinearGradient (CPoint start, CPoint end) cons
}

//------------------------------------------------------------------------
const PatternHandle& Gradient::getRadialGradient ()
const PatternHandle& Gradient::getRadialGradient (CPoint center, CCoord radius,
CPoint originOffset) const
{
if (!radialGradient)
{
radialGradient = PatternHandle (cairo_pattern_create_radial (0, 0, 1, 0, 0, 1));
radialGradient = PatternHandle (
cairo_pattern_create_radial (center.x, center.y, 0., center.x, center.y, radius));

for (auto& it : getColorStops ())
{
cairo_pattern_add_color_stop_rgba (
radialGradient, it.first, it.second.normRed<double> (),
it.second.normGreen<double> (), it.second.normBlue<double> (),
it.second.normAlpha<double> ());
radialGradient, it.first, it.second.normRed<double> (),
it.second.normGreen<double> (), it.second.normBlue<double> (),
it.second.normAlpha<double> ());
}
}
return radialGradient;
}

//------------------------------------------------------------------------
} // Cairo
} // VSTGUI
3 changes: 2 additions & 1 deletion vstgui/lib/platform/linux/cairogradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Gradient : public PlatformGradientBase
~Gradient () noexcept override;

const PatternHandle& getLinearGradient (CPoint start, CPoint end) const;
const PatternHandle& getRadialGradient ();
const PatternHandle& getRadialGradient (CPoint center, CCoord radius,
CPoint originOffset) const;

private:
void changed () override;
Expand Down
29 changes: 27 additions & 2 deletions vstgui/lib/platform/linux/cairographicscontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,33 @@ bool CairoGraphicsDeviceContext::fillRadialGradient (IPlatformGraphicsPath& path
auto cairoPath = dynamic_cast<Cairo::GraphicsPath*> (&path);
if (!cairoPath)
return false;
// TODO: Implementation
return false;

auto cairoGradient = dynamic_cast<const Cairo::Gradient*> (&gradient);
if (!cairoGradient)
return false;
impl->doInContext ([&] () {
std::unique_ptr<Cairo::GraphicsPath> alignedPath;
if (impl->state.drawMode.integralMode ())
{
alignedPath = cairoPath->copyPixelAlign ([&] (CPoint p) {
p = pixelAlign (impl->state.tm, p);
return p;
});
}
auto p = alignedPath ? alignedPath->getCairoPath () : cairoPath->getCairoPath ();
cairo_append_path (impl->context, p);

const auto& radialGradient =
cairoGradient->getRadialGradient (center, radius, originOffset);
cairo_set_source (impl->context, radialGradient);
if (evenOdd)
cairo_set_fill_rule (impl->context, CAIRO_FILL_RULE_EVEN_ODD);

cairo_arc (impl->context, 0, 0, 0, 0., M_PI * 2.);
cairo_fill (impl->context);
});

return true;
}

//------------------------------------------------------------------------
Expand Down

0 comments on commit da4e395

Please sign in to comment.