Skip to content

Commit

Permalink
Export the SkClipOp argument in Canvas.clipRect (flutter#4243)
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons authored Oct 18, 2017
1 parent 5c9e072 commit e50693b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
23 changes: 20 additions & 3 deletions lib/ui/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,18 @@ enum PointMode {
polygon,
}

/// Defines how a new clip region should be merged with the existing clip
/// region.
///
/// Used by [Canvas.clipRect].
enum ClipOp {
/// Subtract the new region from the existing region.
difference,

/// Intersect the new region from the existing region.
intersect,
}

/// An interface for recording graphical operations.
///
/// [Canvas] objects are used in creating [Picture] objects, which can
Expand Down Expand Up @@ -1692,14 +1704,19 @@ class Canvas extends NativeFieldWrapperClass2 {
/// intersect with the clip boundary, this can result in incorrect blending at
/// the clip boundary. See [saveLayer] for a discussion of how to address
/// that.
void clipRect(Rect rect) {
///
/// Use [ClipOp.difference] to subtract the provided rectangle from the
/// current clip.
void clipRect(Rect rect, { ClipOp clipOp: ClipOp.intersect }) {
assert(_rectIsValid(rect));
_clipRect(rect.left, rect.top, rect.right, rect.bottom);
assert(clipOp != null);
_clipRect(rect.left, rect.top, rect.right, rect.bottom, clipOp.index);
}
void _clipRect(double left,
double top,
double right,
double bottom) native "Canvas_clipRect";
double bottom,
int clipOp) native "Canvas_clipRect";

/// Reduces the clip region to the intersection of the current clip and the
/// given rounded rectangle.
Expand Down
9 changes: 6 additions & 3 deletions lib/ui/painting/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ void Canvas::transform(const tonic::Float64List& matrix4) {
canvas_->concat(ToSkMatrix(matrix4));
}

void Canvas::clipRect(double left, double top, double right, double bottom) {
void Canvas::clipRect(double left,
double top,
double right,
double bottom,
SkClipOp clipOp) {
if (!canvas_)
return;
canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom),
SkClipOp::kIntersect, true);
canvas_->clipRect(SkRect::MakeLTRB(left, top, right, bottom), clipOp, true);
}

void Canvas::clipRRect(const RRect& rrect) {
Expand Down
6 changes: 5 additions & 1 deletion lib/ui/painting/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ class Canvas : public fxl::RefCountedThreadSafe<Canvas>,
void skew(double sx, double sy);
void transform(const tonic::Float64List& matrix4);

void clipRect(double left, double top, double right, double bottom);
void clipRect(double left,
double top,
double right,
double bottom,
SkClipOp clipOp);
void clipRRect(const RRect& rrect);
void clipPath(const CanvasPath* path);

Expand Down

0 comments on commit e50693b

Please sign in to comment.