Pārlūkot izejas kodu

Handle different image file formats

Johannes Hofmann 8 gadus atpakaļ
vecāks
revīzija
895c8b1232
5 mainītis faili ar 19 papildinājumiem un 3 dzēšanām
  1. 1
    0
      deltamap.toml
  2. 2
    0
      src/config.rs
  3. 11
    1
      src/main.rs
  4. 1
    1
      src/tile_loader.rs
  5. 4
    1
      src/tile_source.rs

+ 1
- 0
deltamap.toml Parādīt failu

@@ -3,3 +3,4 @@ tile_cache_dir = "/tmp"
3 3
 [sources.OSM]
4 4
 max_zoom = 19
5 5
 url_template = "http://a.tile.openstreetmap.org/{z}/{x}/{y}.png"
6
+extension = "png"

+ 2
- 0
src/config.rs Parādīt failu

@@ -16,6 +16,7 @@ pub struct Config {
16 16
 struct Source {
17 17
     max_zoom: u32,
18 18
     url_template: String,
19
+    extension: String,
19 20
 }
20 21
 
21 22
 impl Config {
@@ -47,6 +48,7 @@ impl Config {
47 48
                     id as u32,
48 49
                     source.url_template.clone(),
49 50
                     path,
51
+                    source.extension.clone(),
50 52
                     source.max_zoom,
51 53
                 ),
52 54
             ));

+ 11
- 1
src/main.rs Parādīt failu

@@ -170,7 +170,7 @@ fn main() {
170 170
     let mut sources = TileSources::new(config.tile_sources()).unwrap();
171 171
 
172 172
     let mut window = glutin::WindowBuilder::new().build().unwrap();
173
-    window.set_title("DeltaMap");
173
+    window.set_title(&("DeltaMap - ".to_string() + sources.current_name()));
174 174
     window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
175 175
     let _ = unsafe { window.make_current() };
176 176
 
@@ -194,6 +194,7 @@ fn main() {
194 194
 
195 195
     'outer: for event in window.wait_events() {
196 196
         let mut start_loop = Instant::now();
197
+        let start_source_id = sources.current().id();
197 198
 
198 199
         let mut redraw = false;
199 200
 
@@ -247,6 +248,11 @@ fn main() {
247 248
             let diff = start_loop.elapsed();
248 249
             println!("EVENT LOOP SECS {}", diff.as_secs() as f64 + f64::from(diff.subsec_nanos()) * 1e-9);
249 250
         }
251
+
252
+        // set window title
253
+        if sources.current().id() != start_source_id {
254
+            window.set_title(&("DeltaMap - ".to_string() + sources.current_name()));
255
+        }
250 256
     }
251 257
 }
252 258
 
@@ -271,6 +277,10 @@ impl TileSources {
271 277
         &self.sources[self.current_index].1
272 278
     }
273 279
 
280
+    pub fn current_name(&self) -> &str {
281
+        &self.sources[self.current_index].0
282
+    }
283
+
274 284
     pub fn switch_to_next(&mut self) {
275 285
         self.current_index = (self.current_index + 1) % self.sources.len();
276 286
     }

+ 1
- 1
src/tile_loader.rs Parādīt failu

@@ -48,7 +48,7 @@ impl TileLoader {
48 48
     {
49 49
         let mut client_opt = None;
50 50
         while let Ok((tile, url, path, write_to_file)) = request_rx.recv() {
51
-            println!("work {:?}", tile);
51
+            println!("work {:?} {:?}", tile, path);
52 52
             match image::open(&path) {
53 53
                 Ok(img) => {
54 54
                     result_tx.send((tile, Some(img))).unwrap();

+ 4
- 1
src/tile_source.rs Parādīt failu

@@ -7,6 +7,7 @@ pub struct TileSource {
7 7
     id: u32,
8 8
     url_template: String,
9 9
     directory: PathBuf,
10
+    extension: String,
10 11
     max_zoom: u32,
11 12
 }
12 13
 
@@ -20,12 +21,14 @@ impl TileSource {
20 21
         id: u32,
21 22
         url_template: S,
22 23
         directory: P,
24
+        extension: String,
23 25
         max_zoom: u32,
24 26
     ) -> Self {
25 27
         TileSource {
26 28
             id: id,
27 29
             url_template: url_template.into(),
28 30
             directory: directory.into(),
31
+            extension: extension,
29 32
             max_zoom: max_zoom,
30 33
         }
31 34
     }
@@ -40,7 +43,7 @@ impl TileSource {
40 43
         let mut path = PathBuf::from(&self.directory);
41 44
         path.push(tile_coord.zoom.to_string());
42 45
         path.push(tile_coord.x.to_string());
43
-        path.push(tile_coord.y.to_string() + ".png");
46
+        path.push(tile_coord.y.to_string() + "." + &self.extension);
44 47
 
45 48
         path
46 49
     }