Debian Codegraph @

third_party/rust/core-graphics/src/gradient.rs

raw
1 // Copyright 2013 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![allow(non_upper_case_globals)]
11
12 use base::CGFloat;
13 use color::CGColor;
14 use color_space::CGColorSpace;
15
16 use core_foundation::array::{ CFArray, CFArrayRef };
17 use core_foundation::base::{CFRelease, CFRetain, TCFType};
18 use foreign_types::ForeignType;
19
20 use libc::size_t;
21
22 bitflags! {
23 #[repr(C)]
24 pub struct CGGradientDrawingOptions: u32 {
25 const CGGradientDrawsBeforeStartLocation = (1 << 0);
26 const CGGradientDrawsAfterEndLocation = (1 << 1);
27 }
28 }
29
30 foreign_type! {
31 #[doc(hidden)]
32 pub unsafe type CGGradient {
33 type CType = ::sys::CGGradient;
34 fn drop = |p| CFRelease(p as *mut _);
35 fn clone = |p| CFRetain(p as *const _) as *mut _;
36 }
37 }
38
39 impl CGGradient {
40 pub fn create_with_color_components(color_space: &CGColorSpace, components: &[CGFloat], locations: &[CGFloat], count: usize) -> CGGradient {
41 unsafe {
42 let result = CGGradientCreateWithColorComponents(color_space.as_ptr(), components.as_ptr(), locations.as_ptr(), count);
43 assert!(!result.is_null());
44 Self::from_ptr(result)
45 }
46 }
47
48 pub fn create_with_colors(color_space: &CGColorSpace, colors: &CFArray<CGColor>, locations: &[CGFloat]) -> CGGradient {
49 unsafe {
50 let result = CGGradientCreateWithColors(color_space.as_ptr(), colors.as_concrete_TypeRef(), locations.as_ptr());
51 assert!(!result.is_null());
52 Self::from_ptr(result)
53 }
54 }
55 }
56
57 #[link(name = "CoreGraphics", kind = "framework")]
58 extern {
59 fn CGGradientCreateWithColorComponents(color_space: ::sys::CGColorSpaceRef, components: *const CGFloat, locations: *const CGFloat, count: size_t) -> ::sys::CGGradientRef;
60 fn CGGradientCreateWithColors(color_space: ::sys::CGColorSpaceRef, colors: CFArrayRef, locations: *const CGFloat) -> ::sys::CGGradientRef;
61 }
62