all_is_cubes/content/
palette.rs

1//! Colors to use in the UI and default content.
2//!
3//! This module exists to be a place where we can review the different colors in use
4//! and tweak them to go well together, and avoid introducing extra slightly different
5//! hardcoded colors if possible.
6//!
7//! TODO: Split "system UI" colors and "demo content" colors.
8
9// Implementation notes:
10//
11// Most of these colors are defined in sRGB because that way, they can be directly viewed
12// in the documentation (using only macro_rules for the generation). However, All is Cubes
13// internally uses strictly linear color space.
14//
15// 0xBB is the sRGB value approximating linear value 0.5.
16
17#![allow(clippy::too_long_first_doc_paragraph, reason = "false positive on SVG")]
18
19use crate::math::{rgb_const, Rgb};
20
21/// Define a color constant and preview it in the documentation.
22macro_rules! palette_entry {
23    (
24        $( #[doc = $doc:literal] )*
25        $name:ident = srgb[$r:literal $g:literal $b:literal]
26    ) => {
27        #[doc = concat!(
28            "<svg width='3.2em' height='3em' style='vertical-align: top; float: left; clear: left; padding-right: .2em;'>",
29            "<rect width='100%' height='100%' fill='rgb(", $r, ",", $g, ",", $b, ")' /></svg>"
30        )]
31        $( #[doc = $doc] )*
32        pub const $name: $crate::math::Rgb = $crate::math::Rgb::from_srgb8([$r, $g, $b]);
33    };
34    (
35        $( #[doc = $doc:literal] )*
36        $name:ident = srgb[$r:literal $g:literal $b:literal $a:literal]
37    ) => {
38        // TODO: visualize alpha
39        #[doc = concat!
40            ("<svg width='3.2em' height='3em' style='vertical-align: top; float: left; clear: left; padding-right: .2em;'>",
41            "<rect width='100%' height='100%' fill='rgb(", $r, ",", $g, ",", $b, ")' /></svg>"
42        )]
43        $( #[doc = $doc] )*
44        pub const $name: $crate::math::Rgba = $crate::math::Rgba::from_srgb8([$r, $g, $b, $a]);
45    };
46}
47
48/// Define many color constants. In the future, this might start defining an enum; I haven't decided.
49macro_rules! palette {
50    ( $(
51        $( #[doc = $doc:literal] )*
52        $name:ident = srgb $data:tt ;
53    )* ) => {
54        $( palette_entry! {
55            $( #[doc = $doc] )*
56            $name = srgb $data
57        } )*
58    }
59}
60
61palette! {
62    /// Default sky color for new [`Space`](crate::space::Space)s.
63    DAY_SKY_COLOR = srgb[243 243 255];
64
65    /// Used in texture atlases to mark areas that should not be visible.
66    UNALLOCATED_TEXELS_ERROR = srgb[0xFF 0x00 0xBB 0xFF];
67
68    /// Used as a placeholder appearance when a block definition fails to evaluate.
69    BLOCK_EVAL_ERROR = srgb[0xFF 0xBB 0x00 0xFF];
70
71    /// Used when a recursive block definition should have provided a voxel color but did not.
72    MISSING_VOXEL_ERROR = srgb[0xBB 0x00 0xFF 0xFF];
73
74    /// Fill color to draw when a renderer does not have any [`Space`](crate::space::Space)
75    /// to define a sky color.
76    NO_WORLD_TO_SHOW = srgb[0xBC 0xBC 0xBC 0xFF];
77}
78
79palette! {
80    // Physical material colors.
81    /// A realistic value for typical black materials, which do not absorb all light.
82    ALMOST_BLACK = srgb[0x3d 0x3d 0x3d];
83    ///
84    GRASS = srgb[0x61 0xAA 0x31];
85    ///
86    DIRT = srgb[0x6C 0x50 0x44];
87    /// Generic unspecified some-kind-of-stone...
88    STONE = srgb[0xD9 0xD7 0xD5];
89    /// TODO: Not actually exercised in demo content yet
90    TREE_BARK = srgb[0x93 0x5C 0x32];
91    /// TODO: Not actually exercised in demo content yet
92    TREE_LEAVES = srgb[0x61 0xAA 0x31];
93    /// Some kind of metallic structure.
94    ///
95    /// TODO: not taken from real references
96    STEEL = srgb[0xAA 0xAA 0xAA];
97    /// Some kind of prepared wood.
98    ///
99    /// TODO: not taken from real references
100    PLANK = srgb[0xE8 0xCC 0x95];
101}
102
103palette! {
104    // All is Cubes logo components
105    // TODO: Decide what we want *actual* logo(type) colors to be.
106    LOGO_FILL = srgb[0xC7 0x33 0x78];
107    LOGO_STROKE = srgb[0x33 0x33 0x33];
108}
109
110palette! {
111    // UI elements
112    CURSOR_OUTLINE = srgb[0x00 0x00 0x00 0xFF];
113    /// Illumination color in the HUD.
114    HUD_SKY = srgb[0xFF 0xFF 0xFF];
115    HUD_TEXT_FILL = srgb[0x00 0x00 0x00 0xFF];
116    HUD_TEXT_STROKE = srgb[0xFF 0xFF 0xFF 0xFF];
117    HUD_TOOLBAR_BACK = srgb[0x7E 0x7E 0x7E 0xFF];
118    HUD_TOOLBAR_FRAME = srgb[0xDD 0xDD 0xDD 0xFF];
119    MENU_BACK = srgb[0xBC 0xBC 0xBC 0xFF];
120    MENU_FRAME = srgb[0xFA 0xFA 0xFA 0xFF];
121    BUTTON_FRAME = srgb[0x3d 0x3d 0x3d 0xFF];
122    BUTTON_BACK = srgb[0xBC 0xBC 0xBC 0xFF];
123    BUTTON_LABEL = srgb[0x3d 0x3d 0x3d 0xFF];
124    BUTTON_ACTIVATED_BACK = srgb[0xD1 0xBC 0xBC 0xFF];
125    BUTTON_ACTIVATED_LABEL = srgb[0x63 0x63 0x63 0xFF];
126}
127pub const BUTTON_ACTIVATED_GLOW: Rgb = rgb_const!(1.0, 0.2, 0.2);
128
129palette! {
130    // In-world debug UI elements (all wireframe)
131    // TODO: these have no reason to be public
132    DEBUG_BEHAVIOR_BOUNDS = srgb[0x00 0x70 0x00 0xFF];
133    DEBUG_COLLISION_BOX = srgb[0x00 0x00 0xFF 0xFF];
134    DEBUG_COLLISION_CUBE_AGAINST = srgb[0xDD 0x00 0x00 0xFF];
135    DEBUG_COLLISION_CUBE_WITHIN = srgb[0xFF 0x22 0x00 0xFF];
136    DEBUG_CHUNK_MAJOR = srgb[0x00 0x00 0xE8 0xFF];
137    DEBUG_CHUNK_MINOR = srgb[0x00 0xE8 0xE8 0xFF];
138}