Auto-format code with "cargo fmt" and check in CI (#615)

* add rustfmt check to CI

* Run "cargo fmt" (rustfmt) over core-foundation-rs
This commit is contained in:
micolous
2023-07-25 12:22:25 +10:00
committed by GitHub
parent 127f2be94c
commit b009c87f2d
102 changed files with 6060 additions and 3567 deletions
+11 -6
View File
@@ -7,21 +7,21 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core_foundation::base::{CFTypeID};
use super::sys::CGColorRef;
use base::CGFloat;
use core_foundation::base::CFTypeID;
use core_foundation::base::TCFType;
use super::sys::{CGColorRef};
pub use super::sys::CGColorRef as SysCGColorRef;
declare_TCFType!{
declare_TCFType! {
CGColor, CGColorRef
}
impl_TCFType!(CGColor, CGColorRef, CGColorGetTypeID);
impl CGColor {
pub fn rgb(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> Self {
unsafe {
unsafe {
let ptr = CGColorCreateGenericRGB(red, green, blue, alpha);
CGColor::wrap_under_create_rule(ptr)
}
@@ -29,7 +29,12 @@ impl CGColor {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
fn CGColorCreateGenericRGB(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> ::sys::CGColorRef;
extern "C" {
fn CGColorCreateGenericRGB(
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
) -> ::sys::CGColorRef;
fn CGColorGetTypeID() -> CFTypeID;
}
+7 -6
View File
@@ -22,15 +22,17 @@ foreign_type! {
impl CGColorSpace {
pub fn type_id() -> CFTypeID {
unsafe {
CGColorSpaceGetTypeID()
}
unsafe { CGColorSpaceGetTypeID() }
}
pub fn create_with_name(name: CFStringRef) -> Option<CGColorSpace> {
unsafe {
let p = CGColorSpaceCreateWithName(name);
if !p.is_null() {Some(CGColorSpace::from_ptr(p))} else {None}
if !p.is_null() {
Some(CGColorSpace::from_ptr(p))
} else {
None
}
}
}
@@ -52,7 +54,7 @@ impl CGColorSpace {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
/// The Display P3 color space, created by Apple.
pub static kCGColorSpaceDisplayP3: CFStringRef;
/// The Display P3 color space, using the HLG transfer function.
@@ -114,4 +116,3 @@ extern {
fn CGColorSpaceCreateWithName(name: CFStringRef) -> ::sys::CGColorSpaceRef;
fn CGColorSpaceGetTypeID() -> CFTypeID;
}
+255 -263
View File
@@ -8,22 +8,22 @@
// except according to those terms.
use base::CGFloat;
use color::CGColor;
use color_space::CGColorSpace;
use core_foundation::base::{CFTypeID, TCFType};
use font::{CGFont, CGGlyph};
use geometry::{CGPoint, CGSize};
use gradient::{CGGradient, CGGradientDrawingOptions};
use color::CGColor;
use path::CGPathRef;
use libc::{c_int, size_t};
use path::CGPathRef;
use std::os::raw::c_void;
use foreign_types::{ForeignType, ForeignTypeRef};
use geometry::{CGAffineTransform, CGRect};
use image::CGImage;
use std::cmp;
use std::ptr;
use std::slice;
use geometry::{CGAffineTransform, CGRect};
use image::CGImage;
use foreign_types::{ForeignType, ForeignTypeRef};
#[repr(C)]
#[derive(Clone, Copy, Debug)]
@@ -68,7 +68,7 @@ pub enum CGTextDrawingMode {
CGTextFillClip,
CGTextStrokeClip,
CGTextFillStrokeClip,
CGTextClip
CGTextClip,
}
#[repr(C)]
@@ -118,19 +118,17 @@ foreign_type! {
impl CGContext {
pub fn type_id() -> CFTypeID {
unsafe {
CGContextGetTypeID()
}
unsafe { CGContextGetTypeID() }
}
/// Creates a `CGContext` instance from an existing [`CGContextRef`] pointer.
///
/// Creates a `CGContext` instance from an existing [`CGContextRef`] pointer.
///
/// This funtion will internally call [`CGRetain`] and hence there is no need to call it explicitly.
///
///
/// This function is particularly useful for cases when the context is not instantiated/managed
/// by the caller, but it's retrieve via other means (e.g., by calling the method [`NSGraphicsContext::CGContext`]
/// in a cocoa application).
///
///
/// [`CGContextRef`]: https://developer.apple.com/documentation/coregraphics/cgcontextref
/// [`CGRetain`]: https://developer.apple.com/documentation/coregraphics/1586506-cgcontextretain
/// [`NSGraphicsContext::CGContext`]: https://developer.apple.com/documentation/appkit/nsgraphicscontext/1535352-currentcontext
@@ -139,22 +137,25 @@ impl CGContext {
Self::from_ptr(ctx)
}
pub fn create_bitmap_context(data: Option<*mut c_void>,
width: size_t,
height: size_t,
bits_per_component: size_t,
bytes_per_row: size_t,
space: &CGColorSpace,
bitmap_info: u32)
-> CGContext {
pub fn create_bitmap_context(
data: Option<*mut c_void>,
width: size_t,
height: size_t,
bits_per_component: size_t,
bytes_per_row: size_t,
space: &CGColorSpace,
bitmap_info: u32,
) -> CGContext {
unsafe {
let result = CGBitmapContextCreate(data.unwrap_or(ptr::null_mut()),
width,
height,
bits_per_component,
bytes_per_row,
space.as_ptr(),
bitmap_info);
let result = CGBitmapContextCreate(
data.unwrap_or(ptr::null_mut()),
width,
height,
bits_per_component,
bytes_per_row,
space.as_ptr(),
bitmap_info,
);
assert!(!result.is_null());
Self::from_ptr(result)
}
@@ -163,41 +164,32 @@ impl CGContext {
pub fn data(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(
CGBitmapContextGetData(self.as_ptr()) as *mut u8,
(self.height() * self.bytes_per_row()) as usize)
CGBitmapContextGetData(self.as_ptr()) as *mut u8,
(self.height() * self.bytes_per_row()) as usize,
)
}
}
}
impl CGContextRef {
pub fn flush(&self) {
unsafe {
CGContextFlush(self.as_ptr())
}
unsafe { CGContextFlush(self.as_ptr()) }
}
pub fn width(&self) -> size_t {
unsafe {
CGBitmapContextGetWidth(self.as_ptr())
}
unsafe { CGBitmapContextGetWidth(self.as_ptr()) }
}
pub fn height(&self) -> size_t {
unsafe {
CGBitmapContextGetHeight(self.as_ptr())
}
unsafe { CGBitmapContextGetHeight(self.as_ptr()) }
}
pub fn bytes_per_row(&self) -> size_t {
unsafe {
CGBitmapContextGetBytesPerRow(self.as_ptr())
}
unsafe { CGBitmapContextGetBytesPerRow(self.as_ptr()) }
}
pub fn clip_bounding_box(&self) -> CGRect {
unsafe {
CGContextGetClipBoundingBox(self.as_ptr())
}
unsafe { CGContextGetClipBoundingBox(self.as_ptr()) }
}
pub fn set_fill_color(&self, color: &CGColor) {
@@ -207,33 +199,29 @@ impl CGContextRef {
}
pub fn set_rgb_fill_color(&self, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
unsafe {
CGContextSetRGBFillColor(self.as_ptr(), red, green, blue, alpha)
}
unsafe { CGContextSetRGBFillColor(self.as_ptr(), red, green, blue, alpha) }
}
pub fn set_rgb_stroke_color(&self, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
unsafe {
CGContextSetRGBStrokeColor(self.as_ptr(), red, green, blue, alpha)
}
pub fn set_rgb_stroke_color(
&self,
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
) {
unsafe { CGContextSetRGBStrokeColor(self.as_ptr(), red, green, blue, alpha) }
}
pub fn set_gray_fill_color(&self, gray: CGFloat, alpha: CGFloat) {
unsafe {
CGContextSetGrayFillColor(self.as_ptr(), gray, alpha)
}
unsafe { CGContextSetGrayFillColor(self.as_ptr(), gray, alpha) }
}
pub fn set_blend_mode(&self, blend_mode: CGBlendMode) {
unsafe {
CGContextSetBlendMode(self.as_ptr(), blend_mode)
}
unsafe { CGContextSetBlendMode(self.as_ptr(), blend_mode) }
}
pub fn set_allows_font_smoothing(&self, allows_font_smoothing: bool) {
unsafe {
CGContextSetAllowsFontSmoothing(self.as_ptr(), allows_font_smoothing)
}
unsafe { CGContextSetAllowsFontSmoothing(self.as_ptr(), allows_font_smoothing) }
}
pub fn set_font_smoothing_style(&self, style: i32) {
@@ -243,26 +231,23 @@ impl CGContextRef {
}
pub fn set_should_smooth_fonts(&self, should_smooth_fonts: bool) {
unsafe {
CGContextSetShouldSmoothFonts(self.as_ptr(), should_smooth_fonts)
}
unsafe { CGContextSetShouldSmoothFonts(self.as_ptr(), should_smooth_fonts) }
}
pub fn set_allows_antialiasing(&self, allows_antialiasing: bool) {
unsafe {
CGContextSetAllowsAntialiasing(self.as_ptr(), allows_antialiasing)
}
unsafe { CGContextSetAllowsAntialiasing(self.as_ptr(), allows_antialiasing) }
}
pub fn set_should_antialias(&self, should_antialias: bool) {
unsafe {
CGContextSetShouldAntialias(self.as_ptr(), should_antialias)
}
unsafe { CGContextSetShouldAntialias(self.as_ptr(), should_antialias) }
}
pub fn set_allows_font_subpixel_quantization(&self, allows_font_subpixel_quantization: bool) {
unsafe {
CGContextSetAllowsFontSubpixelQuantization(self.as_ptr(), allows_font_subpixel_quantization)
CGContextSetAllowsFontSubpixelQuantization(
self.as_ptr(),
allows_font_subpixel_quantization,
)
}
}
@@ -274,7 +259,10 @@ impl CGContextRef {
pub fn set_allows_font_subpixel_positioning(&self, allows_font_subpixel_positioning: bool) {
unsafe {
CGContextSetAllowsFontSubpixelPositioning(self.as_ptr(), allows_font_subpixel_positioning)
CGContextSetAllowsFontSubpixelPositioning(
self.as_ptr(),
allows_font_subpixel_positioning,
)
}
}
@@ -285,39 +273,27 @@ impl CGContextRef {
}
pub fn set_text_drawing_mode(&self, mode: CGTextDrawingMode) {
unsafe {
CGContextSetTextDrawingMode(self.as_ptr(), mode)
}
unsafe { CGContextSetTextDrawingMode(self.as_ptr(), mode) }
}
pub fn set_line_cap(&self, cap: CGLineCap) {
unsafe {
CGContextSetLineCap(self.as_ptr(), cap)
}
unsafe { CGContextSetLineCap(self.as_ptr(), cap) }
}
pub fn set_line_dash(&self, phase: CGFloat, lengths: &[CGFloat]) {
unsafe {
CGContextSetLineDash(self.as_ptr(), phase, lengths.as_ptr(), lengths.len())
}
unsafe { CGContextSetLineDash(self.as_ptr(), phase, lengths.as_ptr(), lengths.len()) }
}
pub fn set_line_join(&self, join: CGLineJoin) {
unsafe {
CGContextSetLineJoin(self.as_ptr(), join)
}
unsafe { CGContextSetLineJoin(self.as_ptr(), join) }
}
pub fn set_line_width(&self, width: CGFloat) {
unsafe {
CGContextSetLineWidth(self.as_ptr(), width)
}
unsafe { CGContextSetLineWidth(self.as_ptr(), width) }
}
pub fn set_miter_limit(&self, limit: CGFloat) {
unsafe {
CGContextSetMiterLimit(self.as_ptr(), limit)
}
unsafe { CGContextSetMiterLimit(self.as_ptr(), limit) }
}
pub fn add_path(&self, path: &CGPathRef) {
@@ -326,30 +302,23 @@ impl CGContextRef {
}
}
pub fn add_curve_to_point(&self,
cp1x: CGFloat,
cp1y: CGFloat,
cp2x: CGFloat,
cp2y: CGFloat,
x: CGFloat,
y: CGFloat) {
pub fn add_curve_to_point(
&self,
cp1x: CGFloat,
cp1y: CGFloat,
cp2x: CGFloat,
cp2y: CGFloat,
x: CGFloat,
y: CGFloat,
) {
unsafe {
CGContextAddCurveToPoint(self.as_ptr(),
cp1x, cp1y,
cp2x, cp2y,
x, y);
CGContextAddCurveToPoint(self.as_ptr(), cp1x, cp1y, cp2x, cp2y, x, y);
}
}
pub fn add_quad_curve_to_point(&self,
cpx: CGFloat,
cpy: CGFloat,
x: CGFloat,
y: CGFloat) {
pub fn add_quad_curve_to_point(&self, cpx: CGFloat, cpy: CGFloat, x: CGFloat, y: CGFloat) {
unsafe {
CGContextAddQuadCurveToPoint(self.as_ptr(),
cpx, cpy,
x, y);
CGContextAddQuadCurveToPoint(self.as_ptr(), cpx, cpy, x, y);
}
}
@@ -360,7 +329,7 @@ impl CGContextRef {
}
pub fn begin_path(&self) {
unsafe {
unsafe {
CGContextBeginPath(self.as_ptr());
}
}
@@ -420,75 +389,51 @@ impl CGContextRef {
}
pub fn fill_rect(&self, rect: CGRect) {
unsafe {
CGContextFillRect(self.as_ptr(), rect)
}
unsafe { CGContextFillRect(self.as_ptr(), rect) }
}
pub fn fill_rects(&self, rects: &[CGRect]) {
unsafe {
CGContextFillRects(self.as_ptr(), rects.as_ptr(), rects.len())
}
unsafe { CGContextFillRects(self.as_ptr(), rects.as_ptr(), rects.len()) }
}
pub fn clear_rect(&self, rect: CGRect) {
unsafe {
CGContextClearRect(self.as_ptr(), rect)
}
unsafe { CGContextClearRect(self.as_ptr(), rect) }
}
pub fn stroke_rect(&self, rect: CGRect) {
unsafe {
CGContextStrokeRect(self.as_ptr(), rect)
}
unsafe { CGContextStrokeRect(self.as_ptr(), rect) }
}
pub fn stroke_rect_with_width(&self, rect: CGRect, width: CGFloat) {
unsafe {
CGContextStrokeRectWithWidth(self.as_ptr(), rect, width)
}
unsafe { CGContextStrokeRectWithWidth(self.as_ptr(), rect, width) }
}
pub fn clip_to_rect(&self, rect: CGRect) {
unsafe {
CGContextClipToRect(self.as_ptr(), rect)
}
unsafe { CGContextClipToRect(self.as_ptr(), rect) }
}
pub fn clip_to_rects(&self, rects: &[CGRect]) {
unsafe {
CGContextClipToRects(self.as_ptr(), rects.as_ptr(), rects.len())
}
unsafe { CGContextClipToRects(self.as_ptr(), rects.as_ptr(), rects.len()) }
}
pub fn clip_to_mask(&self, rect: CGRect, image: &CGImage) {
unsafe {
CGContextClipToMask(self.as_ptr(), rect, image.as_ptr())
}
unsafe { CGContextClipToMask(self.as_ptr(), rect, image.as_ptr()) }
}
pub fn replace_path_with_stroked_path(&self) {
unsafe {
CGContextReplacePathWithStrokedPath(self.as_ptr())
}
unsafe { CGContextReplacePathWithStrokedPath(self.as_ptr()) }
}
pub fn fill_ellipse_in_rect(&self, rect: CGRect) {
unsafe {
CGContextFillEllipseInRect(self.as_ptr(), rect)
}
unsafe { CGContextFillEllipseInRect(self.as_ptr(), rect) }
}
pub fn stroke_ellipse_in_rect(&self, rect: CGRect) {
unsafe {
CGContextStrokeEllipseInRect(self.as_ptr(), rect)
}
unsafe { CGContextStrokeEllipseInRect(self.as_ptr(), rect) }
}
pub fn stroke_line_segments(&self, points: &[CGPoint]) {
unsafe {
CGContextStrokeLineSegments(self.as_ptr(), points.as_ptr(), points.len())
}
unsafe { CGContextStrokeLineSegments(self.as_ptr(), points.as_ptr(), points.len()) }
}
pub fn set_interpolation_quality(&self, quality: CGInterpolationQuality) {
@@ -498,10 +443,7 @@ impl CGContextRef {
}
pub fn get_interpolation_quality(&self) -> CGInterpolationQuality {
unsafe {
CGContextGetInterpolationQuality(self.as_ptr())
}
unsafe { CGContextGetInterpolationQuality(self.as_ptr()) }
}
pub fn draw_image(&self, rect: CGRect, image: &CGImage) {
@@ -520,36 +462,30 @@ impl CGContextRef {
}
pub fn set_font(&self, font: &CGFont) {
unsafe {
CGContextSetFont(self.as_ptr(), font.as_ptr())
}
unsafe { CGContextSetFont(self.as_ptr(), font.as_ptr()) }
}
pub fn set_font_size(&self, size: CGFloat) {
unsafe {
CGContextSetFontSize(self.as_ptr(), size)
}
unsafe { CGContextSetFontSize(self.as_ptr(), size) }
}
pub fn set_text_matrix(&self, t: &CGAffineTransform) {
unsafe {
CGContextSetTextMatrix(self.as_ptr(), *t)
}
unsafe { CGContextSetTextMatrix(self.as_ptr(), *t) }
}
pub fn set_text_position(&self, x: CGFloat, y: CGFloat) {
unsafe {
CGContextSetTextPosition(self.as_ptr(), x, y)
}
unsafe { CGContextSetTextPosition(self.as_ptr(), x, y) }
}
pub fn show_glyphs_at_positions(&self, glyphs: &[CGGlyph], positions: &[CGPoint]) {
unsafe {
let count = cmp::min(glyphs.len(), positions.len());
CGContextShowGlyphsAtPositions(self.as_ptr(),
glyphs.as_ptr(),
positions.as_ptr(),
count)
CGContextShowGlyphsAtPositions(
self.as_ptr(),
glyphs.as_ptr(),
positions.as_ptr(),
count,
)
}
}
@@ -584,26 +520,50 @@ impl CGContextRef {
}
pub fn get_ctm(&self) -> CGAffineTransform {
unsafe {
CGContextGetCTM(self.as_ptr())
}
unsafe { CGContextGetCTM(self.as_ptr()) }
}
pub fn concat_ctm(&self, transform: CGAffineTransform) {
unsafe { CGContextConcatCTM(self.as_ptr(), transform) }
}
pub fn draw_linear_gradient(
&self,
gradient: &CGGradient,
start_point: CGPoint,
end_point: CGPoint,
options: CGGradientDrawingOptions,
) {
unsafe {
CGContextConcatCTM(self.as_ptr(), transform)
CGContextDrawLinearGradient(
self.as_ptr(),
gradient.as_ptr(),
start_point,
end_point,
options,
);
}
}
pub fn draw_linear_gradient(&self, gradient: &CGGradient, start_point: CGPoint, end_point: CGPoint, options: CGGradientDrawingOptions) {
pub fn draw_radial_gradient(
&self,
gradient: &CGGradient,
start_center: CGPoint,
start_radius: CGFloat,
end_center: CGPoint,
end_radius: CGFloat,
options: CGGradientDrawingOptions,
) {
unsafe {
CGContextDrawLinearGradient(self.as_ptr(), gradient.as_ptr(), start_point, end_point, options);
}
}
pub fn draw_radial_gradient(&self, gradient: &CGGradient, start_center: CGPoint, start_radius: CGFloat, end_center: CGPoint, end_radius: CGFloat, options: CGGradientDrawingOptions) {
unsafe {
CGContextDrawRadialGradient(self.as_ptr(), gradient.as_ptr(), start_center, start_radius, end_center, end_radius, options);
CGContextDrawRadialGradient(
self.as_ptr(),
gradient.as_ptr(),
start_center,
start_radius,
end_center,
end_radius,
options,
);
}
}
@@ -631,14 +591,18 @@ fn create_bitmap_context_test() {
use geometry::*;
let cs = CGColorSpace::create_device_rgb();
let ctx = CGContext::create_bitmap_context(None,
16, 8,
8, 0,
&cs,
::base::kCGImageAlphaPremultipliedLast);
ctx.set_rgb_fill_color(1.,0.,1.,1.);
let ctx = CGContext::create_bitmap_context(
None,
16,
8,
8,
0,
&cs,
::base::kCGImageAlphaPremultipliedLast,
);
ctx.set_rgb_fill_color(1., 0., 1., 1.);
ctx.set_miter_limit(4.);
ctx.fill_rect(CGRect::new(&CGPoint::new(0.,0.), &CGSize::new(8.,8.)));
ctx.fill_rect(CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(8., 8.)));
let img = ctx.create_image().unwrap();
assert_eq!(16, img.width());
assert_eq!(8, img.height());
@@ -652,18 +616,19 @@ fn create_bitmap_context_test() {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
fn CGContextRetain(c: ::sys::CGContextRef) -> ::sys::CGContextRef;
fn CGContextRelease(c: ::sys::CGContextRef);
fn CGBitmapContextCreate(data: *mut c_void,
width: size_t,
height: size_t,
bitsPerComponent: size_t,
bytesPerRow: size_t,
space: ::sys::CGColorSpaceRef,
bitmapInfo: u32)
-> ::sys::CGContextRef;
fn CGBitmapContextCreate(
data: *mut c_void,
width: size_t,
height: size_t,
bitsPerComponent: size_t,
bytesPerRow: size_t,
space: ::sys::CGColorSpaceRef,
bitmapInfo: u32,
) -> ::sys::CGContextRef;
fn CGBitmapContextGetData(context: ::sys::CGContextRef) -> *mut c_void;
fn CGBitmapContextGetWidth(context: ::sys::CGContextRef) -> size_t;
fn CGBitmapContextGetHeight(context: ::sys::CGContextRef) -> size_t;
@@ -678,43 +643,56 @@ extern {
fn CGContextSetFontSmoothingStyle(c: ::sys::CGContextRef, style: c_int);
fn CGContextSetAllowsAntialiasing(c: ::sys::CGContextRef, allowsAntialiasing: bool);
fn CGContextSetShouldAntialias(c: ::sys::CGContextRef, shouldAntialias: bool);
fn CGContextSetAllowsFontSubpixelQuantization(c: ::sys::CGContextRef,
allowsFontSubpixelQuantization: bool);
fn CGContextSetShouldSubpixelQuantizeFonts(c: ::sys::CGContextRef,
shouldSubpixelQuantizeFonts: bool);
fn CGContextSetAllowsFontSubpixelPositioning(c: ::sys::CGContextRef,
allowsFontSubpixelPositioning: bool);
fn CGContextSetShouldSubpixelPositionFonts(c: ::sys::CGContextRef,
shouldSubpixelPositionFonts: bool);
fn CGContextSetAllowsFontSubpixelQuantization(
c: ::sys::CGContextRef,
allowsFontSubpixelQuantization: bool,
);
fn CGContextSetShouldSubpixelQuantizeFonts(
c: ::sys::CGContextRef,
shouldSubpixelQuantizeFonts: bool,
);
fn CGContextSetAllowsFontSubpixelPositioning(
c: ::sys::CGContextRef,
allowsFontSubpixelPositioning: bool,
);
fn CGContextSetShouldSubpixelPositionFonts(
c: ::sys::CGContextRef,
shouldSubpixelPositionFonts: bool,
);
fn CGContextSetTextDrawingMode(c: ::sys::CGContextRef, mode: CGTextDrawingMode);
fn CGContextSetFillColorWithColor(c: ::sys::CGContextRef, color: ::sys::CGColorRef);
fn CGContextSetLineCap(c: ::sys::CGContextRef, cap: CGLineCap);
fn CGContextSetLineDash(c: ::sys::CGContextRef, phase: CGFloat, lengths: *const CGFloat, count: size_t);
fn CGContextSetLineDash(
c: ::sys::CGContextRef,
phase: CGFloat,
lengths: *const CGFloat,
count: size_t,
);
fn CGContextSetLineJoin(c: ::sys::CGContextRef, join: CGLineJoin);
fn CGContextSetLineWidth(c: ::sys::CGContextRef, width: CGFloat);
fn CGContextSetMiterLimit(c: ::sys::CGContextRef, limit: CGFloat);
fn CGContextAddPath(c: ::sys::CGContextRef, path: ::sys::CGPathRef);
fn CGContextAddCurveToPoint(c: ::sys::CGContextRef,
cp1x: CGFloat,
cp1y: CGFloat,
cp2x: CGFloat,
cp2y: CGFloat,
x: CGFloat,
y: CGFloat);
fn CGContextAddQuadCurveToPoint(c: ::sys::CGContextRef,
cpx: CGFloat,
cpy: CGFloat,
x: CGFloat,
y: CGFloat);
fn CGContextAddLineToPoint(c: ::sys::CGContextRef,
x: CGFloat,
y: CGFloat);
fn CGContextAddCurveToPoint(
c: ::sys::CGContextRef,
cp1x: CGFloat,
cp1y: CGFloat,
cp2x: CGFloat,
cp2y: CGFloat,
x: CGFloat,
y: CGFloat,
);
fn CGContextAddQuadCurveToPoint(
c: ::sys::CGContextRef,
cpx: CGFloat,
cpy: CGFloat,
x: CGFloat,
y: CGFloat,
);
fn CGContextAddLineToPoint(c: ::sys::CGContextRef, x: CGFloat, y: CGFloat);
fn CGContextBeginPath(c: ::sys::CGContextRef);
fn CGContextClosePath(c: ::sys::CGContextRef);
fn CGContextMoveToPoint(c: ::sys::CGContextRef,
x: CGFloat,
y: CGFloat);
fn CGContextMoveToPoint(c: ::sys::CGContextRef, x: CGFloat, y: CGFloat);
fn CGContextDrawPath(c: ::sys::CGContextRef, mode: CGPathDrawingMode);
fn CGContextFillPath(c: ::sys::CGContextRef);
fn CGContextEOFillPath(c: ::sys::CGContextRef);
@@ -722,43 +700,37 @@ extern {
fn CGContextEOClip(c: ::sys::CGContextRef);
fn CGContextResetClip(c: ::sys::CGContextRef);
fn CGContextStrokePath(c: ::sys::CGContextRef);
fn CGContextSetRGBFillColor(context: ::sys::CGContextRef,
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat);
fn CGContextSetRGBStrokeColor(context: ::sys::CGContextRef,
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat);
fn CGContextSetRGBFillColor(
context: ::sys::CGContextRef,
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
);
fn CGContextSetRGBStrokeColor(
context: ::sys::CGContextRef,
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
);
fn CGContextSetGrayFillColor(context: ::sys::CGContextRef, gray: CGFloat, alpha: CGFloat);
fn CGContextClearRect(context: ::sys::CGContextRef,
rect: CGRect);
fn CGContextFillRect(context: ::sys::CGContextRef,
rect: CGRect);
fn CGContextFillRects(context: ::sys::CGContextRef,
rects: *const CGRect,
count: size_t);
fn CGContextStrokeRect(context: ::sys::CGContextRef,
rect: CGRect);
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 CGContextClearRect(context: ::sys::CGContextRef, rect: CGRect);
fn CGContextFillRect(context: ::sys::CGContextRef, rect: CGRect);
fn CGContextFillRects(context: ::sys::CGContextRef, rects: *const CGRect, count: size_t);
fn CGContextStrokeRect(context: ::sys::CGContextRef, rect: CGRect);
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 CGContextClipToMask(ctx: ::sys::CGContextRef, rect: CGRect, mask: ::sys::CGImageRef);
fn CGContextReplacePathWithStrokedPath(context: ::sys::CGContextRef);
fn CGContextFillEllipseInRect(context: ::sys::CGContextRef,
rect: CGRect);
fn CGContextStrokeEllipseInRect(context: ::sys::CGContextRef,
rect: CGRect);
fn CGContextStrokeLineSegments(context: ::sys::CGContextRef,
points: *const CGPoint,
count: size_t);
fn CGContextFillEllipseInRect(context: ::sys::CGContextRef, rect: CGRect);
fn CGContextStrokeEllipseInRect(context: ::sys::CGContextRef, rect: CGRect);
fn CGContextStrokeLineSegments(
context: ::sys::CGContextRef,
points: *const CGPoint,
count: size_t,
);
fn CGContextDrawImage(c: ::sys::CGContextRef, rect: CGRect, image: ::sys::CGImageRef);
fn CGContextSetInterpolationQuality(c: ::sys::CGContextRef, quality: CGInterpolationQuality);
fn CGContextGetInterpolationQuality(c: ::sys::CGContextRef) -> CGInterpolationQuality;
@@ -766,10 +738,12 @@ extern {
fn CGContextSetFontSize(c: ::sys::CGContextRef, size: CGFloat);
fn CGContextSetTextMatrix(c: ::sys::CGContextRef, t: CGAffineTransform);
fn CGContextSetTextPosition(c: ::sys::CGContextRef, x: CGFloat, y: CGFloat);
fn CGContextShowGlyphsAtPositions(c: ::sys::CGContextRef,
glyphs: *const CGGlyph,
positions: *const CGPoint,
count: size_t);
fn CGContextShowGlyphsAtPositions(
c: ::sys::CGContextRef,
glyphs: *const CGGlyph,
positions: *const CGPoint,
count: size_t,
);
fn CGContextSaveGState(c: ::sys::CGContextRef);
fn CGContextRestoreGState(c: ::sys::CGContextRef);
@@ -779,12 +753,30 @@ extern {
fn CGContextGetCTM(c: ::sys::CGContextRef) -> CGAffineTransform;
fn CGContextConcatCTM(c: ::sys::CGContextRef, transform: CGAffineTransform);
fn CGContextDrawLinearGradient(c: ::sys::CGContextRef, gradient: ::sys::CGGradientRef, startPoint: CGPoint, endPoint: CGPoint, options: CGGradientDrawingOptions);
fn CGContextDrawRadialGradient(c: ::sys::CGContextRef, gradient: ::sys::CGGradientRef, startCenter: CGPoint, startRadius: CGFloat, endCenter:CGPoint, endRadius:CGFloat, options: CGGradientDrawingOptions);
fn CGContextDrawLinearGradient(
c: ::sys::CGContextRef,
gradient: ::sys::CGGradientRef,
startPoint: CGPoint,
endPoint: CGPoint,
options: CGGradientDrawingOptions,
);
fn CGContextDrawRadialGradient(
c: ::sys::CGContextRef,
gradient: ::sys::CGGradientRef,
startCenter: CGPoint,
startRadius: CGFloat,
endCenter: CGPoint,
endRadius: CGFloat,
options: CGGradientDrawingOptions,
);
fn CGContextSetShadow(c: ::sys::CGContextRef, offset: CGSize, blur: CGFloat);
fn CGContextSetShadowWithColor(c: ::sys::CGContextRef, offset: CGSize, blur: CGFloat, color: ::sys::CGColorRef);
fn CGContextSetShadowWithColor(
c: ::sys::CGContextRef,
offset: CGSize,
blur: CGFloat,
color: ::sys::CGColorRef,
);
fn CGContextSetAlpha(c: ::sys::CGContextRef, alpha: CGFloat);
}
+34 -23
View File
@@ -10,25 +10,32 @@
use core_foundation::base::{CFRelease, CFRetain, CFTypeID, TCFType};
use core_foundation::data::{CFData, CFDataRef};
use libc::{size_t, off_t};
use libc::{off_t, size_t};
use std::mem;
use std::os::raw::c_void;
use std::ptr;
use std::sync::Arc;
use std::os::raw::c_void;
use foreign_types::{ForeignType, ForeignTypeRef};
pub type CGDataProviderGetBytesCallback = Option<unsafe extern fn (*mut c_void, *mut c_void, size_t) -> size_t>;
pub type CGDataProviderReleaseInfoCallback = Option<unsafe extern fn (*mut c_void)>;
pub type CGDataProviderRewindCallback = Option<unsafe extern fn (*mut c_void)>;
pub type CGDataProviderSkipBytesCallback = Option<unsafe extern fn (*mut c_void, size_t)>;
pub type CGDataProviderSkipForwardCallback = Option<unsafe extern fn (*mut c_void, off_t) -> off_t>;
pub type CGDataProviderGetBytesCallback =
Option<unsafe extern "C" fn(*mut c_void, *mut c_void, size_t) -> size_t>;
pub type CGDataProviderReleaseInfoCallback = Option<unsafe extern "C" fn(*mut c_void)>;
pub type CGDataProviderRewindCallback = Option<unsafe extern "C" fn(*mut c_void)>;
pub type CGDataProviderSkipBytesCallback = Option<unsafe extern "C" fn(*mut c_void, size_t)>;
pub type CGDataProviderSkipForwardCallback =
Option<unsafe extern "C" fn(*mut c_void, off_t) -> off_t>;
pub type CGDataProviderGetBytePointerCallback = Option<unsafe extern fn (*mut c_void) -> *mut c_void>;
pub type CGDataProviderGetBytesAtOffsetCallback = Option<unsafe extern fn (*mut c_void, *mut c_void, size_t, size_t)>;
pub type CGDataProviderReleaseBytePointerCallback = Option<unsafe extern fn (*mut c_void, *const c_void)>;
pub type CGDataProviderReleaseDataCallback = Option<unsafe extern fn (*mut c_void, *const c_void, size_t)>;
pub type CGDataProviderGetBytesAtPositionCallback = Option<unsafe extern fn (*mut c_void, *mut c_void, off_t, size_t)>;
pub type CGDataProviderGetBytePointerCallback =
Option<unsafe extern "C" fn(*mut c_void) -> *mut c_void>;
pub type CGDataProviderGetBytesAtOffsetCallback =
Option<unsafe extern "C" fn(*mut c_void, *mut c_void, size_t, size_t)>;
pub type CGDataProviderReleaseBytePointerCallback =
Option<unsafe extern "C" fn(*mut c_void, *const c_void)>;
pub type CGDataProviderReleaseDataCallback =
Option<unsafe extern "C" fn(*mut c_void, *const c_void, size_t)>;
pub type CGDataProviderGetBytesAtPositionCallback =
Option<unsafe extern "C" fn(*mut c_void, *mut c_void, off_t, size_t)>;
foreign_type! {
#[doc(hidden)]
@@ -41,9 +48,7 @@ foreign_type! {
impl CGDataProvider {
pub fn type_id() -> CFTypeID {
unsafe {
CGDataProviderGetTypeID()
}
unsafe { CGDataProviderGetTypeID() }
}
/// Creates a data provider from the given reference-counted buffer.
@@ -84,7 +89,9 @@ impl CGDataProvider {
return CGDataProvider::from_ptr(data_provider);
unsafe extern "C" fn release(info: *mut c_void, _: *const c_void, _: size_t) {
drop(mem::transmute::<*mut c_void, Box<Box<dyn CustomData>>>(info))
drop(mem::transmute::<*mut c_void, Box<Box<dyn CustomData>>>(
info,
))
}
}
}
@@ -134,7 +141,10 @@ fn test_data_provider() {
}
let dropped = Arc::new(AtomicBool::default());
let l = Arc::new(VecWrapper {inner: vec![5], dropped: dropped.clone() });
let l = Arc::new(VecWrapper {
inner: vec![5],
dropped: dropped.clone(),
});
let m = l.clone();
let dp = CGDataProvider::from_buffer(l);
drop(m);
@@ -144,16 +154,17 @@ fn test_data_provider() {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
fn CGDataProviderCopyData(provider: ::sys::CGDataProviderRef) -> CFDataRef;
//fn CGDataProviderCreateDirect
//fn CGDataProviderCreateSequential
//fn CGDataProviderCreateWithCFData
fn CGDataProviderCreateWithData(info: *mut c_void,
data: *const c_void,
size: size_t,
releaseData: CGDataProviderReleaseDataCallback
) -> ::sys::CGDataProviderRef;
fn CGDataProviderCreateWithData(
info: *mut c_void,
data: *const c_void,
size: size_t,
releaseData: CGDataProviderReleaseDataCallback,
) -> ::sys::CGDataProviderRef;
//fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef;
//fn CGDataProviderCreateWithURL
fn CGDataProviderGetTypeID() -> CFTypeID;
+51 -49
View File
@@ -10,19 +10,19 @@
#![allow(non_upper_case_globals)]
use libc;
use std::ptr;
use std::ops::Deref;
use std::ptr;
pub use base::{CGError, boolean_t};
pub use geometry::{CGRect, CGPoint, CGSize};
pub use base::{boolean_t, CGError};
pub use geometry::{CGPoint, CGRect, CGSize};
use core_foundation::string::{CFString, CFStringRef};
use core_foundation::base::{CFRetain, TCFType};
use image::CGImage;
use core_foundation::string::{CFString, CFStringRef};
use foreign_types::ForeignType;
use image::CGImage;
pub type CGDirectDisplayID = u32;
pub type CGWindowID = u32;
pub type CGWindowID = u32;
pub type CGWindowLevel = i32;
pub const kCGNullWindowID: CGWindowID = 0 as CGWindowID;
@@ -30,12 +30,12 @@ pub const kCGNullDirectDisplayID: CGDirectDisplayID = 0 as CGDirectDisplayID;
pub type CGWindowListOption = u32;
pub const kCGWindowListOptionAll: CGWindowListOption = 0;
pub const kCGWindowListOptionOnScreenOnly: CGWindowListOption = 1 << 0;
pub const kCGWindowListOptionAll: CGWindowListOption = 0;
pub const kCGWindowListOptionOnScreenOnly: CGWindowListOption = 1 << 0;
pub const kCGWindowListOptionOnScreenAboveWindow: CGWindowListOption = 1 << 1;
pub const kCGWindowListOptionOnScreenBelowWindow: CGWindowListOption = 1 << 2;
pub const kCGWindowListOptionIncludingWindow: CGWindowListOption = 1 << 3;
pub const kCGWindowListExcludeDesktopElements: CGWindowListOption = 1 << 4;
pub const kCGWindowListOptionIncludingWindow: CGWindowListOption = 1 << 3;
pub const kCGWindowListExcludeDesktopElements: CGWindowListOption = 1 << 4;
pub type CGWindowImageOption = u32;
@@ -46,28 +46,28 @@ pub const kCGWindowImageOnlyShadows: CGWindowImageOption = 1 << 2;
pub const kCGWindowImageBestResolution: CGWindowImageOption = 1 << 3;
pub const kCGWindowImageNominalResolution: CGWindowImageOption = 1 << 4;
pub const kDisplayModeValidFlag: u32 = 0x00000001;
pub const kDisplayModeSafeFlag: u32 = 0x00000002;
pub const kDisplayModeDefaultFlag: u32 = 0x00000004;
pub const kDisplayModeAlwaysShowFlag: u32 = 0x00000008;
pub const kDisplayModeNeverShowFlag: u32 = 0x00000080;
pub const kDisplayModeNotResizeFlag: u32 = 0x00000010;
pub const kDisplayModeRequiresPanFlag: u32 = 0x00000020;
pub const kDisplayModeInterlacedFlag: u32 = 0x00000040;
pub const kDisplayModeSimulscanFlag: u32 = 0x00000100;
pub const kDisplayModeBuiltInFlag: u32 = 0x00000400;
pub const kDisplayModeNotPresetFlag: u32 = 0x00000200;
pub const kDisplayModeStretchedFlag: u32 = 0x00000800;
pub const kDisplayModeNotGraphicsQualityFlag: u32 = 0x00001000;
pub const kDisplayModeValidateAgainstDisplay: u32 = 0x00002000;
pub const kDisplayModeTelevisionFlag: u32 = 0x00100000;
pub const kDisplayModeValidForMirroringFlag: u32 = 0x00200000;
pub const kDisplayModeAcceleratorBackedFlag: u32 = 0x00400000;
pub const kDisplayModeValidForHiResFlag: u32 = 0x00800000;
pub const kDisplayModeValidForAirPlayFlag: u32 = 0x01000000;
pub const kDisplayModeNativeFlag: u32 = 0x02000000;
pub const kDisplayModeValidFlag: u32 = 0x00000001;
pub const kDisplayModeSafeFlag: u32 = 0x00000002;
pub const kDisplayModeDefaultFlag: u32 = 0x00000004;
pub const kDisplayModeAlwaysShowFlag: u32 = 0x00000008;
pub const kDisplayModeNeverShowFlag: u32 = 0x00000080;
pub const kDisplayModeNotResizeFlag: u32 = 0x00000010;
pub const kDisplayModeRequiresPanFlag: u32 = 0x00000020;
pub const kDisplayModeInterlacedFlag: u32 = 0x00000040;
pub const kDisplayModeSimulscanFlag: u32 = 0x00000100;
pub const kDisplayModeBuiltInFlag: u32 = 0x00000400;
pub const kDisplayModeNotPresetFlag: u32 = 0x00000200;
pub const kDisplayModeStretchedFlag: u32 = 0x00000800;
pub const kDisplayModeNotGraphicsQualityFlag: u32 = 0x00001000;
pub const kDisplayModeValidateAgainstDisplay: u32 = 0x00002000;
pub const kDisplayModeTelevisionFlag: u32 = 0x00100000;
pub const kDisplayModeValidForMirroringFlag: u32 = 0x00200000;
pub const kDisplayModeAcceleratorBackedFlag: u32 = 0x00400000;
pub const kDisplayModeValidForHiResFlag: u32 = 0x00800000;
pub const kDisplayModeValidForAirPlayFlag: u32 = 0x01000000;
pub const kDisplayModeNativeFlag: u32 = 0x02000000;
pub const kDisplayModeSafetyFlags: u32 = 0x00000007;
pub const kDisplayModeSafetyFlags: u32 = 0x00000007;
pub type CGDisplayBlendFraction = f32;
pub const kCGDisplayBlendNormal: CGDisplayBlendFraction = 0.0;
@@ -80,24 +80,25 @@ pub type CGDisplayFadeInterval = f32;
pub type CGDisplayReservationInterval = f32;
pub const kCGMaxDisplayReservationInterval: CGDisplayReservationInterval = 15.0;
pub const IO1BitIndexedPixels: &str = "P";
pub const IO2BitIndexedPixels: &str = "PP";
pub const IO4BitIndexedPixels: &str = "PPPP";
pub const IO8BitIndexedPixels: &str = "PPPPPPPP";
pub const IO16BitDirectPixels: &str = "-RRRRRGGGGGBBBBB";
pub const IO32BitDirectPixels: &str = "--------RRRRRRRRGGGGGGGGBBBBBBBB";
pub const kIO30BitDirectPixels: &str = "--RRRRRRRRRRGGGGGGGGGGBBBBBBBBBB";
pub const kIO64BitDirectPixels: &str = "-16R16G16B16";
pub const kIO16BitFloatPixels: &str = "-16FR16FG16FB16";
pub const kIO32BitFloatPixels: &str = "-32FR32FG32FB32";
pub const IOYUV422Pixels: &str = "Y4U2V2";
pub const IO8BitOverlayPixels: &str = "O8";
pub const IO1BitIndexedPixels: &str = "P";
pub const IO2BitIndexedPixels: &str = "PP";
pub const IO4BitIndexedPixels: &str = "PPPP";
pub const IO8BitIndexedPixels: &str = "PPPPPPPP";
pub const IO16BitDirectPixels: &str = "-RRRRRGGGGGBBBBB";
pub const IO32BitDirectPixels: &str = "--------RRRRRRRRGGGGGGGGBBBBBBBB";
pub const kIO30BitDirectPixels: &str = "--RRRRRRRRRRGGGGGGGGGGBBBBBBBBBB";
pub const kIO64BitDirectPixels: &str = "-16R16G16B16";
pub const kIO16BitFloatPixels: &str = "-16FR16FG16FB16";
pub const kIO32BitFloatPixels: &str = "-32FR32FG32FB32";
pub const IOYUV422Pixels: &str = "Y4U2V2";
pub const IO8BitOverlayPixels: &str = "O8";
pub use core_foundation::dictionary::{ CFDictionary, CFDictionaryRef, CFDictionaryGetValueIfPresent };
pub use core_foundation::array::{ CFArray, CFArrayRef };
pub use core_foundation::array::{ CFArrayGetCount, CFArrayGetValueAtIndex };
pub use core_foundation::base::{ CFIndex, CFRelease, CFTypeRef };
pub use core_foundation::array::{CFArray, CFArrayRef};
pub use core_foundation::array::{CFArrayGetCount, CFArrayGetValueAtIndex};
pub use core_foundation::base::{CFIndex, CFRelease, CFTypeRef};
pub use core_foundation::dictionary::{
CFDictionary, CFDictionaryGetValueIfPresent, CFDictionaryRef,
};
pub type CGDisplayConfigRef = *mut libc::c_void;
@@ -562,7 +563,8 @@ impl CGDisplayMode {
.map(|value0| {
let x = *value0.deref() as *mut ::sys::CGDisplayMode;
unsafe { CGDisplayMode::from_ptr(x) }
}).collect();
})
.collect();
Some(vec)
}
None => None,
+28 -22
View File
@@ -439,7 +439,6 @@ unsafe extern "C" fn cg_event_tap_callback_internal(
ManuallyDrop::new(event).as_ptr()
}
/// ```no_run
///extern crate core_foundation;
///use core_foundation::runloop::{kCFRunLoopCommonModes, CFRunLoop};
@@ -526,9 +525,7 @@ foreign_type! {
impl CGEvent {
pub fn type_id() -> CFTypeID {
unsafe {
CGEventGetTypeID()
}
unsafe { CGEventGetTypeID() }
}
pub fn new(source: CGEventSource) -> Result<CGEvent, ()> {
@@ -545,7 +542,7 @@ impl CGEvent {
pub fn new_keyboard_event(
source: CGEventSource,
keycode: CGKeyCode,
keydown: bool
keydown: bool,
) -> Result<CGEvent, ()> {
unsafe {
let event_ref = CGEventCreateKeyboardEvent(source.as_ptr(), keycode, keydown);
@@ -561,11 +558,15 @@ impl CGEvent {
source: CGEventSource,
mouse_type: CGEventType,
mouse_cursor_position: CGPoint,
mouse_button: CGMouseButton
mouse_button: CGMouseButton,
) -> Result<CGEvent, ()> {
unsafe {
let event_ref = CGEventCreateMouseEvent(source.as_ptr(), mouse_type,
mouse_cursor_position, mouse_button);
let event_ref = CGEventCreateMouseEvent(
source.as_ptr(),
mouse_type,
mouse_cursor_position,
mouse_button,
);
if !event_ref.is_null() {
Ok(Self::from_ptr(event_ref))
} else {
@@ -630,9 +631,7 @@ impl CGEvent {
}
pub fn get_flags(&self) -> CGEventFlags {
unsafe {
CGEventGetFlags(self.as_ptr())
}
unsafe { CGEventGetFlags(self.as_ptr()) }
}
pub fn set_type(&self, event_type: CGEventType) {
@@ -642,9 +641,7 @@ impl CGEvent {
}
pub fn get_type(&self) -> CGEventType {
unsafe {
CGEventGetType(self.as_ptr())
}
unsafe { CGEventGetType(self.as_ptr()) }
}
pub fn set_string_from_utf16_unchecked(&self, buf: &[u16]) {
@@ -677,7 +674,7 @@ impl CGEvent {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
/// Return the type identifier for the opaque type `CGEventRef'.
fn CGEventGetTypeID() -> CFTypeID;
@@ -695,8 +692,11 @@ extern {
/// SHIFT, CONTROL, OPTION, and COMMAND keys. For example, to produce a 'Z',
/// the SHIFT key must be down, the 'z' key must go down, and then the SHIFT
/// and 'z' key must be released:
fn CGEventCreateKeyboardEvent(source: ::sys::CGEventSourceRef, keycode: CGKeyCode,
keydown: bool) -> ::sys::CGEventRef;
fn CGEventCreateKeyboardEvent(
source: ::sys::CGEventSourceRef,
keycode: CGKeyCode,
keydown: bool,
) -> ::sys::CGEventRef;
/// Return a new mouse event.
///
@@ -711,8 +711,12 @@ extern {
/// thirty-two buttons. Mouse button 0 is the primary button on the mouse.
/// Mouse button 1 is the secondary mouse button (right). Mouse button 2 is
/// the center button, and the remaining buttons are in USB device order.
fn CGEventCreateMouseEvent(source: ::sys::CGEventSourceRef, mouseType: CGEventType,
mouseCursorPosition: CGPoint, mouseButton: CGMouseButton) -> ::sys::CGEventRef;
fn CGEventCreateMouseEvent(
source: ::sys::CGEventSourceRef,
mouseType: CGEventType,
mouseCursorPosition: CGPoint,
mouseButton: CGMouseButton,
) -> ::sys::CGEventRef;
/// A non-variadic variant version of CGEventCreateScrollWheelEvent.
///
@@ -767,9 +771,11 @@ extern {
/// Note that application frameworks may ignore the Unicode string in a
/// keyboard event and do their own translation based on the virtual
/// keycode and perceived event state.
fn CGEventKeyboardSetUnicodeString(event: ::sys::CGEventRef,
length: libc::c_ulong,
string: *const u16);
fn CGEventKeyboardSetUnicodeString(
event: ::sys::CGEventRef,
length: libc::c_ulong,
string: *const u16,
);
/// Return the integer value of a field in an event.
fn CGEventGetIntegerValueField(event: ::sys::CGEventRef, field: CGEventField) -> i64;
+2 -4
View File
@@ -21,9 +21,7 @@ foreign_type! {
impl CGEventSource {
pub fn type_id() -> CFTypeID {
unsafe {
CGEventSourceGetTypeID()
}
unsafe { CGEventSourceGetTypeID() }
}
pub fn new(state_id: CGEventSourceStateID) -> Result<Self, ()> {
@@ -39,7 +37,7 @@ impl CGEventSource {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
/// Return the type identifier for the opaque type `CGEventSourceRef'.
fn CGEventSourceGetTypeID() -> CFTypeID;
+40 -34
View File
@@ -7,12 +7,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core_foundation::base::{CFRelease, CFRetain, CFType, CFTypeID, TCFType};
use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{CFRelease, CFRetain, CFType, CFTypeID, TCFType};
use core_foundation::data::{CFData, CFDataRef};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use core_foundation::number::CFNumber;
use core_foundation::string::{CFString, CFStringRef};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use data_provider::CGDataProvider;
use geometry::CGRect;
use std::ptr::NonNull;
@@ -34,9 +34,7 @@ foreign_type! {
impl CGFont {
pub fn type_id() -> CFTypeID {
unsafe {
CGFontGetTypeID()
}
unsafe { CGFontGetTypeID() }
}
pub fn from_data_provider(provider: CGDataProvider) -> Result<CGFont, ()> {
@@ -59,10 +57,13 @@ impl CGFont {
}
}
pub fn create_copy_from_variations(&self, vars: &CFDictionary<CFString, CFNumber>) -> Result<CGFont, ()> {
pub fn create_copy_from_variations(
&self,
vars: &CFDictionary<CFString, CFNumber>,
) -> Result<CGFont, ()> {
unsafe {
let font_ref = CGFontCreateCopyWithVariations(self.as_ptr(),
vars.as_concrete_TypeRef());
let font_ref =
CGFontCreateCopyWithVariations(self.as_ptr(), vars.as_concrete_TypeRef());
match NonNull::new(font_ref) {
Some(font_ref) => Ok(CGFont(font_ref)),
None => Err(()),
@@ -80,33 +81,33 @@ impl CGFont {
pub fn get_glyph_b_boxes(&self, glyphs: &[CGGlyph], bboxes: &mut [CGRect]) -> bool {
unsafe {
assert!(bboxes.len() >= glyphs.len());
CGFontGetGlyphBBoxes(self.as_ptr(),
glyphs.as_ptr(),
glyphs.len(),
bboxes.as_mut_ptr())
CGFontGetGlyphBBoxes(
self.as_ptr(),
glyphs.as_ptr(),
glyphs.len(),
bboxes.as_mut_ptr(),
)
}
}
pub fn get_glyph_advances(&self, glyphs: &[CGGlyph], advances: &mut [c_int]) -> bool {
unsafe {
assert!(advances.len() >= glyphs.len());
CGFontGetGlyphAdvances(self.as_ptr(),
glyphs.as_ptr(),
glyphs.len(),
advances.as_mut_ptr())
CGFontGetGlyphAdvances(
self.as_ptr(),
glyphs.as_ptr(),
glyphs.len(),
advances.as_mut_ptr(),
)
}
}
pub fn get_units_per_em(&self) -> c_int {
unsafe {
CGFontGetUnitsPerEm(self.as_ptr())
}
unsafe { CGFontGetUnitsPerEm(self.as_ptr()) }
}
pub fn copy_table_tags(&self) -> CFArray<u32> {
unsafe {
TCFType::wrap_under_create_rule(CGFontCopyTableTags(self.as_ptr()))
}
unsafe { TCFType::wrap_under_create_rule(CGFontCopyTableTags(self.as_ptr())) }
}
pub fn copy_table_for_tag(&self, tag: u32) -> Option<CFData> {
@@ -138,11 +139,14 @@ impl CGFont {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
// TODO: basically nothing has bindings (even commented-out) besides what we use.
fn CGFontCreateWithDataProvider(provider: ::sys::CGDataProviderRef) -> ::sys::CGFontRef;
fn CGFontCreateWithFontName(name: CFStringRef) -> ::sys::CGFontRef;
fn CGFontCreateCopyWithVariations(font: ::sys::CGFontRef, vars: CFDictionaryRef) -> ::sys::CGFontRef;
fn CGFontCreateCopyWithVariations(
font: ::sys::CGFontRef,
vars: CFDictionaryRef,
) -> ::sys::CGFontRef;
fn CGFontGetTypeID() -> CFTypeID;
fn CGFontCopyPostScriptName(font: ::sys::CGFontRef) -> CFStringRef;
@@ -152,16 +156,18 @@ extern {
//fn CGFontRetain(font: ::sys::CGFontRef);
//fn CGFontRelease(font: ::sys::CGFontRef);
fn CGFontGetGlyphBBoxes(font: ::sys::CGFontRef,
glyphs: *const CGGlyph,
count: size_t,
bboxes: *mut CGRect)
-> bool;
fn CGFontGetGlyphAdvances(font: ::sys::CGFontRef,
glyphs: *const CGGlyph,
count: size_t,
advances: *mut c_int)
-> bool;
fn CGFontGetGlyphBBoxes(
font: ::sys::CGFontRef,
glyphs: *const CGGlyph,
count: size_t,
bboxes: *mut CGRect,
) -> bool;
fn CGFontGetGlyphAdvances(
font: ::sys::CGFontRef,
glyphs: *const CGGlyph,
count: size_t,
advances: *mut c_int,
) -> bool;
fn CGFontGetUnitsPerEm(font: ::sys::CGFontRef) -> c_int;
fn CGFontCopyTableTags(font: ::sys::CGFontRef) -> CFArrayRef;
+1 -1
View File
@@ -7,4 +7,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use core_graphics_types::geometry::*;
pub use core_graphics_types::geometry::*;
+35 -9
View File
@@ -13,7 +13,7 @@ use base::CGFloat;
use color::CGColor;
use color_space::CGColorSpace;
use core_foundation::array::{ CFArray, CFArrayRef };
use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{CFRelease, CFRetain, TCFType};
use foreign_types::ForeignType;
@@ -37,17 +37,35 @@ foreign_type! {
}
impl CGGradient {
pub fn create_with_color_components(color_space: &CGColorSpace, components: &[CGFloat], locations: &[CGFloat], count: usize) -> CGGradient {
pub fn create_with_color_components(
color_space: &CGColorSpace,
components: &[CGFloat],
locations: &[CGFloat],
count: usize,
) -> CGGradient {
unsafe {
let result = CGGradientCreateWithColorComponents(color_space.as_ptr(), components.as_ptr(), locations.as_ptr(), count);
let result = CGGradientCreateWithColorComponents(
color_space.as_ptr(),
components.as_ptr(),
locations.as_ptr(),
count,
);
assert!(!result.is_null());
Self::from_ptr(result)
}
}
pub fn create_with_colors(color_space: &CGColorSpace, colors: &CFArray<CGColor>, locations: &[CGFloat]) -> CGGradient {
pub fn create_with_colors(
color_space: &CGColorSpace,
colors: &CFArray<CGColor>,
locations: &[CGFloat],
) -> CGGradient {
unsafe {
let result = CGGradientCreateWithColors(color_space.as_ptr(), colors.as_concrete_TypeRef(), locations.as_ptr());
let result = CGGradientCreateWithColors(
color_space.as_ptr(),
colors.as_concrete_TypeRef(),
locations.as_ptr(),
);
assert!(!result.is_null());
Self::from_ptr(result)
}
@@ -55,8 +73,16 @@ impl CGGradient {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
fn CGGradientCreateWithColorComponents(color_space: ::sys::CGColorSpaceRef, components: *const CGFloat, locations: *const CGFloat, count: size_t) -> ::sys::CGGradientRef;
fn CGGradientCreateWithColors(color_space: ::sys::CGColorSpaceRef, colors: CFArrayRef, locations: *const CGFloat) -> ::sys::CGGradientRef;
extern "C" {
fn CGGradientCreateWithColorComponents(
color_space: ::sys::CGColorSpaceRef,
components: *const CGFloat,
locations: *const CGFloat,
count: size_t,
) -> ::sys::CGGradientRef;
fn CGGradientCreateWithColors(
color_space: ::sys::CGColorSpaceRef,
colors: CFArrayRef,
locations: *const CGFloat,
) -> ::sys::CGGradientRef;
}
+58 -67
View File
@@ -1,24 +1,24 @@
use std::ptr;
use base::CGFloat;
use color_space::CGColorSpace;
use core_foundation::base::{CFRetain, CFTypeID};
use core_foundation::data::CFData;
use color_space::CGColorSpace;
use data_provider::{CGDataProviderRef, CGDataProvider};
use data_provider::{CGDataProvider, CGDataProviderRef};
use foreign_types::{ForeignType, ForeignTypeRef};
use geometry::CGRect;
use libc::size_t;
use foreign_types::{ForeignType, ForeignTypeRef};
#[repr(C)]
pub enum CGImageAlphaInfo {
CGImageAlphaNone, /* For example, RGB. */
CGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */
CGImageAlphaNone, /* For example, RGB. */
CGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */
CGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */
CGImageAlphaLast, /* For example, non-premultiplied RGBA */
CGImageAlphaFirst, /* For example, non-premultiplied ARGB */
CGImageAlphaNoneSkipLast, /* For example, RBGX. */
CGImageAlphaNoneSkipFirst, /* For example, XRBG. */
CGImageAlphaOnly /* No color data, alpha data only */
CGImageAlphaLast, /* For example, non-premultiplied RGBA */
CGImageAlphaFirst, /* For example, non-premultiplied ARGB */
CGImageAlphaNoneSkipLast, /* For example, RBGX. */
CGImageAlphaNoneSkipFirst, /* For example, XRBG. */
CGImageAlphaOnly, /* No color data, alpha data only */
}
#[repr(C)]
@@ -27,7 +27,7 @@ pub enum CGImageByteOrderInfo {
CGImageByteOrder16Little = 1 << 12,
CGImageByteOrder32Little = 2 << 12,
CGImageByteOrder16Big = 3 << 12,
CGImageByteOrder32Big = 4 << 12
CGImageByteOrder32Big = 4 << 12,
}
foreign_type! {
@@ -40,70 +40,61 @@ foreign_type! {
}
impl CGImage {
pub fn new(width: size_t,
height: size_t,
bits_per_component: size_t,
bits_per_pixel: size_t,
bytes_per_row: size_t,
colorspace: &CGColorSpace,
bitmap_info: u32,
provider: &CGDataProvider,
should_interpolate: bool,
rendering_intent: u32)
-> Self {
pub fn new(
width: size_t,
height: size_t,
bits_per_component: size_t,
bits_per_pixel: size_t,
bytes_per_row: size_t,
colorspace: &CGColorSpace,
bitmap_info: u32,
provider: &CGDataProvider,
should_interpolate: bool,
rendering_intent: u32,
) -> Self {
unsafe {
let result = CGImageCreate(width,
height,
bits_per_component,
bits_per_pixel,
bytes_per_row,
colorspace.as_ptr(),
bitmap_info,
provider.as_ptr(),
ptr::null_mut(),
should_interpolate,
rendering_intent);
let result = CGImageCreate(
width,
height,
bits_per_component,
bits_per_pixel,
bytes_per_row,
colorspace.as_ptr(),
bitmap_info,
provider.as_ptr(),
ptr::null_mut(),
should_interpolate,
rendering_intent,
);
assert!(!result.is_null());
Self::from_ptr(result)
}
}
pub fn type_id() -> CFTypeID {
unsafe {
CGImageGetTypeID()
}
unsafe { CGImageGetTypeID() }
}
}
impl CGImageRef {
pub fn width(&self) -> size_t {
unsafe {
CGImageGetWidth(self.as_ptr())
}
unsafe { CGImageGetWidth(self.as_ptr()) }
}
pub fn height(&self) -> size_t {
unsafe {
CGImageGetHeight(self.as_ptr())
}
unsafe { CGImageGetHeight(self.as_ptr()) }
}
pub fn bits_per_component(&self) -> size_t {
unsafe {
CGImageGetBitsPerComponent(self.as_ptr())
}
unsafe { CGImageGetBitsPerComponent(self.as_ptr()) }
}
pub fn bits_per_pixel(&self) -> size_t {
unsafe {
CGImageGetBitsPerPixel(self.as_ptr())
}
unsafe { CGImageGetBitsPerPixel(self.as_ptr()) }
}
pub fn bytes_per_row(&self) -> size_t {
unsafe {
CGImageGetBytesPerRow(self.as_ptr())
}
unsafe { CGImageGetBytesPerRow(self.as_ptr()) }
}
pub fn color_space(&self) -> CGColorSpace {
@@ -117,9 +108,8 @@ impl CGImageRef {
/// Returns the raw image bytes wrapped in `CFData`. Note, the returned `CFData` owns the
/// underlying buffer.
pub fn data(&self) -> CFData {
let data_provider = unsafe {
CGDataProviderRef::from_ptr(CGImageGetDataProvider(self.as_ptr()))
};
let data_provider =
unsafe { CGDataProviderRef::from_ptr(CGImageGetDataProvider(self.as_ptr())) };
data_provider.copy_data()
}
@@ -136,7 +126,7 @@ impl CGImageRef {
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
fn CGImageGetTypeID() -> CFTypeID;
fn CGImageGetWidth(image: ::sys::CGImageRef) -> size_t;
fn CGImageGetHeight(image: ::sys::CGImageRef) -> size_t;
@@ -146,18 +136,19 @@ extern {
fn CGImageGetColorSpace(image: ::sys::CGImageRef) -> ::sys::CGColorSpaceRef;
fn CGImageGetDataProvider(image: ::sys::CGImageRef) -> ::sys::CGDataProviderRef;
fn CGImageRelease(image: ::sys::CGImageRef);
fn CGImageCreate(width: size_t,
height: size_t,
bitsPerComponent: size_t,
bitsPerPixel: size_t,
bytesPerRow: size_t,
space: ::sys::CGColorSpaceRef,
bitmapInfo: u32,
provider: ::sys::CGDataProviderRef,
decode: *const CGFloat,
shouldInterpolate: bool,
intent: u32)
-> ::sys::CGImageRef;
fn CGImageCreate(
width: size_t,
height: size_t,
bitsPerComponent: size_t,
bitsPerPixel: size_t,
bytesPerRow: size_t,
space: ::sys::CGColorSpaceRef,
bitmapInfo: u32,
provider: ::sys::CGDataProviderRef,
decode: *const CGFloat,
shouldInterpolate: bool,
intent: u32,
) -> ::sys::CGImageRef;
fn CGImageCreateWithImageInRect(image: ::sys::CGImageRef, rect: CGRect) -> ::sys::CGImageRef;
//fn CGImageGetAlphaInfo(image: ::sys::CGImageRef) -> CGImageAlphaInfo;
+5 -5
View File
@@ -20,6 +20,8 @@ extern crate foreign_types;
extern crate core_graphics_types;
#[cfg(target_os = "macos")]
pub mod access;
pub mod base;
pub mod color;
pub mod color_space;
@@ -34,12 +36,10 @@ pub mod event_source;
pub mod font;
pub mod geometry;
pub mod gradient;
#[cfg(target_os = "macos")]
pub mod window;
#[cfg(target_os = "macos")]
pub mod private;
pub mod image;
pub mod path;
#[cfg(target_os = "macos")]
pub mod private;
pub mod sys;
#[cfg(target_os = "macos")]
pub mod access;
pub mod window;
+16 -12
View File
@@ -40,18 +40,25 @@ impl CGPath {
}
pub fn type_id() -> CFTypeID {
unsafe {
CGPathGetTypeID()
}
unsafe { CGPathGetTypeID() }
}
pub fn apply<'a, F>(&'a self, mut closure: &'a F) where F: FnMut(CGPathElementRef<'a>) {
pub fn apply<'a, F>(&'a self, mut closure: &'a F)
where
F: FnMut(CGPathElementRef<'a>),
{
unsafe {
CGPathApply(self.as_ptr(), &mut closure as *mut _ as *mut c_void, do_apply::<F>);
CGPathApply(
self.as_ptr(),
&mut closure as *mut _ as *mut c_void,
do_apply::<F>,
);
}
unsafe extern "C" fn do_apply<'a, F>(info: *mut c_void, element: *const CGPathElement)
where F: FnMut(CGPathElementRef<'a>) {
where
F: FnMut(CGPathElementRef<'a>),
{
let closure = info as *mut *mut F;
(**closure)(CGPathElementRef::new(element))
}
@@ -85,9 +92,7 @@ impl<'a> CGPathElementRef<'a> {
impl<'a> Deref for CGPathElementRef<'a> {
type Target = CGPathElement;
fn deref(&self) -> &CGPathElement {
unsafe {
&*self.element
}
unsafe { &*self.element }
}
}
@@ -118,11 +123,10 @@ impl CGPathElement {
}
}
type CGPathApplierFunction = unsafe extern "C" fn(info: *mut c_void,
element: *const CGPathElement);
type CGPathApplierFunction = unsafe extern "C" fn(info: *mut c_void, element: *const CGPathElement);
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
fn CGPathCreateWithRect(rect: CGRect, transform: *const CGAffineTransform) -> ::sys::CGPathRef;
fn CGPathApply(path: ::sys::CGPathRef, info: *mut c_void, function: CGPathApplierFunction);
fn CGPathGetTypeID() -> CFTypeID;
+27 -27
View File
@@ -21,9 +21,7 @@ pub struct CGSRegion {
impl Drop for CGSRegion {
fn drop(&mut self) {
unsafe {
ffi::CGSRegionRelease(self.region)
}
unsafe { ffi::CGSRegionRelease(self.region) }
}
}
@@ -33,9 +31,7 @@ impl CGSRegion {
unsafe {
let mut region = ptr::null_mut();
assert!(ffi::CGSNewRegionWithRect(rect, &mut region) == 0);
CGSRegion {
region: region,
}
CGSRegion { region: region }
}
}
@@ -43,12 +39,11 @@ impl CGSRegion {
pub fn from_rects(rects: &[CGRect]) -> CGSRegion {
unsafe {
let mut region = ptr::null_mut();
assert!(ffi::CGSNewRegionWithRectList(rects.as_ptr(),
rects.len() as c_uint,
&mut region) == 0);
CGSRegion {
region: region,
}
assert!(
ffi::CGSNewRegionWithRectList(rects.as_ptr(), rects.len() as c_uint, &mut region)
== 0
);
CGSRegion { region: region }
}
}
}
@@ -78,10 +73,14 @@ impl CGSSurface {
#[inline]
pub fn set_shape(&self, region: &CGSRegion) {
unsafe {
assert!(ffi::CGSSetSurfaceShape(self.context_id,
self.window_number,
self.surface_id,
region.region) == 0)
assert!(
ffi::CGSSetSurfaceShape(
self.context_id,
self.window_number,
self.surface_id,
region.region
) == 0
)
}
}
}
@@ -98,19 +97,20 @@ mod ffi {
pub type OSStatus = i32;
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
pub fn CGSRegionRelease(region: CGSRegionRef);
pub fn CGSNewRegionWithRect(rect: *const CGRect, outRegion: *mut CGSRegionRef) -> CGError;
pub fn CGSNewRegionWithRectList(rects: *const CGRect,
rectCount: c_uint,
outRegion: *mut CGSRegionRef)
-> CGError;
pub fn CGSNewRegionWithRectList(
rects: *const CGRect,
rectCount: c_uint,
outRegion: *mut CGSRegionRef,
) -> CGError;
pub fn CGSSetSurfaceShape(contextID: c_uint,
windowNumber: c_int,
surfaceID: c_uint,
region: CGSRegionRef)
-> CGError;
pub fn CGSSetSurfaceShape(
contextID: c_uint,
windowNumber: c_int,
surfaceID: c_uint,
region: CGSRegionRef,
) -> CGError;
}
}
+8 -8
View File
@@ -28,16 +28,16 @@ pub type CGGradientRef = *mut CGGradient;
#[cfg(target_os = "macos")]
mod macos {
pub enum CGEventTap {}
pub type CGEventTapRef = core_foundation::mach_port::CFMachPortRef;
pub enum CGEvent {}
pub type CGEventRef = *mut CGEvent;
pub enum CGEventTap {}
pub type CGEventTapRef = core_foundation::mach_port::CFMachPortRef;
pub enum CGEvent {}
pub type CGEventRef = *mut CGEvent;
pub enum CGEventSource {}
pub type CGEventSourceRef = *mut CGEventSource;
pub enum CGEventSource {}
pub type CGEventSourceRef = *mut CGEventSource;
pub enum CGDisplayMode {}
pub type CGDisplayModeRef = *mut CGDisplayMode;
pub enum CGDisplayMode {}
pub type CGDisplayModeRef = *mut CGDisplayMode;
}
#[cfg(target_os = "macos")]
+47 -32
View File
@@ -49,8 +49,10 @@ pub const kCGWindowImageNominalResolution: CGWindowImageOption = 1 << 4;
pub const kCGNullWindowID: CGWindowID = 0;
pub fn copy_window_info(option: CGWindowListOption, relative_to_window: CGWindowID)
-> Option<CFArray> {
pub fn copy_window_info(
option: CGWindowListOption,
relative_to_window: CGWindowID,
) -> Option<CFArray> {
unsafe {
let array = CGWindowListCopyWindowInfo(option, relative_to_window);
if array.is_null() {
@@ -61,8 +63,10 @@ pub fn copy_window_info(option: CGWindowListOption, relative_to_window: CGWindow
}
}
pub fn create_window_list(option: CGWindowListOption, relative_to_window: CGWindowID)
-> Option<CFArray<CGWindowID>> {
pub fn create_window_list(
option: CGWindowListOption,
relative_to_window: CGWindowID,
) -> Option<CFArray<CGWindowID>> {
unsafe {
let array = CGWindowListCreate(option, relative_to_window);
if array.is_null() {
@@ -73,8 +77,9 @@ pub fn create_window_list(option: CGWindowListOption, relative_to_window: CGWind
}
}
pub fn create_description_from_array(window_array: CFArray<CGWindowID>) ->
Option<CFArray<CFDictionary<CFString, CFType>>> {
pub fn create_description_from_array(
window_array: CFArray<CGWindowID>,
) -> Option<CFArray<CFDictionary<CFString, CFType>>> {
unsafe {
let array = CGWindowListCreateDescriptionFromArray(window_array.as_concrete_TypeRef());
if array.is_null() {
@@ -85,11 +90,12 @@ pub fn create_description_from_array(window_array: CFArray<CGWindowID>) ->
}
}
pub fn create_image(screen_bounds: CGRect,
list_option: CGWindowListOption,
window_id: CGWindowID,
image_option: CGWindowImageOption)
-> Option<CGImage> {
pub fn create_image(
screen_bounds: CGRect,
list_option: CGWindowListOption,
window_id: CGWindowID,
image_option: CGWindowImageOption,
) -> Option<CGImage> {
unsafe {
let image = CGWindowListCreateImage(screen_bounds, list_option, window_id, image_option);
if image.is_null() {
@@ -100,14 +106,17 @@ pub fn create_image(screen_bounds: CGRect,
}
}
pub fn create_image_from_array(screen_bounds: CGRect,
window_array: CFArray,
image_option: CGWindowImageOption)
-> Option<CGImage> {
pub fn create_image_from_array(
screen_bounds: CGRect,
window_array: CFArray,
image_option: CGWindowImageOption,
) -> Option<CGImage> {
unsafe {
let image = CGWindowListCreateImageFromArray(screen_bounds,
window_array.as_concrete_TypeRef(),
image_option);
let image = CGWindowListCreateImageFromArray(
screen_bounds,
window_array.as_concrete_TypeRef(),
image_option,
);
if image.is_null() {
None
} else {
@@ -117,7 +126,7 @@ pub fn create_image_from_array(screen_bounds: CGRect,
}
#[link(name = "CoreGraphics", kind = "framework")]
extern {
extern "C" {
pub static kCGWindowNumber: CFStringRef;
pub static kCGWindowStoreType: CFStringRef;
pub static kCGWindowLayer: CFStringRef;
@@ -132,18 +141,24 @@ extern {
pub static kCGWindowIsOnscreen: CFStringRef;
pub static kCGWindowBackingLocationVideoMemory: CFStringRef;
pub fn CGWindowListCopyWindowInfo(option: CGWindowListOption, relativeToWindow: CGWindowID)
-> CFArrayRef;
pub fn CGWindowListCreate(option: CGWindowListOption, relativeToWindow: CGWindowID)
-> CFArrayRef;
pub fn CGWindowListCopyWindowInfo(
option: CGWindowListOption,
relativeToWindow: CGWindowID,
) -> CFArrayRef;
pub fn CGWindowListCreate(
option: CGWindowListOption,
relativeToWindow: CGWindowID,
) -> CFArrayRef;
pub fn CGWindowListCreateDescriptionFromArray(windowArray: CFArrayRef) -> CFArrayRef;
pub fn CGWindowListCreateImage(screenBounds: CGRect,
listOption: CGWindowListOption,
windowID: CGWindowID,
imageOption: CGWindowImageOption)
-> *mut sys::CGImage;
pub fn CGWindowListCreateImageFromArray(screenBounds: CGRect,
windowArray: CFArrayRef,
imageOption: CGWindowImageOption)
-> *mut sys::CGImage;
pub fn CGWindowListCreateImage(
screenBounds: CGRect,
listOption: CGWindowListOption,
windowID: CGWindowID,
imageOption: CGWindowImageOption,
) -> *mut sys::CGImage;
pub fn CGWindowListCreateImageFromArray(
screenBounds: CGRect,
windowArray: CFArrayRef,
imageOption: CGWindowImageOption,
) -> *mut sys::CGImage;
}