diff options
Diffstat (limited to 'components/gfx_traits')
-rw-r--r-- | components/gfx_traits/Cargo.toml | 11 | ||||
-rw-r--r-- | components/gfx_traits/color.rs | 41 | ||||
-rw-r--r-- | components/gfx_traits/lib.rs | 9 |
3 files changed, 61 insertions, 0 deletions
diff --git a/components/gfx_traits/Cargo.toml b/components/gfx_traits/Cargo.toml new file mode 100644 index 00000000000..913e973d163 --- /dev/null +++ b/components/gfx_traits/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "gfx_traits" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "gfx_traits" +path = "lib.rs" + +[dependencies.azure] +git = "https://github.com/servo/rust-azure" diff --git a/components/gfx_traits/color.rs b/components/gfx_traits/color.rs new file mode 100644 index 00000000000..a128d364432 --- /dev/null +++ b/components/gfx_traits/color.rs @@ -0,0 +1,41 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use azure::AzFloat; +use azure::azure::AzColor; + +#[inline] +pub fn new(r: AzFloat, g: AzFloat, b: AzFloat, a: AzFloat) -> AzColor { + AzColor { r: r, g: g, b: b, a: a } +} + +#[inline] +pub fn rgb(r: u8, g: u8, b: u8) -> AzColor { + AzColor { + r: (r as AzFloat) / (255.0 as AzFloat), + g: (g as AzFloat) / (255.0 as AzFloat), + b: (b as AzFloat) / (255.0 as AzFloat), + a: 1.0 as AzFloat + } +} + +#[inline] +pub fn rgba(r: AzFloat, g: AzFloat, b: AzFloat, a: AzFloat) -> AzColor { + AzColor { r: r, g: g, b: b, a: a } +} + +#[inline] +pub fn black() -> AzColor { + AzColor { r: 0.0, g: 0.0, b: 0.0, a: 1.0 } +} + +#[inline] +pub fn transparent() -> AzColor { + AzColor { r: 0.0, g: 0.0, b: 0.0, a: 0.0 } +} + +#[inline] +pub fn white() -> AzColor { + AzColor { r: 1.0, g: 1.0, b: 1.0, a: 1.0 } +} diff --git a/components/gfx_traits/lib.rs b/components/gfx_traits/lib.rs new file mode 100644 index 00000000000..ea77933ce89 --- /dev/null +++ b/components/gfx_traits/lib.rs @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#![crate_name = "gfx_traits"] +#![crate_type = "rlib"] +extern crate azure; + +pub mod color; |