bms_rs/bms/command/
graphics.rs

1//! Defines for graphics.
2
3/// A 2D point in pixel coordinates.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct PixelPoint {
7    /// X coordinate in pixels.
8    pub x: i16,
9    /// Y coordinate in pixels.
10    pub y: i16,
11}
12
13impl PixelPoint {
14    /// Creates a new pixel point.
15    #[must_use]
16    pub const fn new(x: i16, y: i16) -> Self {
17        Self { x, y }
18    }
19}
20
21impl From<(i16, i16)> for PixelPoint {
22    fn from((x, y): (i16, i16)) -> Self {
23        Self { x, y }
24    }
25}
26
27impl From<PixelPoint> for (i16, i16) {
28    fn from(point: PixelPoint) -> Self {
29        (point.x, point.y)
30    }
31}
32
33/// A 2D size in pixels.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36pub struct PixelSize {
37    /// Width in pixels.
38    pub width: u16,
39    /// Height in pixels.
40    pub height: u16,
41}
42
43impl PixelSize {
44    /// Creates a new pixel size.
45    #[must_use]
46    pub const fn new(width: u16, height: u16) -> Self {
47        Self { width, height }
48    }
49}
50
51impl From<(u16, u16)> for PixelSize {
52    fn from((width, height): (u16, u16)) -> Self {
53        Self { width, height }
54    }
55}
56
57impl From<PixelSize> for (u16, u16) {
58    fn from(size: PixelSize) -> Self {
59        (size.width, size.height)
60    }
61}
62
63/// An alpha-red-gree-blue color data.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
65#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
66pub struct Argb {
67    /// A component of alpha.
68    pub alpha: u8,
69    /// A component of red.
70    pub red: u8,
71    /// A component of green.
72    pub green: u8,
73    /// A component of blue.
74    pub blue: u8,
75}
76
77impl Default for Argb {
78    fn default() -> Self {
79        Self {
80            alpha: 255,
81            red: 0,
82            green: 0,
83            blue: 0,
84        }
85    }
86}
87
88/// RGB struct, used for #VIDEOCOLORS and similar commands.
89#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
90#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
91pub struct Rgb {
92    /// Red component
93    pub r: u8,
94    /// Green component
95    pub g: u8,
96    /// Blue component
97    pub b: u8,
98}