Struct gdnative_core::core_types::Color
source · Expand description
RGBA color with 32-bit floating point components.
Fields§
§r: f32
§g: f32
§b: f32
§a: f32
Implementations§
source§impl Color
impl Color
pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Color
pub fn from_rgb(r: f32, g: f32, b: f32) -> Color
pub fn from_hsv(h: f32, s: f32, v: f32) -> Color
pub fn from_hsva(h: f32, s: f32, v: f32, a: f32) -> Color
sourcepub fn from_html(argb_or_rgb: &str) -> Option<Self>
pub fn from_html(argb_or_rgb: &str) -> Option<Self>
Parses from a HTML color code, or None
on parse error.
Note that unlike most other constructors, this has ARGB
and not RGBA
format.
In particular, from_html("AB123456")
would correspond to from_rgba_u32(0x123456AB)
.
use gdnative::prelude::Color;
let c1 = Color::from_html("#9eb2d90a"); // ARGB format with "#".
let c2 = Color::from_html("9eb2d90a"); // ARGB format.
let c3 = Color::from_html("#b2d90a"); // RGB format with "#".
let c4 = Color::from_html("b2d90a"); // RGB format.
let expected = Color::from_rgba_u8(0xb2, 0xd9, 0x0a, 0x9e);
assert_eq!(c1, Some(expected));
assert_eq!(c2, Some(expected));
let expected = Color::from_rgba_u8(0xb2, 0xd9, 0x0a, 0xff);
assert_eq!(c3, Some(expected));
assert_eq!(c4, Some(expected));
See also the corresponding GDScript method.
sourcepub fn from_rgba_u32(rgba: u32) -> Self
pub fn from_rgba_u32(rgba: u32) -> Self
Construct a color from a single u32
value, in RGBA
format.
Example:
use gdnative::prelude::Color;
// RGBA (178, 217, 10, 158)
let one = Color::from_rgba_u32(0xb2d90a9e);
let piecewise = Color::from_rgba_u8(0xB2, 0xD9, 0x0A, 0x9E);
assert_eq!(one, piecewise);
sourcepub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a color from four integer channels, each in range 0-255.
This corresponds to the
GDScript method Color8
.
pub fn h(&self) -> f32
pub fn s(&self) -> f32
pub fn v(&self) -> f32
pub fn lerp(&self, other: Color, weight: f32) -> Color
pub fn blend(&self, other: &Color) -> Color
pub fn contrasted(&self) -> Color
pub fn darkened(&self, amount: f32) -> Color
pub fn gray(&self) -> f32
pub fn inverted(&self) -> Color
pub fn to_html(self, with_alpha: bool) -> GodotString
sourcepub fn to_abgr32(self) -> u32
pub fn to_abgr32(self) -> u32
Returns the reverse of the RGBA32 byte representation for this color where each byte represents a component of the ABGR profile. This is the byte information used when storing this color as a part of a texture.
Endianness
On big endian architecture this is stored in ABGR byte order On little endian machines this is stored in RGBA byte order
Example
0x00FF7FFF
would be the equivalent to Color::from_rgba(1.0, 0.5, 1.0, 0.0)
sourcepub fn to_abgr64(self) -> u64
pub fn to_abgr64(self) -> u64
Returns the reverse of the RGBA64 byte representation for this color where each word represents represents a component of the ABGR profile. This is the byte information used when storing this color as a part of a texture.
Endianness
On big endian architecture this is stored in ABGR word order On little endian machines this is stored in RGBA word order
Example
0x0000FFFF7FFFFFFF
would be the equivalent to Color::from_rgba(0.0, 1.0, 0.5, 1.0)
sourcepub fn to_argb32(self) -> u32
pub fn to_argb32(self) -> u32
Returns the ARGB32 format representation representation for this color where each byte represents a component of the ARGB profile. This is the byte information used when storing this color as a part of a texture.
Endianness
On big endian architecture this is stored in the order ARGB byte order
On little endian machines this is stored in the order BGRA byte order
0x0000FFFF7FFFFFFF
would be the equivalent to Color::from_rgba(1.0, 0.5, 1.0, 0.0)
sourcepub fn to_argb64(self) -> u64
pub fn to_argb64(self) -> u64
Returns the ARGB64 format representation for this color where each word represents a component of the ARGB profile. This is the byte information used when storing this color as a part of a texture.
Endianness
On big endian architecture this is stored in the order ARGB word order On little endian machines this is stored in the order BGRA word order
Example
0x0000FFFF7FFFFFFF
would be the equivalent to Color::from_rgba(1.0, 0.5, 1.0, 0.0)
sourcepub fn to_rgba32(self) -> u32
pub fn to_rgba32(self) -> u32
Returns the OpenGL Texture format byte representation for this color where each byte represents a component of the RGBA profile. This is the byte information used when storing this color as a part of a texture.
Endianness
On big endian architecture this is stored in RGBA byte order On little endian machines this is stored in ABGR byte order
Example
0x00FF7FFF
would be the equivalent to Color::from_rgba(0.0, 1.0, 0.5, 1.0)
sourcepub fn to_rgba64(self) -> u64
pub fn to_rgba64(self) -> u64
Returns the OpenGL Texture format byte representation for this color where each byte represents a component of the RGBA profile. This is the byte information used when storing this color as a part of a texture.
Endianness
On big endian architecture this is stored in RGBA word order On little endian machines this is stored in ABGR word order
Example
0x0000FFFF7FFFFFFF
would be the equivalent to Color::from_rgba(0.0, 1.0, 0.5, 1.0)
Trait Implementations§
source§impl CoerceFromVariant for Color
impl CoerceFromVariant for Color
fn coerce_from_variant(v: &Variant) -> Self
source§impl Export for Color
impl Export for Color
§type Hint = ColorHint
type Hint = ColorHint
source§fn export_info(hint: Option<Self::Hint>) -> ExportInfo
fn export_info(hint: Option<Self::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.