1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
extern crate camera_controllers;
extern crate find_folder;
extern crate gfx;
extern crate gfx_device_gl;
extern crate image;
extern crate piston_window;
extern crate rand;
extern crate serde;
extern crate serde_json;
extern crate shader_version;
extern crate vecmath;
mod data;
mod grid;
mod paint_tool;
mod piston_wrapper;
mod settings;
mod window_operation;
use crate::piston_wrapper::kusa_image::write_k_image;
use crate::piston_wrapper::kusa_image::KusaImage;
use crate::settings::*;
use crate::window_operation::*;
use std::path::Path;
pub fn run() {
let mut settings = match Settings::load() {
Ok(x) => x,
Err(_) => {
let settings = Settings::default();
settings.save();
settings
}
};
println!("Debug | Load image {}", settings.image_file);
let mut k_image = match image::open(Path::new(&settings.image_file)) {
Ok(img) => {
let k_image = KusaImage::load_image(&img);
settings.image_width = k_image.width;
settings.image_height = k_image.height;
k_image
}
Err(_e) => {
let k_image = KusaImage::new(settings.image_width, settings.image_height);
write_k_image(&k_image, &settings.image_file);
k_image
}
};
show_window(settings, &mut k_image);
}