From 2d5bdcc9b529bdaddaf45b36588e318aecd28fa3 Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 29 Apr 2019 10:27:49 +0900 Subject: [PATCH] Add `CGContext::{clip_to_rect, clip_to_rects}` --- core-graphics/src/context.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core-graphics/src/context.rs b/core-graphics/src/context.rs index d8e9c36..ec0b7b1 100644 --- a/core-graphics/src/context.rs +++ b/core-graphics/src/context.rs @@ -415,6 +415,18 @@ impl CGContextRef { } } + pub fn clip_to_rect(&self, rect: CGRect) { + unsafe { + CGContextClipToRect(self.as_ptr(), rect) + } + } + + pub fn clip_to_rects(&self, rects: &[CGRect]) { + unsafe { + CGContextClipToRects(self.as_ptr(), rects.as_ptr(), rects.len()) + } + } + pub fn replace_path_with_stroked_path(&self) { unsafe { CGContextReplacePathWithStrokedPath(self.as_ptr()) @@ -640,6 +652,11 @@ extern { fn CGContextStrokeRectWithWidth(context: ::sys::CGContextRef, rect: CGRect, width: CGFloat); + fn CGContextClipToRect(context: ::sys::CGContextRef, + rect: CGRect); + fn CGContextClipToRects(context: ::sys::CGContextRef, + rects: *const CGRect, + count: size_t); fn CGContextReplacePathWithStrokedPath(context: ::sys::CGContextRef); fn CGContextFillEllipseInRect(context: ::sys::CGContextRef, rect: CGRect);