From 40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 29 Sep 2022 10:52:58 -0700 Subject: Adds linear gradient support to 2D meshes in the canvas widget. --- graphics/src/shader.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 graphics/src/shader.rs (limited to 'graphics/src/shader.rs') diff --git a/graphics/src/shader.rs b/graphics/src/shader.rs new file mode 100644 index 00000000..b9071c74 --- /dev/null +++ b/graphics/src/shader.rs @@ -0,0 +1,42 @@ +//! Supported shaders; + +use crate::{Color, widget}; +use crate::gradient::Gradient; +use crate::widget::canvas::{FillStyle, StrokeStyle}; + +#[derive(Debug, Clone)] +/// Supported shaders for primitives. +pub enum Shader { + /// Fill a primitive with a solid color. + Solid(Color), + /// Fill a primitive with an interpolated color. + Gradient(Gradient) +} + +impl <'a> Into for StrokeStyle<'a> { + fn into(self) -> Shader { + match self { + StrokeStyle::Solid(color) => Shader::Solid(color), + StrokeStyle::Gradient(gradient) => gradient.clone().into() + } + } +} + +impl <'a> Into for FillStyle<'a> { + fn into(self) -> Shader { + match self { + FillStyle::Solid(color) => Shader::Solid(color), + FillStyle::Gradient(gradient) => gradient.clone().into() + } + } +} + +impl <'a> Into for widget::canvas::Gradient { + fn into(self) -> Shader { + match self { + widget::canvas::Gradient::Linear(linear) => { + Shader::Gradient(Gradient::Linear(linear)) + } + } + } +} \ No newline at end of file -- cgit