diff --git a/src/appstate.rs b/src/appstate.rs index 8d428945..153e1b7d 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -49,7 +49,7 @@ impl Message { } pub struct TexWrap{ - pub texture_array:Vec, + texture_array:Vec, pub col_count:u32, pub row_count:u32, pub col_translation:u32, diff --git a/src/main.rs b/src/main.rs index 20676e5b..848f9684 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1083,14 +1083,19 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O state.image_geometry.offset.y, state.image_geometry.scale); } else { - //TODO: How to implement this efficient? - draw.pattern(&texture.texture_array[0]) - .scale(state.image_geometry.scale, state.image_geometry.scale) - .translate(state.image_geometry.offset.x, state.image_geometry.offset.y) - .size( - texture.texture_array[0].width() * state.tiling as f32, - texture.texture_array[0].height() * state.tiling as f32, - ); + + for yi in 0..state.tiling { + for xi in 0..state.tiling { + //The "old" version used only a static offset, is this correct? + let translate_x = xi as f32* texture.width()*state.image_geometry.scale + state.image_geometry.offset.x; + let translate_y = yi as f32* texture.height()*state.image_geometry.scale + state.image_geometry.offset.y; + + texture.draw_textures(&mut draw, + translate_x, + translate_y, + state.image_geometry.scale); + } + } } if state.persistent_settings.show_frame { diff --git a/src/ui.rs b/src/ui.rs index 037457c3..1539aad6 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -184,7 +184,7 @@ impl EguiExt for Ui { #[allow(unused)] pub fn image_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) { if let Some(texture) = &state.current_texture { - let tex_id = gfx.egui_register_texture(&texture.texture_array[0]); //TODO: Adapt if needed + //let tex_id = gfx.egui_register_texture(&texture.texture_array[0]); //TODO: Adapt if needed let image_rect = Rect::from_center_size( Pos2::new( @@ -199,12 +199,12 @@ pub fn image_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) { ) * state.image_geometry.scale, ); - egui::Painter::new(ctx.clone(), LayerId::background(), ctx.available_rect()).image( + /*egui::Painter::new(ctx.clone(), LayerId::background(), ctx.available_rect()).image( tex_id.id, image_rect, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE, - ); + );*/ } // state.image_geometry.scale; @@ -248,11 +248,7 @@ pub fn info_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) { egui::ScrollArea::vertical().auto_shrink([false,true]) .show(ui, |ui| { if let Some(texture) = &state.current_texture { - // texture. - //let tex_id = gfx.egui_register_texture(&texture.texture_array[0]); - - // width of image widget - // let desired_width = ui.available_width() - ui.spacing().indent; + let desired_width = PANEL_WIDTH as f64 - PANEL_WIDGET_OFFSET as f64; let scale = (desired_width / 8.) / texture.size().0 as f64; @@ -331,8 +327,6 @@ pub fn info_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) { }); - //let mut draw = gfx.create_draw(); - // make sure aspect ratio is compensated for the square preview let ratio = texture.size().0 / texture.size().1; let uv_size = (scale, scale * ratio as f64); @@ -350,27 +344,24 @@ pub fn info_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) { ) .rect;*/ + //Pre initialize the rectangle coordinates of the preview window let mut bbox_tl = egui::pos2(f32::MAX, f32::MAX); let mut bbox_br = egui::pos2(f32::MIN, f32::MIN); + //The uv positions in the image, we iterate over + let mut curr_cursor_v = uv_center.1 - uv_size.1; let end_cursor_u = uv_center.0 + uv_size.0; let end_cursor_v = uv_center.1 + uv_size.1; - - - //let base_ui_curs = ui.cursor().min; //our start position - + //Ui position to start at let base_ui_curs = nalgebra::Vector2::new(ui.cursor().min.x as f64, ui.cursor().min.y as f64); let mut curr_ui_curs = base_ui_curs; //our start position - let mut curr_cursor_v = uv_center.1 - uv_size.1; - let mut counter_v = 0; //Safety measure... while(curr_cursor_v