2020-12-29 00:13:14 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
2021-01-10 10:37:47 +00:00
|
|
|
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
2020-12-29 00:13:14 +00:00
|
|
|
pub struct Shadow {
|
|
|
|
// The shadow extends this much outside the rect.
|
|
|
|
pub extrusion: f32,
|
2021-01-02 16:02:18 +00:00
|
|
|
pub color: Color32,
|
2020-12-29 00:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Shadow {
|
|
|
|
/// Tooltips, menus, ...
|
|
|
|
pub fn small() -> Self {
|
|
|
|
Self {
|
|
|
|
extrusion: 8.0,
|
2021-01-03 17:03:11 +00:00
|
|
|
color: Color32::from_black_alpha(64),
|
2020-12-29 00:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Windows
|
|
|
|
pub fn big() -> Self {
|
|
|
|
Self {
|
|
|
|
extrusion: 32.0,
|
2021-01-03 17:03:11 +00:00
|
|
|
color: Color32::from_black_alpha(96),
|
2020-12-29 00:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-10 14:42:46 +00:00
|
|
|
pub fn tessellate(&self, rect: emath::Rect, corner_radius: f32) -> Triangles {
|
2020-12-29 00:13:14 +00:00
|
|
|
// tessellator.clip_rect = clip_rect; // TODO: culling
|
|
|
|
|
|
|
|
let Self { extrusion, color } = *self;
|
|
|
|
|
2021-01-10 14:42:46 +00:00
|
|
|
use crate::tessellator::*;
|
2020-12-29 00:13:14 +00:00
|
|
|
let rect = PaintRect {
|
|
|
|
rect: rect.expand(0.5 * extrusion),
|
|
|
|
corner_radius: corner_radius + 0.5 * extrusion,
|
|
|
|
fill: color,
|
|
|
|
stroke: Default::default(),
|
|
|
|
};
|
|
|
|
let mut tessellator = Tessellator::from_options(TessellationOptions {
|
|
|
|
aa_size: extrusion,
|
|
|
|
anti_alias: true,
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
let mut triangles = Triangles::default();
|
|
|
|
tessellator.tessellate_rect(&rect, &mut triangles);
|
|
|
|
triangles
|
|
|
|
}
|
|
|
|
}
|