diff --git a/core-graphics/src/context.rs b/core-graphics/src/context.rs index 7b659cf..3cca450 100644 --- a/core-graphics/src/context.rs +++ b/core-graphics/src/context.rs @@ -9,9 +9,11 @@ use base::CGFloat; use color_space::CGColorSpace; -use core_foundation::base::{CFRelease, CFRetain, CFTypeID}; +use core_foundation::base::{ToVoid, CFRelease, CFRetain, CFTypeID}; use font::{CGFont, CGGlyph}; use geometry::CGPoint; +use color::CGColor; +use path::CGPathRef; use libc::{c_int, size_t}; use std::os::raw::c_void; @@ -20,7 +22,7 @@ use std::ptr; use std::slice; use geometry::{CGAffineTransform, CGRect}; use image::CGImage; -use foreign_types::ForeignType; +use foreign_types::{ForeignType, ForeignTypeRef}; #[repr(C)] pub enum CGTextDrawingMode { @@ -77,7 +79,9 @@ impl CGContext { (self.height() * self.bytes_per_row()) as usize) } } +} +impl CGContextRef { pub fn flush(&self) { unsafe { CGContextFlush(self.as_ptr()) @@ -102,6 +106,12 @@ impl CGContext { } } + pub fn set_fill_color(&self, color: &CGColor) { + unsafe { + CGContextSetFillColorWithColor(self.as_ptr(), color.to_void()); + } + } + pub fn set_rgb_fill_color(&self, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { unsafe { CGContextSetRGBFillColor(self.as_ptr(), red, green, blue, alpha) @@ -174,6 +184,24 @@ impl CGContext { } } + pub fn add_path(&self, path: &CGPathRef) { + unsafe { + CGContextAddPath(self.as_ptr(), path.as_ptr()); + } + } + + pub fn close_path(&self) { + unsafe { + CGContextClosePath(self.as_ptr()); + } + } + + pub fn fill_path(&self) { + unsafe { + CGContextFillPath(self.as_ptr()); + } + } + pub fn fill_rect(&self, rect: CGRect) { unsafe { CGContextFillRect(self.as_ptr(), rect) @@ -222,6 +250,30 @@ impl CGContext { count) } } + + pub fn save(&self) { + unsafe { + CGContextSaveGState(self.as_ptr()); + } + } + + pub fn restore(&self) { + unsafe { + CGContextRestoreGState(self.as_ptr()); + } + } + + pub fn translate(&self, tx: CGFloat, ty: CGFloat) { + unsafe { + CGContextTranslateCTM(self.as_ptr(), tx, ty); + } + } + + pub fn scale(&self, sx: CGFloat, sy: CGFloat) { + unsafe { + CGContextScaleCTM(self.as_ptr(), sx, sy); + } + } } #[test] @@ -279,6 +331,10 @@ extern { fn CGContextSetShouldSubpixelPositionFonts(c: ::sys::CGContextRef, shouldSubpixelPositionFonts: bool); fn CGContextSetTextDrawingMode(c: ::sys::CGContextRef, mode: CGTextDrawingMode); + fn CGContextSetFillColorWithColor(c: ::sys::CGContextRef, color: *const c_void); + fn CGContextAddPath(c: ::sys::CGContextRef, path: ::sys::CGPathRef); + fn CGContextClosePath(c: ::sys::CGContextRef); + fn CGContextFillPath(c: ::sys::CGContextRef); fn CGContextSetRGBFillColor(context: ::sys::CGContextRef, red: CGFloat, green: CGFloat, @@ -295,5 +351,10 @@ extern { glyphs: *const CGGlyph, positions: *const CGPoint, count: size_t); + + fn CGContextSaveGState(c: ::sys::CGContextRef); + fn CGContextRestoreGState(c: ::sys::CGContextRef); + fn CGContextTranslateCTM(c: ::sys::CGContextRef, tx: CGFloat, ty: CGFloat); + fn CGContextScaleCTM(c: ::sys::CGContextRef, sx: CGFloat, sy: CGFloat); }