Skip to main content

euv_engine/renderer/canvas/
enum.rs

1use super::*;
2
3/// A single deferred draw operation recorded into a `DrawList`.
4///
5/// Commands carry the resolved style for the operation (fill/stroke color, line
6/// width) so that replay can group consecutive same-style shapes into a single
7/// path and skip redundant canvas state changes. Colors are stored as `Color`
8/// and converted to CSS strings only at replay time.
9#[derive(Clone, Debug, PartialEq)]
10pub enum DrawCommand {
11    /// Fills a rectangle. Carries the fill color.
12    FillRect {
13        /// The top-left position in world space.
14        position: Vector2D,
15        /// The width in pixels.
16        width: f64,
17        /// The height in pixels.
18        height: f64,
19        /// The fill color.
20        color: Color,
21    },
22    /// Strokes the outline of a rectangle. Carries stroke color and line width.
23    StrokeRect {
24        /// The top-left position in world space.
25        position: Vector2D,
26        /// The width in pixels.
27        width: f64,
28        /// The height in pixels.
29        height: f64,
30        /// The stroke color.
31        color: Color,
32        /// The stroke line width in pixels.
33        line_width: f64,
34    },
35    /// Fills a circle. Carries the fill color.
36    FillCircle {
37        /// The center in world space.
38        center: Vector2D,
39        /// The radius in pixels.
40        radius: f64,
41        /// The fill color.
42        color: Color,
43    },
44    /// Strokes the outline of a circle. Carries stroke color and line width.
45    StrokeCircle {
46        /// The center in world space.
47        center: Vector2D,
48        /// The radius in pixels.
49        radius: f64,
50        /// The stroke color.
51        color: Color,
52        /// The stroke line width in pixels.
53        line_width: f64,
54    },
55    /// Draws a line segment. Carries stroke color and line width.
56    Line {
57        /// The start point in world space.
58        start: Vector2D,
59        /// The end point in world space.
60        end: Vector2D,
61        /// The stroke color.
62        color: Color,
63        /// The stroke line width in pixels.
64        line_width: f64,
65    },
66    /// Fills text at a position. Carries the fill color and font.
67    FillText {
68        /// The text to draw.
69        text: String,
70        /// The position in world space.
71        position: Vector2D,
72        /// The fill color.
73        color: Color,
74        /// The CSS font string.
75        font: String,
76    },
77    /// Draws a transformed sprite sub-region (image, source rect, TRS transform).
78    DrawSprite {
79        /// The image to draw.
80        image: HtmlImageElement,
81        /// The source rectangle within the image.
82        source: Rect,
83        /// The world-space transform (position, rotation, scale). Scale signs flip.
84        transform: Transform2D,
85    },
86    /// Draws an image sub-region at a destination rect (no rotation).
87    DrawImageRect {
88        /// The image to draw.
89        image: HtmlImageElement,
90        /// The source rectangle within the image.
91        source: Rect,
92        /// The destination top-left position in world space.
93        dest_position: Vector2D,
94        /// The destination width in pixels.
95        dest_width: f64,
96        /// The destination height in pixels.
97        dest_height: f64,
98    },
99    /// Applies a global alpha to all subsequent commands until changed.
100    SetGlobalAlpha {
101        /// The alpha value in the range 0.0 to 1.0.
102        alpha: f64,
103    },
104    /// Applies a blend mode to all subsequent commands until changed.
105    SetBlendMode {
106        /// The blend mode to apply.
107        mode: BlendMode,
108    },
109    /// Draws a texture as a nine-slice, keeping the corners fixed while
110    /// the edges and centre stretch to the destination rectangle.
111    DrawNineSlice {
112        /// The source texture to slice.
113        image: web_sys::HtmlImageElement,
114        /// The border insets splitting the texture into nine regions.
115        insets: NineSliceInsets,
116        /// The top-left position in world space.
117        dest_position: Vector2D,
118        /// The destination width in pixels.
119        dest_width: f64,
120        /// The destination height in pixels.
121        dest_height: f64,
122    },
123    /// Draws one named region of a sprite atlas texture.
124    DrawAtlasRegion {
125        /// The atlas texture holding the region.
126        image: web_sys::HtmlImageElement,
127        /// The region within the atlas, in source pixels.
128        source: Rect,
129        /// The top-left position in world space.
130        dest_position: Vector2D,
131        /// The destination width in pixels.
132        dest_width: f64,
133        /// The destination height in pixels.
134        dest_height: f64,
135    },
136}