Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of the radial gradient with cairo for Linux. #306

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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