1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License in the LICENSE-APACHE file or at:
// https://www.apache.org/licenses/LICENSE-2.0
//! Drawing APIs — shaded drawing
use kas::draw::color::Rgba;
use kas::draw::{DrawIface, DrawImpl, DrawSharedImpl, PassId};
use kas::geom::Quad;
/// Extension trait providing shaded drawing over [`DrawIface`]
///
/// All methods draw some feature.
///
/// Methods are parameterised via a pair of normals, `(inner, outer)`, which
/// specify the surface normal direction at inner and outer edges of the feature
/// respectively (with interpolation between these edges). These have values
/// from the closed range `[-1, 1]`, where -1 points towards the inside of the
/// feature, 1 points away from the feature, and 0 is perpendicular to the
/// screen towards the viewer.
pub trait DrawShaded {
/// Add a shaded square to the draw buffer
///
/// For shading purposes, the mid-point is considered the inner edge.
fn shaded_square(&mut self, rect: Quad, norm: (f32, f32), col: Rgba);
/// Add a shaded circle to the draw buffer
///
/// For shading purposes, the mid-point is considered the inner edge.
fn shaded_circle(&mut self, rect: Quad, norm: (f32, f32), col: Rgba);
/// Add a shaded frame with square corners to the draw buffer
fn shaded_square_frame(
&mut self,
outer: Quad,
inner: Quad,
norm: (f32, f32),
outer_col: Rgba,
inner_col: Rgba,
);
/// Add a shaded frame with rounded corners to the draw buffer
fn shaded_round_frame(&mut self, outer: Quad, inner: Quad, norm: (f32, f32), col: Rgba);
}
impl<'a, DS: DrawSharedImpl> DrawShaded for DrawIface<'a, DS>
where
DS::Draw: DrawShadedImpl,
{
fn shaded_square(&mut self, rect: Quad, norm: (f32, f32), col: Rgba) {
self.draw.shaded_square(self.pass, rect, norm, col);
}
fn shaded_circle(&mut self, rect: Quad, norm: (f32, f32), col: Rgba) {
self.draw.shaded_circle(self.pass, rect, norm, col);
}
fn shaded_square_frame(
&mut self,
outer: Quad,
inner: Quad,
norm: (f32, f32),
outer_col: Rgba,
inner_col: Rgba,
) {
self.draw
.shaded_square_frame(self.pass, outer, inner, norm, outer_col, inner_col);
}
fn shaded_round_frame(&mut self, outer: Quad, inner: Quad, norm: (f32, f32), col: Rgba) {
self.draw
.shaded_round_frame(self.pass, outer, inner, norm, col);
}
}
/// Drawing commands for shaded shapes
///
/// This trait is an extension over [`DrawImpl`] providing solid shaded shapes.
///
/// Some drawing primitives (the "round" ones) are partially transparent.
/// If the implementation buffers draw commands, it should draw these
/// primitives after solid primitives.
///
/// Methods are parameterised via a pair of normals, `(inner, outer)`. These may
/// have values from the closed range `[-1, 1]`, where -1 points inwards,
/// 0 is perpendicular to the screen towards the viewer, and 1 points outwards.
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
pub trait DrawShadedImpl: DrawImpl {
/// Add a shaded square to the draw buffer
fn shaded_square(&mut self, pass: PassId, rect: Quad, norm: (f32, f32), col: Rgba);
/// Add a shaded circle to the draw buffer
fn shaded_circle(&mut self, pass: PassId, rect: Quad, norm: (f32, f32), col: Rgba);
/// Add a square shaded frame to the draw buffer.
fn shaded_square_frame(
&mut self,
pass: PassId,
outer: Quad,
inner: Quad,
norm: (f32, f32),
outer_col: Rgba,
inner_col: Rgba,
);
/// Add a rounded shaded frame to the draw buffer.
fn shaded_round_frame(
&mut self,
pass: PassId,
outer: Quad,
inner: Quad,
norm: (f32, f32),
col: Rgba,
);
}