use quicksilver::{
geom::{Rectangle, Vector},
graphics::blend::{BlendChannel, BlendFactor, BlendFunction, BlendInput, BlendMode},
graphics::{Color, Image},
run, Graphics, Input, Result, Settings, Window,
};
fn main() {
run(
Settings {
title: "Blend Example",
..Settings::default()
},
app,
);
}
async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> {
let image = Image::load(&gfx, "image.png").await?;
gfx.clear(Color::WHITE);
gfx.set_blend_mode(Some(BlendMode {
equation: Default::default(),
function: BlendFunction::Same {
source: BlendFactor::Color {
input: BlendInput::Source,
channel: BlendChannel::Alpha,
is_inverse: false,
},
destination: BlendFactor::Color {
input: BlendInput::Source,
channel: BlendChannel::Alpha,
is_inverse: true,
},
},
global_color: [0.0; 4],
}));
let region = Rectangle::new(Vector::new(200.0, 200.0), image.size());
gfx.draw_image(&image, region);
gfx.fill_rect(®ion, Color::RED.with_alpha(0.5));
gfx.set_blend_mode(Some(BlendMode {
equation: Default::default(),
function: BlendFunction::Same {
source: BlendFactor::One,
destination: BlendFactor::Zero,
},
global_color: [0.0; 4],
}));
let region = Rectangle::new(Vector::new(400.0, 300.0), image.size());
gfx.draw_image(&image, region);
gfx.fill_rect(®ion, Color::RED.with_alpha(0.5));
gfx.present(&window)?;
loop {
while let Some(_) = input.next_event().await {}
}
}