Change vector drawing primitive from shape to doubly-connected edge graph
This commit is contained in:
@@ -10,7 +10,6 @@ use eframe::egui;
|
||||
use lightningbeam_core::clip::{AudioClipType, VectorClip};
|
||||
use lightningbeam_core::document::Document;
|
||||
use lightningbeam_core::layer::AnyLayer;
|
||||
use lightningbeam_core::shape::ShapeColor;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -413,8 +412,7 @@ fn generate_midi_thumbnail(
|
||||
/// Generate a 64x64 RGBA thumbnail for a vector clip
|
||||
/// Renders frame 0 of the clip using tiny-skia for software rendering
|
||||
fn generate_vector_thumbnail(clip: &VectorClip, bg_color: egui::Color32) -> Vec<u8> {
|
||||
use kurbo::PathEl;
|
||||
use tiny_skia::{Paint, PathBuilder, Pixmap, Transform as TsTransform};
|
||||
use tiny_skia::Pixmap;
|
||||
|
||||
let size = THUMBNAIL_SIZE as usize;
|
||||
let mut pixmap = Pixmap::new(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
|
||||
@@ -431,94 +429,14 @@ fn generate_vector_thumbnail(clip: &VectorClip, bg_color: egui::Color32) -> Vec<
|
||||
// Calculate scale to fit clip dimensions into thumbnail
|
||||
let scale_x = THUMBNAIL_SIZE as f64 / clip.width.max(1.0);
|
||||
let scale_y = THUMBNAIL_SIZE as f64 / clip.height.max(1.0);
|
||||
let scale = scale_x.min(scale_y) * 0.9; // 90% to leave a small margin
|
||||
|
||||
// Center offset
|
||||
let offset_x = (THUMBNAIL_SIZE as f64 - clip.width * scale) / 2.0;
|
||||
let offset_y = (THUMBNAIL_SIZE as f64 - clip.height * scale) / 2.0;
|
||||
let _scale = scale_x.min(scale_y) * 0.9; // 90% to leave a small margin
|
||||
|
||||
// Iterate through layers and render shapes
|
||||
for layer_node in clip.layers.iter() {
|
||||
if let AnyLayer::Vector(vector_layer) = &layer_node.data {
|
||||
// Render each shape at time 0.0 (frame 0)
|
||||
for shape in vector_layer.shapes_at_time(0.0) {
|
||||
// Get the path (frame 0)
|
||||
let kurbo_path = shape.path();
|
||||
|
||||
// Convert kurbo BezPath to tiny-skia PathBuilder
|
||||
let mut path_builder = PathBuilder::new();
|
||||
for el in kurbo_path.iter() {
|
||||
match el {
|
||||
PathEl::MoveTo(p) => {
|
||||
let x = (p.x * scale + offset_x) as f32;
|
||||
let y = (p.y * scale + offset_y) as f32;
|
||||
path_builder.move_to(x, y);
|
||||
}
|
||||
PathEl::LineTo(p) => {
|
||||
let x = (p.x * scale + offset_x) as f32;
|
||||
let y = (p.y * scale + offset_y) as f32;
|
||||
path_builder.line_to(x, y);
|
||||
}
|
||||
PathEl::QuadTo(p1, p2) => {
|
||||
let x1 = (p1.x * scale + offset_x) as f32;
|
||||
let y1 = (p1.y * scale + offset_y) as f32;
|
||||
let x2 = (p2.x * scale + offset_x) as f32;
|
||||
let y2 = (p2.y * scale + offset_y) as f32;
|
||||
path_builder.quad_to(x1, y1, x2, y2);
|
||||
}
|
||||
PathEl::CurveTo(p1, p2, p3) => {
|
||||
let x1 = (p1.x * scale + offset_x) as f32;
|
||||
let y1 = (p1.y * scale + offset_y) as f32;
|
||||
let x2 = (p2.x * scale + offset_x) as f32;
|
||||
let y2 = (p2.y * scale + offset_y) as f32;
|
||||
let x3 = (p3.x * scale + offset_x) as f32;
|
||||
let y3 = (p3.y * scale + offset_y) as f32;
|
||||
path_builder.cubic_to(x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
PathEl::ClosePath => {
|
||||
path_builder.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ts_path) = path_builder.finish() {
|
||||
// Draw fill if present
|
||||
if let Some(fill_color) = &shape.fill_color {
|
||||
let mut paint = Paint::default();
|
||||
paint.set_color(shape_color_to_tiny_skia(fill_color));
|
||||
paint.anti_alias = true;
|
||||
pixmap.fill_path(
|
||||
&ts_path,
|
||||
&paint,
|
||||
tiny_skia::FillRule::Winding,
|
||||
TsTransform::identity(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
// Draw stroke if present
|
||||
if let Some(stroke_color) = &shape.stroke_color {
|
||||
if let Some(stroke_style) = &shape.stroke_style {
|
||||
let mut paint = Paint::default();
|
||||
paint.set_color(shape_color_to_tiny_skia(stroke_color));
|
||||
paint.anti_alias = true;
|
||||
|
||||
let stroke = tiny_skia::Stroke {
|
||||
width: (stroke_style.width * scale) as f32,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
pixmap.stroke_path(
|
||||
&ts_path,
|
||||
&paint,
|
||||
&stroke,
|
||||
TsTransform::identity(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: DCEL - thumbnail shape rendering disabled during migration
|
||||
// (was: shapes_at_time(0.0) to render shape fills/strokes into thumbnail)
|
||||
let _ = vector_layer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,11 +459,6 @@ fn generate_vector_thumbnail(clip: &VectorClip, bg_color: egui::Color32) -> Vec<
|
||||
rgba
|
||||
}
|
||||
|
||||
/// Convert ShapeColor to tiny_skia Color
|
||||
fn shape_color_to_tiny_skia(color: &ShapeColor) -> tiny_skia::Color {
|
||||
tiny_skia::Color::from_rgba8(color.r, color.g, color.b, color.a)
|
||||
}
|
||||
|
||||
/// Generate a simple effect thumbnail with a pink gradient
|
||||
#[allow(dead_code)]
|
||||
fn generate_effect_thumbnail() -> Vec<u8> {
|
||||
|
||||
@@ -114,84 +114,9 @@ impl InfopanelPane {
|
||||
if let Some(layer) = document.get_layer(&layer_id) {
|
||||
if let AnyLayer::Vector(vector_layer) = layer {
|
||||
// Gather values from all selected instances
|
||||
let mut first = true;
|
||||
|
||||
for instance_id in &info.instance_ids {
|
||||
if let Some(shape) = vector_layer.get_shape_in_keyframe(instance_id, *shared.playback_time) {
|
||||
info.shape_ids.push(*instance_id);
|
||||
|
||||
if first {
|
||||
// First shape - set initial values
|
||||
info.x = Some(shape.transform.x);
|
||||
info.y = Some(shape.transform.y);
|
||||
info.rotation = Some(shape.transform.rotation);
|
||||
info.scale_x = Some(shape.transform.scale_x);
|
||||
info.scale_y = Some(shape.transform.scale_y);
|
||||
info.skew_x = Some(shape.transform.skew_x);
|
||||
info.skew_y = Some(shape.transform.skew_y);
|
||||
info.opacity = Some(shape.opacity);
|
||||
|
||||
// Get shape properties
|
||||
info.fill_color = Some(shape.fill_color);
|
||||
info.stroke_color = Some(shape.stroke_color);
|
||||
info.stroke_width = shape
|
||||
.stroke_style
|
||||
.as_ref()
|
||||
.map(|s| Some(s.width))
|
||||
.unwrap_or(Some(1.0));
|
||||
|
||||
first = false;
|
||||
} else {
|
||||
// Check if values differ (set to None if mixed)
|
||||
if info.x != Some(shape.transform.x) {
|
||||
info.x = None;
|
||||
}
|
||||
if info.y != Some(shape.transform.y) {
|
||||
info.y = None;
|
||||
}
|
||||
if info.rotation != Some(shape.transform.rotation) {
|
||||
info.rotation = None;
|
||||
}
|
||||
if info.scale_x != Some(shape.transform.scale_x) {
|
||||
info.scale_x = None;
|
||||
}
|
||||
if info.scale_y != Some(shape.transform.scale_y) {
|
||||
info.scale_y = None;
|
||||
}
|
||||
if info.skew_x != Some(shape.transform.skew_x) {
|
||||
info.skew_x = None;
|
||||
}
|
||||
if info.skew_y != Some(shape.transform.skew_y) {
|
||||
info.skew_y = None;
|
||||
}
|
||||
if info.opacity != Some(shape.opacity) {
|
||||
info.opacity = None;
|
||||
}
|
||||
|
||||
// Check shape properties
|
||||
// Compare fill colors - set to None if mixed
|
||||
if let Some(current_fill) = &info.fill_color {
|
||||
if *current_fill != shape.fill_color {
|
||||
info.fill_color = None;
|
||||
}
|
||||
}
|
||||
// Compare stroke colors - set to None if mixed
|
||||
if let Some(current_stroke) = &info.stroke_color {
|
||||
if *current_stroke != shape.stroke_color {
|
||||
info.stroke_color = None;
|
||||
}
|
||||
}
|
||||
let stroke_w = shape
|
||||
.stroke_style
|
||||
.as_ref()
|
||||
.map(|s| s.width)
|
||||
.unwrap_or(1.0);
|
||||
if info.stroke_width != Some(stroke_w) {
|
||||
info.stroke_width = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: DCEL - shape property gathering disabled during migration
|
||||
// (was: get_shape_in_keyframe to gather transform/fill/stroke properties)
|
||||
let _ = vector_layer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user