use std::ops::{Add, Mul};
use csfml_graphics_sys as ffi;
#[repr(C)]
pub struct Color(pub ffi::sfColor);
impl Color {
pub fn new_rgb(red: u8, green: u8, blue: u8) -> Color {
Color(ffi::sfColor {
red: red,
green: green,
blue: blue,
alpha: 255
})
}
pub fn new_rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Color {
Color(ffi::sfColor {
red: red,
green: green,
blue: blue,
alpha: alpha
})
}
pub fn add(color1: Color, color2: Color) -> Color {
Color(unsafe {ffi::sfColor_add(color1.0, color2.0)})
}
pub fn modulate(color1: Color, color2: Color) -> Color {
Color(unsafe {ffi::sfColor_modulate(color1.0, color2.0)})
}
pub fn black() -> Color {
Color::new_rgb(0, 0, 0)
}
pub fn white() -> Color {
Color::new_rgb(255, 255, 255)
}
pub fn red() -> Color {
Color::new_rgb(255, 0, 0)
}
pub fn green() -> Color {
Color::new_rgb(0, 255, 0)
}
pub fn blue() -> Color {
Color::new_rgb(0, 0, 255)
}
pub fn yellow() -> Color {
Color::new_rgb(255, 255, 0)
}
pub fn magenta() -> Color {
Color::new_rgb(255, 0, 255)
}
pub fn cyan() -> Color {
Color::new_rgb(0, 255, 255)
}
pub fn transparent() -> Color {
Color::new_rgba(0, 0, 0, 0)
}
}
impl Add for Color {
type Output = Color;
fn add(self, other: Color) -> Color {
let r: i32 = self.0.red as i32 + other.0.red as i32;
let g: i32 = self.0.green as i32 + other.0.green as i32;
let b: i32 = self.0.blue as i32 + other.0.blue as i32;
let a: i32 = self.0.alpha as i32 + other.0.alpha as i32;
Color(ffi::sfColor {
red: if r > 255 {255} else {r as u8},
green: if g > 255 {255} else {g as u8},
blue: if b > 255 {255} else {b as u8},
alpha: if a > 255 {255} else {a as u8}
})
}
}
impl Mul for Color {
type Output = Color;
fn mul(self, other: Color) -> Color {
let r: i32 = self.0.red as i32 * (other.0.red as i32);
let g: i32 = self.0.green as i32 * (other.0.green as i32);
let b: i32 = self.0.blue as i32 * (other.0.blue as i32);
let a: i32 = self.0.alpha as i32 * (other.0.alpha as i32);
Color(ffi::sfColor {
red: if r > 255 {255} else {r as u8},
green: if g > 255 {255} else {g as u8},
blue: if b > 255 {255} else {b as u8},
alpha: if a > 255 {255} else {a as u8}
})
}
}