From b5e1b114f6e0ad5bd3cd149eb824edda9d167c8f Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sun, 24 Nov 2024 18:51:51 +0100 Subject: [PATCH] render: add opacity to surfaces --- src/buffers.rs | 15 +++++++++++++-- src/render.rs | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/buffers.rs b/src/buffers.rs index eee4c37..04ad382 100644 --- a/src/buffers.rs +++ b/src/buffers.rs @@ -12,7 +12,8 @@ use std::sync::{Arc, Mutex}; #[derive(Debug)] pub struct ShaderBinding { shader: Option>, - rect: Rectangle + rect: Rectangle, + opacity: u8 } #[derive(Clone)] @@ -24,6 +25,7 @@ impl Debug for BoundSurface>> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("BoundSurface") .field("shader", &self.binding.borrow().shader) + .field("opacity", &self.binding.borrow().opacity) .finish() } } @@ -35,7 +37,8 @@ impl Default for BoundSurface>>{ Self { binding: Rc::new(RefCell::new(ShaderBinding { shader: None, - rect: Rectangle::everything() + rect: Rectangle::everything(), + opacity: 255 })), } } @@ -63,6 +66,14 @@ impl Surface for BoundSurface>> { fn set_rect(&mut self, rect: &Rectangle) { self.binding.borrow_mut().rect = rect.clone(); } + + fn opacity(&self) -> u8 { + self.binding.borrow().opacity + } + + fn set_opacity(&mut self, opacity: u8) { + self.binding.borrow_mut().opacity = opacity + } } #[cfg(feature="threads")] diff --git a/src/render.rs b/src/render.rs index c7fd76d..3a75cd4 100644 --- a/src/render.rs +++ b/src/render.rs @@ -23,6 +23,8 @@ pub trait Surface: Default + Clone + Debug { fn rect(&self) -> Rectangle; fn set_rect(&mut self, rect: &Rectangle); + fn opacity(&self) -> u8; + fn set_opacity(&mut self, opacity: u8); } pub trait Framed {