diff --git a/api/src/persistence/source.rs b/api/src/persistence/source.rs index 691ce4e6e..4dd1e01ad 100644 --- a/api/src/persistence/source.rs +++ b/api/src/persistence/source.rs @@ -325,48 +325,52 @@ pub struct StreamDeckButtonDesign { #[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)] #[serde(tag = "kind")] pub enum StreamDeckButtonForeground { - Solid(StreamDeckButtonSolidForeground), - Image(StreamDeckButtonImageForeground), - Bar(StreamDeckButtonBarForeground), + FadingColor(StreamDeckButtonFadingColorForeground), + FadingImage(StreamDeckButtonFadingImageForeground), + FullBar(StreamDeckButtonFullBarForeground), Arc(StreamDeckButtonArcForeground), } impl Default for StreamDeckButtonForeground { fn default() -> Self { - Self::Solid(StreamDeckButtonSolidForeground::default()) + Self::FadingColor(StreamDeckButtonFadingColorForeground::default()) } } #[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)] #[serde(tag = "kind")] pub enum StreamDeckButtonBackground { - Solid(StreamDeckButtonSolidBackground), + Color(StreamDeckButtonColorBackground), Image(StreamDeckButtonImageBackground), } impl Default for StreamDeckButtonBackground { fn default() -> Self { - Self::Solid(StreamDeckButtonSolidBackground::default()) + Self::Color(StreamDeckButtonColorBackground::default()) } } #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, Serialize, Deserialize)] -pub struct StreamDeckButtonImageForeground {} +pub struct StreamDeckButtonFadingImageForeground { + pub path: String, +} #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, Serialize, Deserialize)] -pub struct StreamDeckButtonSolidForeground {} +pub struct StreamDeckButtonFadingColorForeground {} #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, Serialize, Deserialize)] -pub struct StreamDeckButtonBarForeground {} +pub struct StreamDeckButtonFullBarForeground {} #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, Serialize, Deserialize)] pub struct StreamDeckButtonArcForeground {} #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, Serialize, Deserialize)] -pub struct StreamDeckButtonImageBackground {} +pub struct StreamDeckButtonImageBackground { + pub path: String, +} #[derive(Clone, Eq, PartialEq, Debug, Hash, Default, Serialize, Deserialize)] -pub struct StreamDeckButtonSolidBackground {} +pub struct StreamDeckButtonColorBackground {} #[derive(Copy, Clone, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct Keystroke { diff --git a/main/src/application/source_model.rs b/main/src/application/source_model.rs index 35b4dd173..4b5174a1a 100644 --- a/main/src/application/source_model.rs +++ b/main/src/application/source_model.rs @@ -744,7 +744,7 @@ impl SourceModel { StreamDeckButtonDesign { background: match self.button_background_type { StreamDeckButtonBackgroundType::Solid => { - StreamDeckButtonBackground::Solid(Default::default()) + StreamDeckButtonBackground::Color(Default::default()) } StreamDeckButtonBackgroundType::Image => { StreamDeckButtonBackground::Image(Default::default()) @@ -752,13 +752,13 @@ impl SourceModel { }, foreground: match self.button_foreground_type { StreamDeckButtonForegroundType::Solid => { - StreamDeckButtonForeground::Solid(Default::default()) + StreamDeckButtonForeground::FadingColor(Default::default()) } StreamDeckButtonForegroundType::Image => { - StreamDeckButtonForeground::Image(Default::default()) + StreamDeckButtonForeground::FadingImage(Default::default()) } StreamDeckButtonForegroundType::Bar => { - StreamDeckButtonForeground::Bar(Default::default()) + StreamDeckButtonForeground::FullBar(Default::default()) } StreamDeckButtonForegroundType::Arc => { StreamDeckButtonForeground::Arc(Default::default()) @@ -1322,7 +1322,7 @@ pub enum StreamDeckButtonBackgroundType { impl From<&StreamDeckButtonBackground> for StreamDeckButtonBackgroundType { fn from(value: &StreamDeckButtonBackground) -> Self { match value { - StreamDeckButtonBackground::Solid(_) => Self::Solid, + StreamDeckButtonBackground::Color(_) => Self::Solid, StreamDeckButtonBackground::Image(_) => Self::Image, } } @@ -1343,10 +1343,10 @@ pub enum StreamDeckButtonForegroundType { impl From<&StreamDeckButtonForeground> for StreamDeckButtonForegroundType { fn from(value: &StreamDeckButtonForeground) -> Self { match value { - StreamDeckButtonForeground::Solid(_) => Self::Solid, - StreamDeckButtonForeground::Image(_) => Self::Image, + StreamDeckButtonForeground::FadingColor(_) => Self::Solid, + StreamDeckButtonForeground::FadingImage(_) => Self::Image, StreamDeckButtonForeground::Arc(_) => Self::Arc, - StreamDeckButtonForeground::Bar(_) => Self::Bar, + StreamDeckButtonForeground::FullBar(_) => Self::Bar, } } } diff --git a/main/src/domain/backbone.rs b/main/src/domain/backbone.rs index 015aa0edb..86870e7dc 100644 --- a/main/src/domain/backbone.rs +++ b/main/src/domain/backbone.rs @@ -248,16 +248,16 @@ impl Backbone { // Paint background let bg_color = value.background_color.unwrap_or(DEFAULT_BG_COLOR); let mut img: ImageBuffer, _> = match value.button_design.background { - StreamDeckButtonBackground::Solid(_) => { + StreamDeckButtonBackground::Color(_) => { ImageBuffer::from_pixel(width, height, bg_color.into()) } - StreamDeckButtonBackground::Image(_) => ImageBuffer::default(), + StreamDeckButtonBackground::Image(b) => image::open(b.path).unwrap().into(), }; // Paint foreground if value.numeric_value.is_some() || value.text_value.is_some() { let fg_color = value.foreground_color.unwrap_or(DEFAULT_FG_COLOR); match value.button_design.foreground { - StreamDeckButtonForeground::Solid(_) => { + StreamDeckButtonForeground::FadingColor(_) => { let opacity = value.numeric_value.unwrap_or(UnitValue::MAX); let mut rgba: Rgba = fg_color.into(); rgba[3] = (opacity.get() * 255.0).round() as u8; @@ -265,8 +265,8 @@ impl Backbone { pixel.blend(&rgba); } } - StreamDeckButtonForeground::Image(_) => {} - StreamDeckButtonForeground::Bar(_) => { + StreamDeckButtonForeground::FadingImage(_) => {} + StreamDeckButtonForeground::FullBar(_) => { let percentage = value.numeric_value.map(|v| v.get()).unwrap_or(0.0); let rect_height = (height as f64 * percentage) as u32; // Fill the background