diff --git a/src/graphics/circle.rs b/src/graphics/circle.rs index 398e5cf..93e8207 100644 --- a/src/graphics/circle.rs +++ b/src/graphics/circle.rs @@ -17,7 +17,7 @@ impl Circle { impl Drawable for Circle { fn update(&mut self) { - self.x += 1; + // self.x += 1; } fn draw(&self, buffer: &wl_buffer, shm_pool: &mut ShmPool) { diff --git a/src/graphics/drawable.rs b/src/graphics/drawable.rs index 3f7039e..e6315c7 100644 --- a/src/graphics/drawable.rs +++ b/src/graphics/drawable.rs @@ -1,12 +1,9 @@ use crate::wayland::{shm::ShmPool, wl_shm::wl_buffer}; -pub fn color_blend(col1: u32, col2: u32, diff: f64) -> u32 { - // TODO: Account for alpha channel - let a1 = (col1 & 0xff000000) >> 24; +pub fn rgb_blend(col1: u32, col2: u32, diff: f64) -> u32 { let r1 = (col1 & 0x00ff0000) >> 16; let g1 = (col1 & 0x0000ff00) >> 8; let b1 = col1 & 0x000000ff; - let a2 = (col2 & 0xff000000) >> 24; let r2 = (col2 & 0x00ff0000) >> 16; let g2 = (col2 & 0x0000ff00) >> 8; let b2 = col2 & 0x000000ff; @@ -25,7 +22,13 @@ pub fn color_blend(col1: u32, col2: u32, diff: f64) -> u32 { } else { b1 - ((b1 - b2) as f64 * diff) as u32 }; - return 0xff000000 + (r3 << 16) + (g3 << 8) + b3; + (r3 << 16) + (g3 << 8) + b3 +} + +pub fn color_blend(col1: u32, col2: u32, diff: f64) -> u32 { + let a1 = (col1 & 0xff000000) >> 24; + let a2 = (col2 & 0xff000000) >> 24; + ((a2 + ((a1 as f64/0xff as f64)*(0xff - a2) as f64*(1.0-diff)) as u32) << 24) + rgb_blend(col1, col2, diff * (a1 as f64 / 0xff as f64)) } pub trait Drawable : Send { diff --git a/src/wayland/wl_client.rs b/src/wayland/wl_client.rs index e73fb88..94dcf42 100644 --- a/src/wayland/wl_client.rs +++ b/src/wayland/wl_client.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, env::var, error::Error, fmt::Debug, io::{IoSliceMut, Write}, os::unix::net::{AncillaryData, SocketAncillary, UnixStream}, sync::{atomic::{AtomicBool, AtomicU32, Ordering}, mpsc, Arc, Mutex, RwLock}, thread::{self}, time::Duration, u32}; +use std::{collections::HashMap, env::var, error::Error, fmt::Debug, io::{IoSliceMut, Write}, os::unix::net::{AncillaryData, SocketAncillary, UnixStream}, sync::{atomic::{AtomicBool, AtomicU32, Ordering}, mpsc, Arc, Mutex, RwLock}, thread::{self}, u32}; use crate::{graphics::{circle::Circle, drawable::Drawable, rectangle::Rectangle}, wayland::{shm, surface::UnsetErr, vec_utils::WlMessage, wl_shm::wl_buffer}}; @@ -67,7 +67,10 @@ impl WlClient { arc_wl_client.wl_display_get_registry(); if let Ok(mut drawables) = arc_wl_client.drawables.lock() { drawables.push(Rectangle::new(50, 50, 300, 300, 16, 0xffff8800).into()); - drawables.push(Circle::new(150, 80, 25, 0xff00ffff).into()); + drawables.push(Rectangle::new(350, 50, 300, 300, 16, 0xffaa22aa).into()); + drawables.push(Circle::new(350, 80, 25, 0xff00ffff).into()); + drawables.push(Circle::new(350, 160, 25, 0x8800ffff).into()); + drawables.push(Circle::new(350, 240, 25, 0x0000ffff).into()); } arc_wl_client.running.store(true, Ordering::Relaxed);