use objc::runtime::*;
use objc::*;
use crate::coregraphics::CGFloat;
use crate::Raw;
pub struct UIColor {
object: *mut Object,
}
impl UIColor {
pub fn new(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> UIColor {
unsafe {
UIColor::from_raw_retain(msg_send![class!(UIColor), colorWithRed: red
green: green
blue: blue
alpha: alpha])
}
}
pub fn get_components(&self) -> (CGFloat, CGFloat, CGFloat, CGFloat) {
let mut red: CGFloat = 0.0;
let mut green: CGFloat = 0.0;
let mut blue: CGFloat = 0.0;
let mut alpha: CGFloat = 0.0;
unsafe {
let _: () = msg_send![self.object, getRed: &mut red
green: &mut green
blue: &mut blue
alpha: &mut alpha];
}
(red, green, blue, alpha)
}
pub fn clear() -> UIColor {
unsafe { UIColor::from_raw_retain(msg_send![class!(UIColor), clearColor]) }
}
}
unsafe impl Send for UIColor {}
unsafe impl Sync for UIColor {}
impl Raw for UIColor {
unsafe fn from_raw(object: *mut Object) -> Self {
UIColor { object }
}
unsafe fn as_raw(&self) -> *mut Object {
self.object
}
}
impl Clone for UIColor {
fn clone(&self) -> Self {
unsafe { UIColor::from_raw_retain(self.as_raw()) }
}
}
impl Drop for UIColor {
fn drop(&mut self) {
unsafe { objc_release(self.object) }
}
}