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)]
pub struct ShaderBinding {
shader: Option<Box<dyn Shader>>,
rect: Rectangle<u8, Virtual>
rect: Rectangle<u8, Virtual>,
opacity: u8
}
#[derive(Clone)]
@ -24,6 +25,7 @@ impl Debug for BoundSurface<Rc<RefCell<ShaderBinding>>> {
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<Rc<RefCell<ShaderBinding>>>{
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<Rc<RefCell<ShaderBinding>>> {
fn set_rect(&mut self, rect: &Rectangle<u8, Virtual>) {
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")]

View File

@ -23,6 +23,8 @@ pub trait Surface: Default + Clone + Debug {
fn rect(&self) -> 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 {