Skip to content

Commit

Permalink
avoid calling render_to_texture two times
Browse files Browse the repository at this point in the history
  • Loading branch information
FUFSoB committed Feb 16, 2024
1 parent 91cd4ab commit e94ae91
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ impl SketchBoard {
}

fn handle_save(&self, sender: ComponentSender<Self>) {
let texture = match self.renderer.render_to_texture(&self.active_tool) {
Ok(t) => t,
Err(e) => {
println!("Error while creating texture: {e}");
return;
}
};

self.handle_save_texture(sender, &texture);
}

fn handle_save_texture(&self, sender: ComponentSender<Self>, texture: &MemoryTexture) {
let output_filename = match APP_CONFIG.read().output_filename() {
None => {
println!("No Output filename specified!");
Expand All @@ -164,14 +176,6 @@ impl SketchBoard {
return;
}

let texture = match self.renderer.render_to_texture(&self.active_tool) {
Ok(t) => t,
Err(e) => {
println!("Error while creating texture: {e}");
return;
}
};

let data = texture.save_to_png_bytes();

let msg = match fs::write(&output_filename, data) {
Expand Down Expand Up @@ -236,7 +240,7 @@ impl SketchBoard {
));

if APP_CONFIG.read().save_on_copy() {
self.handle_save(sender);
self.handle_save_texture(sender, &texture);
};
},
}
Expand Down

0 comments on commit e94ae91

Please sign in to comment.