Add cocoa-foundation crate
This should let gfx-metal-rust avoid depending on core-graphics
This commit is contained in:
+1
-1
@@ -1,2 +1,2 @@
|
||||
[workspace]
|
||||
members = ["core-foundation", "core-foundation-sys", "core-graphics", "core-text", "cocoa", "io-surface"]
|
||||
members = ["core-foundation", "core-foundation-sys", "core-graphics-types", "core-graphics", "core-text", "cocoa", "cocoa-foundation", "io-surface"]
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
*~
|
||||
build
|
||||
/target
|
||||
/Cargo.lock
|
||||
@@ -0,0 +1,3 @@
|
||||
os: osx
|
||||
|
||||
language: rust
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
[package]
|
||||
name = "cocoa-foundation"
|
||||
description = "Bindings to Cocoa Foundation for macOS"
|
||||
homepage = "https://github.com/servo/core-foundation-rs"
|
||||
repository = "https://github.com/servo/core-foundation-rs"
|
||||
version = "0.1.0"
|
||||
authors = ["The Servo Project Developers"]
|
||||
license = "MIT / Apache-2.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
default-target = "x86_64-apple-darwin"
|
||||
|
||||
[dependencies]
|
||||
block = "0.1"
|
||||
bitflags = "1.0"
|
||||
libc = "0.2"
|
||||
core-foundation = { path = "../core-foundation", version = "0.9" }
|
||||
core-graphics-types = { path = "../core-graphics-types", version = "0.1" }
|
||||
foreign-types = "0.3"
|
||||
objc = "0.2.3"
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use objc::runtime;
|
||||
|
||||
pub use objc::runtime::{BOOL, NO, YES};
|
||||
|
||||
pub type Class = *mut runtime::Class;
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type id = *mut runtime::Object;
|
||||
pub type SEL = runtime::Sel;
|
||||
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const nil: id = 0 as id;
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const Nil: Class = 0 as Class;
|
||||
|
||||
/// A convenience method to convert the name of a selector to the selector object.
|
||||
#[inline]
|
||||
pub fn selector(name: &str) -> SEL {
|
||||
runtime::Sel::register(name)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
extern crate block;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
extern crate core_foundation;
|
||||
extern crate core_graphics_types;
|
||||
extern crate foreign_types;
|
||||
extern crate libc;
|
||||
#[macro_use]
|
||||
extern crate objc;
|
||||
|
||||
pub mod base;
|
||||
pub mod foundation;
|
||||
@@ -1,13 +1,13 @@
|
||||
#[macro_use]
|
||||
extern crate objc;
|
||||
extern crate block;
|
||||
extern crate cocoa;
|
||||
extern crate cocoa_foundation;
|
||||
|
||||
#[cfg(test)]
|
||||
mod foundation {
|
||||
mod nsstring {
|
||||
use cocoa::foundation::NSString;
|
||||
use cocoa::base::nil;
|
||||
use cocoa_foundation::foundation::NSString;
|
||||
use cocoa_foundation::base::nil;
|
||||
use std::slice;
|
||||
use std::str;
|
||||
|
||||
@@ -66,8 +66,8 @@ mod foundation {
|
||||
mod nsfastenumeration {
|
||||
use std::str;
|
||||
use std::slice;
|
||||
use cocoa::foundation::{NSString, NSFastEnumeration};
|
||||
use cocoa::base::{id, nil};
|
||||
use cocoa_foundation::foundation::{NSString, NSFastEnumeration};
|
||||
use cocoa_foundation::base::{id, nil};
|
||||
|
||||
#[test]
|
||||
fn test_iter() {
|
||||
@@ -108,9 +108,9 @@ mod foundation {
|
||||
|
||||
mod nsdictionary {
|
||||
use block::ConcreteBlock;
|
||||
use cocoa::foundation::{NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration,
|
||||
use cocoa_foundation::foundation::{NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration,
|
||||
NSString};
|
||||
use cocoa::base::{id, nil};
|
||||
use cocoa_foundation::base::{id, nil};
|
||||
|
||||
#[test]
|
||||
fn test_get() {
|
||||
@@ -15,6 +15,7 @@ default-target = "x86_64-apple-darwin"
|
||||
block = "0.1"
|
||||
bitflags = "1.0"
|
||||
libc = "0.2"
|
||||
cocoa-foundation = { path = "../cocoa-foundation", version = "0.1" }
|
||||
core-foundation = { path = "../core-foundation", version = "0.9" }
|
||||
core-graphics = { path = "../core-graphics", version = "0.21" }
|
||||
foreign-types = "0.3"
|
||||
|
||||
+1
-18
@@ -7,22 +7,5 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use objc::runtime;
|
||||
|
||||
pub use objc::runtime::{BOOL, NO, YES};
|
||||
|
||||
pub type Class = *mut runtime::Class;
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type id = *mut runtime::Object;
|
||||
pub type SEL = runtime::Sel;
|
||||
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const nil: id = 0 as id;
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const Nil: Class = 0 as Class;
|
||||
|
||||
/// A convenience method to convert the name of a selector to the selector object.
|
||||
#[inline]
|
||||
pub fn selector(name: &str) -> SEL {
|
||||
runtime::Sel::register(name)
|
||||
}
|
||||
pub use cocoa_foundation::base::*;
|
||||
|
||||
+1
-1367
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@ extern crate block;
|
||||
extern crate bitflags;
|
||||
extern crate core_foundation;
|
||||
extern crate core_graphics;
|
||||
extern crate cocoa_foundation;
|
||||
extern crate foreign_types;
|
||||
extern crate libc;
|
||||
#[macro_use]
|
||||
|
||||
@@ -15,5 +15,6 @@ highsierra = []
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
||||
core-foundation = { path = "../core-foundation", version = "0.9" }
|
||||
core-graphics-types = { path = "../core-graphics-types", version = "0.1" }
|
||||
foreign-types = "0.3.0"
|
||||
libc = "0.2"
|
||||
|
||||
@@ -12,21 +12,7 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
use libc;
|
||||
|
||||
#[cfg(any(target_arch = "x86",
|
||||
target_arch = "arm",
|
||||
target_arch = "aarch64"))]
|
||||
pub type boolean_t = libc::c_int;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub type boolean_t = libc::c_uint;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub type CGFloat = libc::c_double;
|
||||
#[cfg(not(target_pointer_width = "64"))]
|
||||
pub type CGFloat = libc::c_float;
|
||||
|
||||
pub type CGError = i32;
|
||||
pub use core_graphics_types::base::*;
|
||||
|
||||
pub const kCGImageAlphaNone: u32 = 0;
|
||||
pub const kCGImageAlphaPremultipliedLast: u32 = 1;
|
||||
|
||||
@@ -18,9 +18,9 @@ use geometry::CGRect;
|
||||
|
||||
use foreign_types::ForeignType;
|
||||
|
||||
use libc::{self, c_int, size_t};
|
||||
use libc::{c_int, size_t};
|
||||
|
||||
pub type CGGlyph = libc::c_ushort;
|
||||
pub use core_graphics_types::base::CGGlyph;
|
||||
|
||||
foreign_type! {
|
||||
#[doc(hidden)]
|
||||
|
||||
@@ -7,269 +7,4 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use base::CGFloat;
|
||||
use core_foundation::base::TCFType;
|
||||
use core_foundation::dictionary::CFDictionary;
|
||||
|
||||
pub const CG_ZERO_POINT: CGPoint = CGPoint {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
};
|
||||
|
||||
pub const CG_ZERO_SIZE: CGSize = CGSize {
|
||||
width: 0.0,
|
||||
height: 0.0,
|
||||
};
|
||||
|
||||
pub const CG_ZERO_RECT: CGRect = CGRect {
|
||||
origin: CG_ZERO_POINT,
|
||||
size: CG_ZERO_SIZE,
|
||||
};
|
||||
|
||||
pub const CG_AFFINE_TRANSFORM_IDENTITY: CGAffineTransform = CGAffineTransform {
|
||||
a: 1.0, b: 0.0,
|
||||
c: 0.0, d: 1.0,
|
||||
tx: 0.0, ty: 0.0,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub struct CGSize {
|
||||
pub width: CGFloat,
|
||||
pub height: CGFloat,
|
||||
}
|
||||
|
||||
impl CGSize {
|
||||
#[inline]
|
||||
pub fn new(width: CGFloat, height: CGFloat) -> CGSize {
|
||||
CGSize {
|
||||
width: width,
|
||||
height: height,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn apply_transform(&self, t: &CGAffineTransform) -> CGSize {
|
||||
unsafe {
|
||||
ffi::CGSizeApplyAffineTransform(*self, *t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub struct CGPoint {
|
||||
pub x: CGFloat,
|
||||
pub y: CGFloat,
|
||||
}
|
||||
|
||||
impl CGPoint {
|
||||
#[inline]
|
||||
pub fn new(x: CGFloat, y: CGFloat) -> CGPoint {
|
||||
CGPoint {
|
||||
x: x,
|
||||
y: y,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn apply_transform(&self, t: &CGAffineTransform) -> CGPoint {
|
||||
unsafe {
|
||||
ffi::CGPointApplyAffineTransform(*self, *t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct CGRect {
|
||||
pub origin: CGPoint,
|
||||
pub size: CGSize
|
||||
}
|
||||
|
||||
impl CGRect {
|
||||
#[inline]
|
||||
pub fn new(origin: &CGPoint, size: &CGSize) -> CGRect {
|
||||
CGRect {
|
||||
origin: *origin,
|
||||
size: *size,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inset(&self, size: &CGSize) -> CGRect {
|
||||
unsafe {
|
||||
ffi::CGRectInset(*self, size.width, size.height)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_dict_representation(dict: &CFDictionary) -> Option<CGRect> {
|
||||
let mut rect = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(0., 0.));
|
||||
let result = unsafe {
|
||||
ffi::CGRectMakeWithDictionaryRepresentation(dict.as_concrete_TypeRef(), &mut rect)
|
||||
};
|
||||
if result == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(rect)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
unsafe {
|
||||
// I use one, as it seems that `YES` is not available from this crate.
|
||||
ffi::CGRectIsEmpty(*self) == 1
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_intersects(&self, other: &CGRect) -> bool {
|
||||
unsafe {
|
||||
// I use one, as it seems that `YES` is not available from this crate.
|
||||
ffi::CGRectIntersectsRect(*self, *other) == 1
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn apply_transform(&self, t: &CGAffineTransform) -> CGRect {
|
||||
unsafe {
|
||||
ffi::CGRectApplyAffineTransform(*self, *t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for CGRect {
|
||||
#[inline]
|
||||
fn eq(&self, other: &CGRect) -> bool {
|
||||
unsafe {
|
||||
ffi::CGRectEqualToRect(*self, *other) != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct CGAffineTransform {
|
||||
pub a: CGFloat,
|
||||
pub b: CGFloat,
|
||||
pub c: CGFloat,
|
||||
pub d: CGFloat,
|
||||
pub tx: CGFloat,
|
||||
pub ty: CGFloat,
|
||||
}
|
||||
|
||||
impl CGAffineTransform {
|
||||
#[inline]
|
||||
pub fn new(
|
||||
a: CGFloat,
|
||||
b: CGFloat,
|
||||
c: CGFloat,
|
||||
d: CGFloat,
|
||||
tx: CGFloat,
|
||||
ty: CGFloat,
|
||||
) -> CGAffineTransform {
|
||||
CGAffineTransform { a, b, c, d, tx, ty }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn make_translation(tx: CGFloat, ty: CGFloat) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformMakeTranslation(tx, ty)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn make_rotation(angle: CGFloat) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformMakeRotation(angle)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn make_scale(sx: CGFloat, sy: CGFloat) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformMakeScale(sx, sy)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn translate(&self, tx: CGFloat, ty: CGFloat) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformTranslate(*self, tx, ty)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn rotate(&self, angle: CGFloat) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformRotate(*self, angle)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scale(&self, sx: CGFloat, sy: CGFloat) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformScale(*self, sx, sy)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn invert(&self) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformInvert(*self)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn concat(&self, t: CGAffineTransform) -> CGAffineTransform {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformConcat(*self, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for CGAffineTransform {
|
||||
#[inline]
|
||||
fn eq(&self, other: &CGAffineTransform) -> bool {
|
||||
unsafe {
|
||||
ffi::CGAffineTransformEqualToTransform(*self, *other) != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod ffi {
|
||||
use base::{CGFloat, boolean_t};
|
||||
use geometry::{CGAffineTransform, CGPoint, CGRect, CGSize};
|
||||
use core_foundation::dictionary::CFDictionaryRef;
|
||||
|
||||
#[link(name = "CoreGraphics", kind = "framework")]
|
||||
extern {
|
||||
pub fn CGRectInset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect;
|
||||
pub fn CGRectMakeWithDictionaryRepresentation(dict: CFDictionaryRef,
|
||||
rect: *mut CGRect) -> boolean_t;
|
||||
pub fn CGRectIsEmpty(rect: CGRect) -> boolean_t;
|
||||
pub fn CGRectIntersectsRect(rect1: CGRect, rect2: CGRect) -> boolean_t;
|
||||
pub fn CGRectEqualToRect(rect1: CGRect, rect2: CGRect) -> boolean_t;
|
||||
|
||||
// Creating an Affine Transformation Matrix
|
||||
pub fn CGAffineTransformMakeTranslation(tx: CGFloat, ty: CGFloat) -> CGAffineTransform;
|
||||
pub fn CGAffineTransformMakeRotation(angle: CGFloat) -> CGAffineTransform;
|
||||
pub fn CGAffineTransformMakeScale(sx: CGFloat, sy: CGFloat) -> CGAffineTransform;
|
||||
|
||||
// Modifying Affine Transformations
|
||||
pub fn CGAffineTransformTranslate(t: CGAffineTransform, tx: CGFloat, ty: CGFloat) -> CGAffineTransform;
|
||||
pub fn CGAffineTransformRotate(t: CGAffineTransform, angle: CGFloat) -> CGAffineTransform;
|
||||
pub fn CGAffineTransformScale(t: CGAffineTransform, sx: CGFloat, sy: CGFloat) -> CGAffineTransform;
|
||||
pub fn CGAffineTransformInvert(t: CGAffineTransform) -> CGAffineTransform;
|
||||
pub fn CGAffineTransformConcat(t1: CGAffineTransform, t2: CGAffineTransform) -> CGAffineTransform;
|
||||
pub fn CGAffineTransformEqualToTransform(t1: CGAffineTransform,
|
||||
t2: CGAffineTransform) -> boolean_t;
|
||||
|
||||
pub fn CGPointApplyAffineTransform(point: CGPoint, t: CGAffineTransform) -> CGPoint;
|
||||
pub fn CGRectApplyAffineTransform(rect: CGRect, t: CGAffineTransform) -> CGRect;
|
||||
pub fn CGSizeApplyAffineTransform(size: CGSize, t: CGAffineTransform) -> CGSize;
|
||||
}
|
||||
}
|
||||
|
||||
pub use core_graphics_types::geometry::*;
|
||||
@@ -18,6 +18,8 @@ extern crate bitflags;
|
||||
#[macro_use]
|
||||
extern crate foreign_types;
|
||||
|
||||
extern crate core_graphics_types;
|
||||
|
||||
pub mod base;
|
||||
pub mod color;
|
||||
pub mod color_space;
|
||||
|
||||
Reference in New Issue
Block a user