Skip to content

Commit

Permalink
Implement CornerRadius support for RippleEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
SKProCH committed Apr 27, 2024
1 parent e737aaf commit 9fb298b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions Material.Ripple/RippleEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private CompositionCustomVisual CreateRipple(double x, double y, bool center) {
Ripple.Easing,
Ripple.Duration,
RippleOpacity,
CornerRadius,
x, y, w, h, t);

var visual = ElementComposition.GetElementVisual(this)!.Compositor.CreateCustomVisual(handler);
Expand Down
15 changes: 10 additions & 5 deletions Material.Ripple/RippleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ internal class RippleHandler : CompositionCustomVisualHandler {

private readonly double _maxRadius;
private readonly double _opacity;
private readonly RoundedRect _cornerRadiusRect;
private readonly bool _transitions;
private TimeSpan _animationElapsed;
private TimeSpan? _lastServerTime;
private TimeSpan? _secondStepStart;

public RippleHandler(
IImmutableBrush brush,
public RippleHandler(IImmutableBrush brush,
Easing easing,
TimeSpan duration,
double opacity,
CornerRadius cornerRadius,
double positionX, double positionY,
double outerWidth, double outerHeight, bool transitions) {

_brush = brush;
_easing = easing;
_duration = duration;
_opacity = opacity;
_cornerRadiusRect = new RoundedRect(new Rect(0, 0, outerWidth, outerHeight),
cornerRadius.BottomLeft, cornerRadius.BottomRight,
cornerRadius.BottomRight, cornerRadius.BottomLeft);
_transitions = transitions;
_center = new Point(positionX, positionY);

Expand All @@ -57,8 +60,10 @@ public override void OnRender(ImmediateDrawingContext drawingContext) {
}
}

using (drawingContext.PushOpacity(currentOpacity, default)) {
drawingContext.DrawEllipse(_brush, null, _center, currentRadius, currentRadius);
using (drawingContext.PushClip(_cornerRadiusRect)) {
using (drawingContext.PushOpacity(currentOpacity, default)) {
drawingContext.DrawEllipse(_brush, null, _center, currentRadius, currentRadius);
}
}
}

Expand Down

0 comments on commit 9fb298b

Please sign in to comment.