mirror of
https://github.com/CrispyPin/julia-fractal-renderer.git
synced 2024-11-24 19:10:27 +01:00
improve export options
This commit is contained in:
parent
eb2fa3f8f7
commit
cc43258aad
1 changed files with 47 additions and 31 deletions
78
src/main.rs
78
src/main.rs
|
@ -1,8 +1,8 @@
|
||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::Write,
|
io::Write,
|
||||||
|
path::PathBuf,
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,9 +44,10 @@ struct JuliaGUI {
|
||||||
preview_render_ms: f64,
|
preview_render_ms: f64,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
export_render_ms: Option<f64>,
|
export_render_ms: Option<f64>,
|
||||||
export_res_multiplier: u32,
|
export_res_power: u8,
|
||||||
export_iterations: u32,
|
export_iterations: u32,
|
||||||
export_name: String,
|
#[serde(skip)]
|
||||||
|
export_path: PathBuf,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
settings_changed: bool,
|
settings_changed: bool,
|
||||||
}
|
}
|
||||||
|
@ -59,9 +60,9 @@ impl Default for JuliaGUI {
|
||||||
render_options: RenderOptions::default(),
|
render_options: RenderOptions::default(),
|
||||||
preview_render_ms: 0.0,
|
preview_render_ms: 0.0,
|
||||||
export_render_ms: None,
|
export_render_ms: None,
|
||||||
export_res_multiplier: 8,
|
export_res_power: 8,
|
||||||
export_iterations: 512,
|
export_iterations: 512,
|
||||||
export_name: String::from("julia_fractal.png"),
|
export_path: "".into(),
|
||||||
settings_changed: true,
|
settings_changed: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +84,7 @@ impl JuliaGUI {
|
||||||
|
|
||||||
n.preview = Some(preview);
|
n.preview = Some(preview);
|
||||||
n.settings_changed = true;
|
n.settings_changed = true;
|
||||||
|
n.export_path = "julia_fractal.png".into();
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,19 +112,31 @@ impl JuliaGUI {
|
||||||
|
|
||||||
fn export_render(&mut self) {
|
fn export_render(&mut self) {
|
||||||
let start_time = SystemTime::now();
|
let start_time = SystemTime::now();
|
||||||
|
let res_mul = 1 << self.export_res_power;
|
||||||
let settings = RenderOptions {
|
let settings = RenderOptions {
|
||||||
width: self.render_options.width * self.export_res_multiplier,
|
width: self.render_options.width * res_mul,
|
||||||
height: self.render_options.height * self.export_res_multiplier,
|
height: self.render_options.height * res_mul,
|
||||||
max_iterations: self.export_iterations,
|
max_iterations: self.export_iterations,
|
||||||
..self.render_options.clone()
|
..self.render_options.clone()
|
||||||
};
|
};
|
||||||
let image = render(&settings, self.color);
|
let image = render(&settings, self.color);
|
||||||
if let Err(err) = image.save(&self.export_name) {
|
if let Err(err) = image.save(&self.export_path) {
|
||||||
println!("Error exporting render: {err}");
|
println!("Error exporting render: {err}");
|
||||||
}
|
}
|
||||||
self.export_render_ms = Some(start_time.elapsed().unwrap().as_micros() as f64 / 1000.0);
|
self.export_render_ms = Some(start_time.elapsed().unwrap().as_micros() as f64 / 1000.0);
|
||||||
self.save_settings();
|
self.save_settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn export_render_new_path(&mut self) {
|
||||||
|
if let Ok(Some(path)) = FileDialog::new()
|
||||||
|
.set_filename(&self.export_path.to_string_lossy().to_string())
|
||||||
|
.add_filter("PNG file", &["png"])
|
||||||
|
.show_save_single_file()
|
||||||
|
{
|
||||||
|
self.export_path = path;
|
||||||
|
self.export_render();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl eframe::App for JuliaGUI {
|
impl eframe::App for JuliaGUI {
|
||||||
|
@ -196,39 +210,41 @@ impl eframe::App for JuliaGUI {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.label("Export iterations:");
|
ui.label("Render iterations:");
|
||||||
ui.add(Slider::new(&mut self.export_iterations, 5..=1024).clamp_to_range(false));
|
ui.add(Slider::new(&mut self.export_iterations, 5..=1024).clamp_to_range(false));
|
||||||
ui.label("Resolution multiplier:");
|
ui.label("Render resolution:");
|
||||||
ui.add(Slider::new(&mut self.export_res_multiplier, 1..=32));
|
ui.add(Slider::new(&mut self.export_res_power, 0..=6).clamp_to_range(false));
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"Export resolution: {}x{}",
|
"Render resolution: {}x{}",
|
||||||
self.export_res_multiplier * self.render_options.width,
|
(1 << self.export_res_power) * self.render_options.width,
|
||||||
self.export_res_multiplier * self.render_options.height
|
(1 << self.export_res_power) * self.render_options.height
|
||||||
));
|
));
|
||||||
|
|
||||||
if ui.button("Select file").clicked() {
|
|
||||||
if let Ok(Some(path)) = FileDialog::new()
|
|
||||||
.set_filename(&self.export_name)
|
|
||||||
.add_filter("PNG file", &["png"])
|
|
||||||
.show_save_single_file()
|
|
||||||
{
|
|
||||||
self.export_name = path
|
|
||||||
.strip_prefix(env::current_dir().unwrap())
|
|
||||||
.unwrap_or(&path)
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ui.label(&self.export_name);
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Render").clicked() {
|
let export_text = if self.export_path.is_file() {
|
||||||
|
"Overwrite"
|
||||||
|
} else {
|
||||||
|
"Render"
|
||||||
|
};
|
||||||
|
if ui.button(export_text).clicked() {
|
||||||
self.export_render();
|
self.export_render();
|
||||||
}
|
}
|
||||||
if let Some(ms) = self.export_render_ms {
|
if ui.button("Render to").clicked() {
|
||||||
ui.label(format!("(took {:.2}ms)", ms));
|
self.export_render_new_path();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui.label(
|
||||||
|
self.export_path
|
||||||
|
.file_name()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
if let Some(ms) = self.export_render_ms {
|
||||||
|
ui.label(format!("(took {:.2}ms)", ms));
|
||||||
|
}
|
||||||
|
|
||||||
if set_cx.changed()
|
if set_cx.changed()
|
||||||
|| set_cy.changed() || set_unit_width.changed()
|
|| set_cy.changed() || set_unit_width.changed()
|
||||||
|| set_iter.changed()
|
|| set_iter.changed()
|
||||||
|
|
Loading…
Reference in a new issue