Paint bucket

This commit is contained in:
Skyler Lehmkuhl
2026-03-07 02:53:47 -05:00
parent 4386917fc2
commit 1e80b1bc77
6 changed files with 379 additions and 28 deletions
@@ -32,6 +32,7 @@ pub mod region_split;
pub mod toggle_group_expansion;
pub mod group_layers;
pub mod raster_stroke;
pub mod raster_fill;
pub mod move_layer;
pub use add_clip_instance::AddClipInstanceAction;
@@ -63,4 +64,5 @@ pub use region_split::RegionSplitAction;
pub use toggle_group_expansion::ToggleGroupExpansionAction;
pub use group_layers::GroupLayersAction;
pub use raster_stroke::RasterStrokeAction;
pub use raster_fill::RasterFillAction;
pub use move_layer::MoveLayerAction;
@@ -0,0 +1,58 @@
//! Raster flood-fill action — records and undoes a paint bucket fill on a RasterLayer.
use crate::action::Action;
use crate::document::Document;
use crate::layer::AnyLayer;
use uuid::Uuid;
pub struct RasterFillAction {
layer_id: Uuid,
time: f64,
buffer_before: Vec<u8>,
buffer_after: Vec<u8>,
width: u32,
height: u32,
}
impl RasterFillAction {
pub fn new(
layer_id: Uuid,
time: f64,
buffer_before: Vec<u8>,
buffer_after: Vec<u8>,
width: u32,
height: u32,
) -> Self {
Self { layer_id, time, buffer_before, buffer_after, width, height }
}
}
impl Action for RasterFillAction {
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
let layer = document.get_layer_mut(&self.layer_id)
.ok_or_else(|| format!("Layer {} not found", self.layer_id))?;
let raster = match layer {
AnyLayer::Raster(rl) => rl,
_ => return Err("Not a raster layer".to_string()),
};
let kf = raster.ensure_keyframe_at(self.time, self.width, self.height);
kf.raw_pixels = self.buffer_after.clone();
Ok(())
}
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
let layer = document.get_layer_mut(&self.layer_id)
.ok_or_else(|| format!("Layer {} not found", self.layer_id))?;
let raster = match layer {
AnyLayer::Raster(rl) => rl,
_ => return Err("Not a raster layer".to_string()),
};
let kf = raster.ensure_keyframe_at(self.time, self.width, self.height);
kf.raw_pixels = self.buffer_before.clone();
Ok(())
}
fn description(&self) -> String {
"Flood fill".to_string()
}
}