render: add opacity to surfaces

This commit is contained in:
Victoria Fischer 2024-11-24 18:51:51 +01:00
parent 43c3344418
commit b5e1b114f6
2 changed files with 15 additions and 2 deletions

View File

@ -12,7 +12,8 @@ use std::sync::{Arc, Mutex};
#[derive(Debug)] #[derive(Debug)]
pub struct ShaderBinding { pub struct ShaderBinding {
shader: Option<Box<dyn Shader>>, shader: Option<Box<dyn Shader>>,
rect: Rectangle<u8, Virtual> rect: Rectangle<u8, Virtual>,
opacity: u8
} }
#[derive(Clone)] #[derive(Clone)]
@ -24,6 +25,7 @@ impl Debug for BoundSurface<Rc<RefCell<ShaderBinding>>> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BoundSurface") f.debug_struct("BoundSurface")
.field("shader", &self.binding.borrow().shader) .field("shader", &self.binding.borrow().shader)
.field("opacity", &self.binding.borrow().opacity)
.finish() .finish()
} }
} }
@ -35,7 +37,8 @@ impl Default for BoundSurface<Rc<RefCell<ShaderBinding>>>{
Self { Self {
binding: Rc::new(RefCell::new(ShaderBinding { binding: Rc::new(RefCell::new(ShaderBinding {
shader: None, shader: None,
rect: Rectangle::everything() rect: Rectangle::everything(),
opacity: 255
})), })),
} }
} }
@ -63,6 +66,14 @@ impl Surface for BoundSurface<Rc<RefCell<ShaderBinding>>> {
fn set_rect(&mut self, rect: &Rectangle<u8, Virtual>) { fn set_rect(&mut self, rect: &Rectangle<u8, Virtual>) {
self.binding.borrow_mut().rect = rect.clone(); 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")] #[cfg(feature="threads")]

View File

@ -23,6 +23,8 @@ pub trait Surface: Default + Clone + Debug {
fn rect(&self) -> Rectangle<u8, Virtual>; fn rect(&self) -> Rectangle<u8, Virtual>;
fn set_rect(&mut self, rect: &Rectangle<u8, Virtual>); fn set_rect(&mut self, rect: &Rectangle<u8, Virtual>);
fn opacity(&self) -> u8;
fn set_opacity(&mut self, opacity: u8);
} }
pub trait Framed { pub trait Framed {