From 45415b0a6a88d2038f8af80ad613b84f65d6f649 Mon Sep 17 00:00:00 2001 From: Johann Woelper Date: Sat, 1 Feb 2025 01:24:53 +0100 Subject: [PATCH] fix: Prevent flickering metadata when playing animations, color picker has better contrast on bright images --- src/appstate.rs | 2 -- src/main.rs | 60 ++++++++++++++++++++++-------------------- src/texture_wrapper.rs | 29 +++++++++----------- src/ui/info_ui.rs | 4 +-- src/ui/mod.rs | 1 - 5 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/appstate.rs b/src/appstate.rs index 1f9d557..c2150de 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -65,7 +65,6 @@ pub struct OculanteState { /// Channel to load images from pub load_channel: (Sender, Receiver), pub extended_info_channel: (Sender, Receiver), - pub extended_info_loading: bool, /// The Player, responsible for loading and sending Frames pub player: Player, //pub current_texture: Option, @@ -138,7 +137,6 @@ impl<'b> Default for OculanteState { message_channel: msg_channel, load_channel: mpsc::channel(), extended_info_channel: meta_channel, - extended_info_loading: Default::default(), mouse_delta: Default::default(), current_texture: Default::default(), current_image: Default::default(), diff --git a/src/main.rs b/src/main.rs index d5e7102..fe54b86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -790,38 +790,38 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O debug!("Got frame: {}", frame.to_string()); - match &frame { - Frame::AnimationStart(_) | Frame::Still(_) | Frame::ImageCollectionMember(_) => { - // Something new came in, update scrubber (index slider) and path - if let Some(path) = &state.current_path { - if state.scrubber.has_folder_changed(&path) { - debug!("Folder has changed, creating new scrubber"); - state.scrubber = scrubber::Scrubber::new(path); - state.scrubber.wrap = state.persistent_settings.wrap_folder; - } else { - let index = state - .scrubber - .entries - .iter() - .position(|p| p == path) - .unwrap_or_default(); - if index < state.scrubber.entries.len() { - state.scrubber.index = index; - } + if matches!( + &frame, + Frame::AnimationStart(_) | Frame::Still(_) | Frame::ImageCollectionMember(_) + ) { + // Something new came in, update scrubber (index slider) and path + if let Some(path) = &state.current_path { + if state.scrubber.has_folder_changed(&path) { + debug!("Folder has changed, creating new scrubber"); + state.scrubber = scrubber::Scrubber::new(path); + state.scrubber.wrap = state.persistent_settings.wrap_folder; + } else { + let index = state + .scrubber + .entries + .iter() + .position(|p| p == path) + .unwrap_or_default(); + if index < state.scrubber.entries.len() { + state.scrubber.index = index; } } + } - if let Some(path) = &state.current_path { - if !state.volatile_settings.recent_images.contains(path) { - state - .volatile_settings - .recent_images - .insert(0, path.clone()); - state.volatile_settings.recent_images.truncate(12); - } + if let Some(path) = &state.current_path { + if !state.volatile_settings.recent_images.contains(path) { + state + .volatile_settings + .recent_images + .insert(0, path.clone()); + state.volatile_settings.recent_images.truncate(12); } } - _ => {} } match &frame { @@ -937,6 +937,10 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O Frame::UpdateTexture => {} } + if !matches!(frame, Frame::Animation(_, _)) { + state.image_metadata = None; + } + // Deal with everything that sends an image match frame { Frame::AnimationStart(img) @@ -992,7 +996,6 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O // In those cases, we want the image to stay as it is. // TODO: PERF: This copies the image buffer. This should also maybe not run for animation frames // although it looks cool. - state.image_metadata = None; send_extended_info( &state.current_image, &state.current_path, @@ -1093,7 +1096,6 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O } state.pointer_over_ui = ctx.is_pointer_over_area(); - // ("using pointer {}", ctx.is_using_pointer()); // if there is interaction on the ui (dragging etc) // we don't want zoom & pan to work, so we "grab" the pointer diff --git a/src/texture_wrapper.rs b/src/texture_wrapper.rs index 0074a98..878ac6b 100644 --- a/src/texture_wrapper.rs +++ b/src/texture_wrapper.rs @@ -5,6 +5,7 @@ use image::DynamicImage; use log::debug; use log::error; use log::warn; +use notan::app::Color; use notan::draw::*; use notan::math::{Mat4, Vec4}; use notan::prelude::{BlendMode, Buffer, Graphics, ShaderSource, Texture, TextureFilter}; @@ -737,7 +738,6 @@ impl TexWrap { let x_coordinate_end = xy_tex_center.0 + xy_tex_size.0; let mut y_coordinate = xy_tex_center.1 - xy_tex_size.1; let y_coordinate_end = xy_tex_center.1 + xy_tex_size.1; - //print!("Start x: {}, y: {}\n",xy_tex_center.0 - xy_tex_size.0,y_coordinate); while y_coordinate <= y_coordinate_end { let mut y_coordinate_new = i32::MAX; //increment for y coordinate after x loop @@ -757,9 +757,6 @@ impl TexWrap { shader_active = false; } - //print!("x: {} y: {} ", x_coordinate, y_coordinate); - //print!("top: {} left: {} ", curr_tex_response.y_tex_top_global, curr_tex_response.x_tex_left_global); - //print!("bottom: {} right: {} \n", curr_tex_response.y_tex_bottom_global, curr_tex_response.x_tex_right_global); //Handling last texture in a row or col let curr_tex_end = nalgebra::Vector2::new( @@ -797,32 +794,32 @@ impl TexWrap { curr_ui_curs.x += display_size.x; last_display_size_y = last_display_size_y.min(display_size.y); } - //Update y coordinates - //print!("new y: {}, old y: {} \n", y_coordinate_new, y_coordinate); + // Update y coordinates y_coordinate = y_coordinate_new; curr_ui_curs.y += last_display_size_y; } - //print!("\n"); self.remove_draw_shader(draw); - //Draw crosshair - //let stroke_width = 0.5; + // Draw crosshair let half_width = scale/4.0/*-stroke_width*/; draw.rect( (translation_x + width / 2.0 - half_width, translation_y), (2.0 * half_width, width), - ) - /*.fill() - .stroke(stroke_width) - .stroke_color(notan::app::Color { r: (0.0), g: (0.0), b: (0.0), a: (1.0) }) */; + ).alpha(0.5); + draw.rect( (translation_x, translation_y + width / 2.0 - half_width), (width, 2.0 * half_width), + ).alpha(0.5); + + draw.rect( + (translation_x + width / 2.0 - half_width, translation_y + width / 2.0 - half_width), + (2.0 * half_width, 2.0* half_width), ) - /* .fill() - .stroke(stroke_width) - .stroke_color(notan::app::Color { r: (0.0), g: (0.0), b: (0.0), a: (1.0) })*/; + .fill_color(Color::from_rgb(0.1, 0.1, 0.1)) + .alpha(0.2); + } pub fn update_textures( diff --git a/src/ui/info_ui.rs b/src/ui/info_ui.rs index d18d117..dab27b9 100644 --- a/src/ui/info_ui.rs +++ b/src/ui/info_ui.rs @@ -141,12 +141,10 @@ pub fn info_ui(ctx: &Context, state: &mut OculanteState, _gfx: &mut Graphics) -> let offset = (ui.available_width() - preview_rect.width())/2.; preview_rect = preview_rect.translate(vec2(offset, 0.)); - //Rendering a placeholder rectangle + // Rendering a placeholder rectangle ui.painter().rect(preview_rect, ROUNDING, egui::Color32::TRANSPARENT, egui::Stroke::NONE); bbox_tl = preview_rect.left_top(); bbox_br = preview_rect.right_bottom(); - - // let preview_rect = egui::Rect::from_min_max(bbox_tl, bbox_br); ui.advance_cursor_after_rect(preview_rect); } ui.add_space(10.); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 8fa43ee..6293f24 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -742,7 +742,6 @@ pub fn drag_area(ui: &mut Ui, state: &mut OculanteState, app: &mut App) { } } - pub fn blank_icon( _ui: &egui::Ui, _rect: egui::Rect,