Transparency works now and my brain is too fried to explain why
This commit is contained in:
@@ -42,8 +42,8 @@ pub fn color_over(over: u32, under: u32) -> u32 {
|
|||||||
let g_under = (under & 0x0000ff00) >> 8;
|
let g_under = (under & 0x0000ff00) >> 8;
|
||||||
let b_over = (over & 0x000000ff) >> 0;
|
let b_over = (over & 0x000000ff) >> 0;
|
||||||
let b_under = (under & 0x000000ff) >> 0;
|
let b_under = (under & 0x000000ff) >> 0;
|
||||||
((a_over + (a_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 24).min(0xff) +
|
((a_over + (a_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 24) +
|
||||||
((r_over + (r_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 16).min(0xff) +
|
((r_over + (r_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 16) +
|
||||||
((g_over + (g_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 8) +
|
((g_over + (g_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 8) +
|
||||||
((b_over + (b_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 0)
|
((b_over + (b_under as f64 * (0xff - a_over) as f64 / 0xff as f64) as u32).min(0xff) << 0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,12 +81,34 @@ impl ShmPool {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write_raw(&mut self, color: u32, offset: usize, len: usize) {
|
||||||
|
if offset + len/4 >= self.size {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for i in offset..offset+len { unsafe {
|
||||||
|
*((self.addr as *mut u32).offset(i as isize)) = color;
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn write_pixel(&mut self, color: u32, offset: usize) {
|
pub fn write_pixel(&mut self, color: u32, offset: usize) {
|
||||||
// TODO: Return error if out of bounds
|
// TODO: Return error if out of bounds
|
||||||
if offset + 3 > self.size {
|
if offset + 3 > self.size {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsafe {*((self.addr as *mut u32).offset(offset as isize)) = color;}
|
unsafe {
|
||||||
|
*((self.addr as *mut u32).offset(offset as isize))
|
||||||
|
= color_over(color, self.read_pixel(offset).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_pixel_raw(&mut self, color: u32, offset: usize) {
|
||||||
|
// TODO: Return error if out of bounds
|
||||||
|
if offset + 3 > self.size {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
*((self.addr as *mut u32).offset(offset as isize)) = color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_pixel(&self, offset: usize) -> Option<u32> {
|
pub fn read_pixel(&self, offset: usize) -> Option<u32> {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ impl WlClient {
|
|||||||
self.wl_surface_attach(buffer)?;
|
self.wl_surface_attach(buffer)?;
|
||||||
let mut drawables = self.drawables.lock()?;
|
let mut drawables = self.drawables.lock()?;
|
||||||
let mut shm_pool = self.shm_pool.lock()?;
|
let mut shm_pool = self.shm_pool.lock()?;
|
||||||
shm_pool.write(0, 0, 800 * 800 * 2);
|
shm_pool.write_raw(0, 0, 800 * 800 * 2);
|
||||||
for drawable in &mut *drawables {
|
for drawable in &mut *drawables {
|
||||||
drawable.update();
|
drawable.update();
|
||||||
drawable.draw(buffer, &mut *shm_pool);
|
drawable.draw(buffer, &mut *shm_pool);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ impl WlClient {
|
|||||||
arc_wl_client.wl_display_get_registry();
|
arc_wl_client.wl_display_get_registry();
|
||||||
if let Ok(mut drawables) = arc_wl_client.drawables.lock() {
|
if let Ok(mut drawables) = arc_wl_client.drawables.lock() {
|
||||||
drawables.push(Rectangle::new(50, 50, 300, 300, 16, 0xffff8800).into());
|
drawables.push(Rectangle::new(50, 50, 300, 300, 16, 0xffff8800).into());
|
||||||
drawables.push(Rectangle::new(350, 50, 300, 300, 16, 0xffaa22aa).into());
|
drawables.push(Rectangle::new(350, 50, 300, 300, 16, premultiply(0x77aa22aa)).into());
|
||||||
drawables.push(Circle::new(350, 80, 25, premultiply(0xff00ffff)).into());
|
drawables.push(Circle::new(350, 80, 25, premultiply(0xff00ffff)).into());
|
||||||
drawables.push(Circle::new(350, 160, 25, premultiply(0x8800ffff)).into());
|
drawables.push(Circle::new(350, 160, 25, premultiply(0x8800ffff)).into());
|
||||||
drawables.push(Circle::new(350, 240, 25, premultiply(0x0000ffff)).into());
|
drawables.push(Circle::new(350, 240, 25, premultiply(0x0000ffff)).into());
|
||||||
|
|||||||
Reference in New Issue
Block a user