diff --git a/core-graphics/src/color.rs b/core-graphics/src/color.rs new file mode 100644 index 0000000..f8364f1 --- /dev/null +++ b/core-graphics/src/color.rs @@ -0,0 +1,33 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use core_foundation::base::{CFTypeID}; +use base::CGFloat; +use core_foundation::base::TCFType; +use super::sys::{CGColorRef}; + +declare_TCFType!{ + CGColor, CGColorRef +} +impl_TCFType!(CGColor, CGColorRef, CGColorGetTypeID); + +impl CGColor { + pub fn rgb(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> Self { + unsafe { + let ptr = CGColorCreateGenericRGB(red, green, blue, alpha); + CGColor::wrap_under_create_rule(ptr) + } + } +} + +#[link(name = "CoreGraphics", kind = "framework")] +extern { + fn CGColorCreateGenericRGB(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> ::sys::CGColorRef; + fn CGColorGetTypeID() -> CFTypeID; +} diff --git a/core-graphics/src/lib.rs b/core-graphics/src/lib.rs index 01854e1..71f94b8 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -8,6 +8,8 @@ // except according to those terms. extern crate libc; + +#[macro_use] extern crate core_foundation; #[macro_use] @@ -18,6 +20,7 @@ extern crate bitflags; extern crate foreign_types; pub mod base; +pub mod color; pub mod color_space; pub mod context; pub mod data_provider; diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index 1048e04..ccf0625 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -1,6 +1,13 @@ +use std::os::raw::c_void; + pub enum CGImage {} pub type CGImageRef = *mut CGImage; +#[repr(C)] +pub struct __CGColor(c_void); + +pub type CGColorRef = *const __CGColor; + pub enum CGColorSpace {} pub type CGColorSpaceRef = *mut CGColorSpace;