Video import
This commit is contained in:
@@ -272,6 +272,70 @@ fn generate_waveform_thumbnail(
|
||||
rgba
|
||||
}
|
||||
|
||||
/// Generate a video thumbnail by decoding the first frame
|
||||
/// Returns a 64x64 RGBA thumbnail with letterboxing to maintain aspect ratio
|
||||
fn generate_video_thumbnail(
|
||||
clip_id: &uuid::Uuid,
|
||||
video_manager: &std::sync::Arc<std::sync::Mutex<lightningbeam_core::video::VideoManager>>,
|
||||
) -> Option<Vec<u8>> {
|
||||
// Get a frame from the video (at 1 second to skip potential black intros)
|
||||
let timestamp = 1.0;
|
||||
|
||||
let frame = {
|
||||
let mut video_mgr = video_manager.lock().ok()?;
|
||||
video_mgr.get_frame(clip_id, timestamp)?
|
||||
};
|
||||
|
||||
let src_width = frame.width as usize;
|
||||
let src_height = frame.height as usize;
|
||||
let dst_size = THUMBNAIL_SIZE as usize;
|
||||
|
||||
// Calculate letterboxing dimensions to maintain aspect ratio
|
||||
let src_aspect = src_width as f32 / src_height as f32;
|
||||
let (scaled_width, scaled_height, offset_x, offset_y) = if src_aspect > 1.0 {
|
||||
// Wide video - letterbox top and bottom
|
||||
let scaled_width = dst_size;
|
||||
let scaled_height = (dst_size as f32 / src_aspect) as usize;
|
||||
let offset_y = (dst_size - scaled_height) / 2;
|
||||
(scaled_width, scaled_height, 0, offset_y)
|
||||
} else {
|
||||
// Tall video - letterbox left and right
|
||||
let scaled_height = dst_size;
|
||||
let scaled_width = (dst_size as f32 * src_aspect) as usize;
|
||||
let offset_x = (dst_size - scaled_width) / 2;
|
||||
(scaled_width, scaled_height, offset_x, 0)
|
||||
};
|
||||
|
||||
// Create thumbnail with black letterbox bars
|
||||
let mut rgba = vec![0u8; dst_size * dst_size * 4];
|
||||
|
||||
let x_ratio = src_width as f32 / scaled_width as f32;
|
||||
let y_ratio = src_height as f32 / scaled_height as f32;
|
||||
|
||||
// Fill the scaled region
|
||||
for dst_y in 0..scaled_height {
|
||||
for dst_x in 0..scaled_width {
|
||||
let src_x = (dst_x as f32 * x_ratio) as usize;
|
||||
let src_y = (dst_y as f32 * y_ratio) as usize;
|
||||
let src_idx = (src_y * src_width + src_x) * 4;
|
||||
|
||||
let final_x = dst_x + offset_x;
|
||||
let final_y = dst_y + offset_y;
|
||||
let dst_idx = (final_y * dst_size + final_x) * 4;
|
||||
|
||||
// Copy RGBA bytes
|
||||
if src_idx + 3 < frame.rgba_data.len() && dst_idx + 3 < rgba.len() {
|
||||
rgba[dst_idx] = frame.rgba_data[src_idx];
|
||||
rgba[dst_idx + 1] = frame.rgba_data[src_idx + 1];
|
||||
rgba[dst_idx + 2] = frame.rgba_data[src_idx + 2];
|
||||
rgba[dst_idx + 3] = frame.rgba_data[src_idx + 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(rgba)
|
||||
}
|
||||
|
||||
/// Generate a piano roll thumbnail for MIDI clips
|
||||
/// Shows notes as horizontal bars with Y position = note % 12 (one octave)
|
||||
fn generate_midi_thumbnail(
|
||||
@@ -960,16 +1024,17 @@ impl AssetLibraryPane {
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
assets: &[&AssetEntry],
|
||||
document: &Document,
|
||||
) {
|
||||
match self.view_mode {
|
||||
AssetViewMode::List => {
|
||||
self.render_asset_list_view(ui, rect, shared, assets, document);
|
||||
self.render_asset_list_view(ui, rect, path, shared, assets, document);
|
||||
}
|
||||
AssetViewMode::Grid => {
|
||||
self.render_asset_grid_view(ui, rect, shared, assets, document);
|
||||
self.render_asset_grid_view(ui, rect, path, shared, assets, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -979,6 +1044,7 @@ impl AssetLibraryPane {
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
assets: &[&AssetEntry],
|
||||
document: &Document,
|
||||
@@ -1019,6 +1085,7 @@ impl AssetLibraryPane {
|
||||
let scroll_area_rect = rect;
|
||||
ui.allocate_ui_at_rect(scroll_area_rect, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt(("asset_list_scroll", path))
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
ui.set_min_width(scroll_area_rect.width() - 16.0); // Account for scrollbar
|
||||
@@ -1157,8 +1224,9 @@ impl AssetLibraryPane {
|
||||
.map(|clip| generate_vector_thumbnail(clip, bg_color))
|
||||
}
|
||||
AssetCategory::Video => {
|
||||
// Video backend not implemented yet - use placeholder
|
||||
Some(generate_placeholder_thumbnail(AssetCategory::Video, 200))
|
||||
// Generate video thumbnail from first frame
|
||||
generate_video_thumbnail(&asset_id, &shared.video_manager)
|
||||
.or_else(|| Some(generate_placeholder_thumbnail(AssetCategory::Video, 200)))
|
||||
}
|
||||
AssetCategory::Audio => {
|
||||
// Check if it's sampled or MIDI
|
||||
@@ -1287,6 +1355,7 @@ impl AssetLibraryPane {
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
assets: &[&AssetEntry],
|
||||
document: &Document,
|
||||
@@ -1335,6 +1404,7 @@ impl AssetLibraryPane {
|
||||
// Use egui's built-in ScrollArea for scrolling
|
||||
ui.allocate_ui_at_rect(rect, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt(("asset_grid_scroll", path))
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
// Reserve space for the entire grid
|
||||
@@ -1429,7 +1499,9 @@ impl AssetLibraryPane {
|
||||
.map(|clip| generate_vector_thumbnail(clip, bg_color))
|
||||
}
|
||||
AssetCategory::Video => {
|
||||
Some(generate_placeholder_thumbnail(AssetCategory::Video, 200))
|
||||
// Generate video thumbnail from first frame
|
||||
generate_video_thumbnail(&asset_id, &shared.video_manager)
|
||||
.or_else(|| Some(generate_placeholder_thumbnail(AssetCategory::Video, 200)))
|
||||
}
|
||||
AssetCategory::Audio => {
|
||||
if let Some(clip) = document.audio_clips.get(&asset_id) {
|
||||
@@ -1572,7 +1644,7 @@ impl PaneRenderer for AssetLibraryPane {
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
_path: &NodePath,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
) {
|
||||
// Get an Arc clone of the document for thumbnail generation
|
||||
@@ -1600,7 +1672,7 @@ impl PaneRenderer for AssetLibraryPane {
|
||||
// Render components
|
||||
self.render_search_bar(ui, search_rect, shared);
|
||||
self.render_category_tabs(ui, tabs_rect, shared);
|
||||
self.render_assets(ui, list_rect, shared, &filtered_assets, &document_arc);
|
||||
self.render_assets(ui, list_rect, path, shared, &filtered_assets, &document_arc);
|
||||
|
||||
// Context menu handling
|
||||
if let Some(ref context_state) = self.context_menu.clone() {
|
||||
|
||||
@@ -204,7 +204,7 @@ impl InfopanelPane {
|
||||
}
|
||||
|
||||
/// Render tool-specific options section
|
||||
fn render_tool_section(&mut self, ui: &mut Ui, shared: &mut SharedPaneState) {
|
||||
fn render_tool_section(&mut self, ui: &mut Ui, path: &NodePath, shared: &mut SharedPaneState) {
|
||||
let tool = *shared.selected_tool;
|
||||
|
||||
// Only show tool options for tools that have options
|
||||
@@ -218,6 +218,7 @@ impl InfopanelPane {
|
||||
}
|
||||
|
||||
egui::CollapsingHeader::new("Tool Options")
|
||||
.id_salt(("tool_options", path))
|
||||
.default_open(self.tool_section_open)
|
||||
.show(ui, |ui| {
|
||||
self.tool_section_open = true;
|
||||
@@ -234,7 +235,7 @@ impl InfopanelPane {
|
||||
// Simplify mode
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Simplify:");
|
||||
egui::ComboBox::from_id_salt("draw_simplify")
|
||||
egui::ComboBox::from_id_salt(("draw_simplify", path))
|
||||
.selected_text(match shared.draw_simplify_mode {
|
||||
SimplifyMode::Corners => "Corners",
|
||||
SimplifyMode::Smooth => "Smooth",
|
||||
@@ -325,10 +326,12 @@ impl InfopanelPane {
|
||||
fn render_transform_section(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
info: &SelectionInfo,
|
||||
) {
|
||||
egui::CollapsingHeader::new("Transform")
|
||||
.id_salt(("transform", path))
|
||||
.default_open(self.transform_section_open)
|
||||
.show(ui, |ui| {
|
||||
self.transform_section_open = true;
|
||||
@@ -523,10 +526,12 @@ impl InfopanelPane {
|
||||
fn render_shape_section(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
info: &SelectionInfo,
|
||||
) {
|
||||
egui::CollapsingHeader::new("Shape")
|
||||
.id_salt(("shape", path))
|
||||
.default_open(self.shape_section_open)
|
||||
.show(ui, |ui| {
|
||||
self.shape_section_open = true;
|
||||
@@ -666,8 +671,9 @@ impl InfopanelPane {
|
||||
}
|
||||
|
||||
/// Render document settings section (shown when nothing is selected)
|
||||
fn render_document_section(&self, ui: &mut Ui, shared: &mut SharedPaneState) {
|
||||
fn render_document_section(&self, ui: &mut Ui, path: &NodePath, shared: &mut SharedPaneState) {
|
||||
egui::CollapsingHeader::new("Document")
|
||||
.id_salt(("document", path))
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
ui.add_space(4.0);
|
||||
@@ -755,7 +761,7 @@ impl PaneRenderer for InfopanelPane {
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
rect: egui::Rect,
|
||||
_path: &NodePath,
|
||||
path: &NodePath,
|
||||
shared: &mut SharedPaneState,
|
||||
) {
|
||||
// Background
|
||||
@@ -774,29 +780,29 @@ impl PaneRenderer for InfopanelPane {
|
||||
);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("infopanel_scroll")
|
||||
.id_salt(("infopanel_scroll", path))
|
||||
.show(&mut content_ui, |ui| {
|
||||
ui.set_min_width(content_rect.width() - 16.0);
|
||||
|
||||
// 1. Tool options section (always shown if tool has options)
|
||||
self.render_tool_section(ui, shared);
|
||||
self.render_tool_section(ui, path, shared);
|
||||
|
||||
// 2. Gather selection info
|
||||
let info = self.gather_selection_info(shared);
|
||||
|
||||
// 3. Transform section (if shapes selected)
|
||||
if info.shape_count > 0 {
|
||||
self.render_transform_section(ui, shared, &info);
|
||||
self.render_transform_section(ui, path, shared, &info);
|
||||
}
|
||||
|
||||
// 4. Shape properties section (if shapes selected)
|
||||
if info.shape_count > 0 {
|
||||
self.render_shape_section(ui, shared, &info);
|
||||
self.render_shape_section(ui, path, shared, &info);
|
||||
}
|
||||
|
||||
// 5. Document settings (if nothing selected)
|
||||
if info.is_empty {
|
||||
self.render_document_section(ui, shared);
|
||||
self.render_document_section(ui, path, shared);
|
||||
}
|
||||
|
||||
// Show selection count at bottom
|
||||
|
||||
@@ -109,6 +109,8 @@ pub struct SharedPaneState<'a> {
|
||||
pub schneider_max_error: &'a mut f64,
|
||||
/// Audio engine controller for playback control (wrapped in Arc<Mutex<>> for thread safety)
|
||||
pub audio_controller: Option<&'a std::sync::Arc<std::sync::Mutex<daw_backend::EngineController>>>,
|
||||
/// Video manager for video decoding and frame caching
|
||||
pub video_manager: &'a std::sync::Arc<std::sync::Mutex<lightningbeam_core::video::VideoManager>>,
|
||||
/// Mapping from Document layer UUIDs to daw-backend TrackIds
|
||||
pub layer_to_track_map: &'a std::collections::HashMap<Uuid, daw_backend::TrackId>,
|
||||
/// Global playback state
|
||||
|
||||
@@ -46,6 +46,8 @@ struct SharedVelloResources {
|
||||
sampler: wgpu::Sampler,
|
||||
/// Shared image cache for avoiding re-decoding images every frame
|
||||
image_cache: Mutex<lightningbeam_core::renderer::ImageCache>,
|
||||
/// Video manager for video decoding and frame caching
|
||||
video_manager: std::sync::Arc<std::sync::Mutex<lightningbeam_core::video::VideoManager>>,
|
||||
}
|
||||
|
||||
/// Per-instance Vello resources (created for each Stage pane)
|
||||
@@ -62,7 +64,7 @@ pub struct VelloResourcesMap {
|
||||
}
|
||||
|
||||
impl SharedVelloResources {
|
||||
pub fn new(device: &wgpu::Device) -> Result<Self, String> {
|
||||
pub fn new(device: &wgpu::Device, video_manager: std::sync::Arc<std::sync::Mutex<lightningbeam_core::video::VideoManager>>) -> Result<Self, String> {
|
||||
let renderer = vello::Renderer::new(
|
||||
device,
|
||||
vello::RendererOptions {
|
||||
@@ -164,6 +166,7 @@ impl SharedVelloResources {
|
||||
blit_bind_group_layout,
|
||||
sampler,
|
||||
image_cache: Mutex::new(lightningbeam_core::renderer::ImageCache::new()),
|
||||
video_manager,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -242,6 +245,7 @@ struct VelloCallback {
|
||||
selected_tool: lightningbeam_core::tool::Tool, // Current tool for rendering mode-specific UI
|
||||
eyedropper_request: Option<(egui::Pos2, super::ColorMode)>, // Pending eyedropper sample
|
||||
playback_time: f64, // Current playback time for animation evaluation
|
||||
video_manager: std::sync::Arc<std::sync::Mutex<lightningbeam_core::video::VideoManager>>,
|
||||
}
|
||||
|
||||
impl VelloCallback {
|
||||
@@ -261,8 +265,9 @@ impl VelloCallback {
|
||||
selected_tool: lightningbeam_core::tool::Tool,
|
||||
eyedropper_request: Option<(egui::Pos2, super::ColorMode)>,
|
||||
playback_time: f64,
|
||||
video_manager: std::sync::Arc<std::sync::Mutex<lightningbeam_core::video::VideoManager>>,
|
||||
) -> Self {
|
||||
Self { rect, pan_offset, zoom, instance_id, document, tool_state, active_layer_id, drag_delta, selection, fill_color, stroke_color, stroke_width, selected_tool, eyedropper_request, playback_time }
|
||||
Self { rect, pan_offset, zoom, instance_id, document, tool_state, active_layer_id, drag_delta, selection, fill_color, stroke_color, stroke_width, selected_tool, eyedropper_request, playback_time, video_manager }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +293,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
// Initialize shared resources if not yet created (only happens once for first Stage pane)
|
||||
if map.shared.is_none() {
|
||||
map.shared = Some(Arc::new(
|
||||
SharedVelloResources::new(device).expect("Failed to initialize shared Vello resources")
|
||||
SharedVelloResources::new(device, self.video_manager.clone()).expect("Failed to initialize shared Vello resources")
|
||||
));
|
||||
}
|
||||
|
||||
@@ -320,7 +325,13 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
|
||||
// Render the document to the scene with camera transform
|
||||
let mut image_cache = shared.image_cache.lock().unwrap();
|
||||
lightningbeam_core::renderer::render_document_with_transform(&self.document, &mut scene, camera_transform, &mut image_cache);
|
||||
lightningbeam_core::renderer::render_document_with_transform(
|
||||
&self.document,
|
||||
&mut scene,
|
||||
camera_transform,
|
||||
&mut image_cache,
|
||||
&shared.video_manager,
|
||||
);
|
||||
drop(image_cache); // Explicitly release lock before other operations
|
||||
|
||||
// Render drag preview objects with transparency
|
||||
@@ -4237,9 +4248,31 @@ impl PaneRenderer for StagePane {
|
||||
shared.pending_actions.push(Box::new(action));
|
||||
} else {
|
||||
// For clips, create a clip instance
|
||||
let clip_instance = ClipInstance::new(dragging.clip_id)
|
||||
// Video clips align to stage origin (0,0), other clips use mouse position
|
||||
let (pos_x, pos_y) = if dragging.clip_type == DragClipType::Video {
|
||||
(0.0, 0.0)
|
||||
} else {
|
||||
(world_pos.x as f64, world_pos.y as f64)
|
||||
};
|
||||
|
||||
let mut clip_instance = ClipInstance::new(dragging.clip_id)
|
||||
.with_timeline_start(drop_time)
|
||||
.with_position(world_pos.x as f64, world_pos.y as f64);
|
||||
.with_position(pos_x, pos_y);
|
||||
|
||||
// For video clips, scale to fill document dimensions
|
||||
if dragging.clip_type == DragClipType::Video {
|
||||
if let Some((video_width, video_height)) = dragging.dimensions {
|
||||
let doc_width = shared.action_executor.document().width;
|
||||
let doc_height = shared.action_executor.document().height;
|
||||
|
||||
// Calculate scale to fill document
|
||||
let scale_x = doc_width / video_width;
|
||||
let scale_y = doc_height / video_height;
|
||||
|
||||
clip_instance.transform.scale_x = scale_x;
|
||||
clip_instance.transform.scale_y = scale_y;
|
||||
}
|
||||
}
|
||||
|
||||
// Create and queue action
|
||||
let action = lightningbeam_core::actions::AddClipInstanceAction::new(
|
||||
@@ -4347,6 +4380,7 @@ impl PaneRenderer for StagePane {
|
||||
*shared.selected_tool,
|
||||
self.pending_eyedropper_sample,
|
||||
*shared.playback_time,
|
||||
shared.video_manager.clone(),
|
||||
);
|
||||
|
||||
let cb = egui_wgpu::Callback::new_paint_callback(
|
||||
|
||||
@@ -943,6 +943,7 @@ impl TimelinePane {
|
||||
}
|
||||
|
||||
/// Render layer rows (timeline content area)
|
||||
/// Returns video clip hover data for processing after input handling
|
||||
fn render_layers(
|
||||
&self,
|
||||
ui: &mut egui::Ui,
|
||||
@@ -955,9 +956,12 @@ impl TimelinePane {
|
||||
waveform_cache: &std::collections::HashMap<usize, Vec<daw_backend::WaveformPeak>>,
|
||||
waveform_image_cache: &mut crate::waveform_image_cache::WaveformImageCache,
|
||||
audio_controller: Option<&std::sync::Arc<std::sync::Mutex<daw_backend::EngineController>>>,
|
||||
) {
|
||||
) -> Vec<(egui::Rect, uuid::Uuid, f64, f64)> {
|
||||
let painter = ui.painter();
|
||||
|
||||
// Collect video clip rects for hover detection (to avoid borrow conflicts)
|
||||
let mut video_clip_hovers: Vec<(egui::Rect, uuid::Uuid, f64, f64)> = Vec::new();
|
||||
|
||||
// Theme colors for active/inactive layers
|
||||
let active_style = theme.style(".timeline-row-active", ui.ctx());
|
||||
let inactive_style = theme.style(".timeline-row-inactive", ui.ctx());
|
||||
@@ -1186,6 +1190,11 @@ impl TimelinePane {
|
||||
}
|
||||
}
|
||||
|
||||
// VIDEO PREVIEW: Collect clip rect for hover detection
|
||||
if let lightningbeam_core::layer::AnyLayer::Video(_) = layer {
|
||||
video_clip_hovers.push((clip_rect, clip_instance.clip_id, clip_instance.trim_start, instance_start));
|
||||
}
|
||||
|
||||
// Draw border only if selected (brighter version of clip color)
|
||||
if selection.contains_clip_instance(&clip_instance.id) {
|
||||
painter.rect_stroke(
|
||||
@@ -1221,6 +1230,9 @@ impl TimelinePane {
|
||||
egui::Stroke::new(1.0, egui::Color32::from_gray(20)),
|
||||
);
|
||||
}
|
||||
|
||||
// Return video clip hover data for processing after input handling
|
||||
video_clip_hovers
|
||||
}
|
||||
|
||||
/// Handle mouse input for scrubbing, panning, zooming, layer selection, and clip instance selection
|
||||
@@ -1936,7 +1948,7 @@ impl PaneRenderer for TimelinePane {
|
||||
|
||||
// Render layer rows with clipping
|
||||
ui.set_clip_rect(content_rect.intersect(original_clip_rect));
|
||||
self.render_layers(ui, content_rect, shared.theme, document, shared.active_layer_id, shared.selection, shared.midi_event_cache, shared.waveform_cache, shared.waveform_image_cache, shared.audio_controller);
|
||||
let video_clip_hovers = self.render_layers(ui, content_rect, shared.theme, document, shared.active_layer_id, shared.selection, shared.midi_event_cache, shared.waveform_cache, shared.waveform_image_cache, shared.audio_controller);
|
||||
|
||||
// Render playhead on top (clip to timeline area)
|
||||
ui.set_clip_rect(timeline_rect.intersect(original_clip_rect));
|
||||
@@ -1962,6 +1974,70 @@ impl PaneRenderer for TimelinePane {
|
||||
shared.audio_controller,
|
||||
);
|
||||
|
||||
// VIDEO HOVER DETECTION: Handle video clip hover tooltips AFTER input handling
|
||||
// This ensures hover events aren't consumed by the main input handler
|
||||
for (clip_rect, clip_id, trim_start, instance_start) in video_clip_hovers {
|
||||
let hover_response = ui.allocate_rect(clip_rect, egui::Sense::hover());
|
||||
|
||||
if hover_response.hovered() {
|
||||
if let Some(hover_pos) = hover_response.hover_pos() {
|
||||
// Calculate timestamp at hover position
|
||||
let hover_offset_pixels = hover_pos.x - clip_rect.min.x;
|
||||
let hover_offset_time = (hover_offset_pixels as f64) / (self.pixels_per_second as f64);
|
||||
let hover_timestamp = instance_start + hover_offset_time;
|
||||
|
||||
// Remap to clip content time accounting for trim
|
||||
let clip_content_time = trim_start + (hover_timestamp - instance_start);
|
||||
|
||||
// Try to get thumbnail from video manager
|
||||
let thumbnail_data: Option<(u32, u32, std::sync::Arc<Vec<u8>>)> = {
|
||||
let video_mgr = shared.video_manager.lock().unwrap();
|
||||
video_mgr.get_thumbnail_at(&clip_id, clip_content_time)
|
||||
};
|
||||
|
||||
if let Some((thumb_width, thumb_height, ref thumb_data)) = thumbnail_data {
|
||||
// Create texture from thumbnail
|
||||
let color_image = egui::ColorImage::from_rgba_unmultiplied(
|
||||
[thumb_width as usize, thumb_height as usize],
|
||||
&thumb_data,
|
||||
);
|
||||
let texture = ui.ctx().load_texture(
|
||||
format!("video_hover_{}", clip_id),
|
||||
color_image,
|
||||
egui::TextureOptions::LINEAR,
|
||||
);
|
||||
|
||||
// Show tooltip with thumbnail positioned near cursor
|
||||
let tooltip_pos = hover_pos + egui::vec2(10.0, 10.0);
|
||||
egui::Area::new(egui::Id::new(format!("video_hover_tooltip_{}", clip_id)))
|
||||
.fixed_pos(tooltip_pos)
|
||||
.order(egui::Order::Tooltip)
|
||||
.show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style())
|
||||
.show(ui, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.image(&texture);
|
||||
ui.label(format!("Time: {:.2}s", clip_content_time));
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Show simple tooltip if no thumbnail available
|
||||
let tooltip_pos = hover_pos + egui::vec2(10.0, 10.0);
|
||||
egui::Area::new(egui::Id::new(format!("video_tooltip_{}", clip_id)))
|
||||
.fixed_pos(tooltip_pos)
|
||||
.order(egui::Order::Tooltip)
|
||||
.show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style())
|
||||
.show(ui, |ui| {
|
||||
ui.label(format!("Video clip\nTime: {:.2}s\n(Thumbnails generating...)", clip_content_time));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle asset drag-and-drop from Asset Library
|
||||
if let Some(dragging) = shared.dragging_asset.as_ref() {
|
||||
if let Some(pointer_pos) = ui.ctx().pointer_interact_pos() {
|
||||
@@ -2016,10 +2092,22 @@ impl PaneRenderer for TimelinePane {
|
||||
let center_y = doc.height / 2.0;
|
||||
|
||||
// Create clip instance centered on stage, at drop time
|
||||
let clip_instance = ClipInstance::new(dragging.clip_id)
|
||||
let mut clip_instance = ClipInstance::new(dragging.clip_id)
|
||||
.with_timeline_start(drop_time)
|
||||
.with_position(center_x, center_y);
|
||||
|
||||
// For video clips, scale to fill document dimensions
|
||||
if dragging.clip_type == DragClipType::Video {
|
||||
if let Some((video_width, video_height)) = dragging.dimensions {
|
||||
// Calculate scale to fill document
|
||||
let scale_x = doc.width / video_width;
|
||||
let scale_y = doc.height / video_height;
|
||||
|
||||
clip_instance.transform.scale_x = scale_x;
|
||||
clip_instance.transform.scale_y = scale_y;
|
||||
}
|
||||
}
|
||||
|
||||
// Create and queue action
|
||||
let action = lightningbeam_core::actions::AddClipInstanceAction::new(
|
||||
layer_id,
|
||||
|
||||
Reference in New Issue
Block a user