Browse Source

Allow changing render zoom level

Johannes Hofmann 8 years ago
parent
commit
b7988fd29f
3 changed files with 57 additions and 4 deletions
  1. 41
    2
      src/main.rs
  2. 11
    2
      src/map_view.rs
  3. 5
    0
      src/map_view_gl.rs

+ 41
- 2
src/main.rs View File

46
 struct InputState {
46
 struct InputState {
47
     mouse_position: (i32, i32),
47
     mouse_position: (i32, i32),
48
     mouse_pressed: bool,
48
     mouse_pressed: bool,
49
+    lctrl_pressed: bool,
50
+    rctrl_pressed: bool,
51
+}
52
+
53
+impl InputState {
54
+    fn ctrl_pressed(&self) -> bool {
55
+        self.lctrl_pressed | self.rctrl_pressed
56
+    }
49
 }
57
 }
50
 
58
 
51
 fn handle_event(event: &Event, map: &mut MapViewGl, input_state: &mut InputState, sources: &mut TileSources) -> Action {
59
 fn handle_event(event: &Event, map: &mut MapViewGl, input_state: &mut InputState, sources: &mut TileSources) -> Action {
112
                 VirtualKeyCode::Escape => {
120
                 VirtualKeyCode::Escape => {
113
                     Action::Close
121
                     Action::Close
114
                 },
122
                 },
123
+                VirtualKeyCode::LControl => {
124
+                    input_state.lctrl_pressed = true;
125
+                    Action::Nothing
126
+                },
127
+                VirtualKeyCode::RControl => {
128
+                    input_state.rctrl_pressed = true;
129
+                    Action::Nothing
130
+                },
115
                 VirtualKeyCode::PageUp => {
131
                 VirtualKeyCode::PageUp => {
116
                     sources.switch_to_prev();
132
                     sources.switch_to_prev();
117
                     Action::Redraw
133
                     Action::Redraw
137
                     Action::Redraw
153
                     Action::Redraw
138
                 },
154
                 },
139
                 VirtualKeyCode::Add => {
155
                 VirtualKeyCode::Add => {
140
-                    map.step_zoom(1, 0.5);
156
+                    if input_state.ctrl_pressed() {
157
+                        map.change_zoom_level_offset(1.0);
158
+                    } else {
159
+                        map.step_zoom(1, 0.5);
160
+                    }
141
                     Action::Redraw
161
                     Action::Redraw
142
                 },
162
                 },
143
                 VirtualKeyCode::Subtract => {
163
                 VirtualKeyCode::Subtract => {
144
-                    map.step_zoom(-1, 0.5);
164
+                    if input_state.ctrl_pressed() {
165
+                        map.change_zoom_level_offset(-1.0);
166
+                    } else {
167
+                        map.step_zoom(-1, 0.5);
168
+                    }
145
                     Action::Redraw
169
                     Action::Redraw
146
                 },
170
                 },
147
                 _ => Action::Nothing,
171
                 _ => Action::Nothing,
148
             }
172
             }
149
         },
173
         },
174
+        Event::KeyboardInput(glutin::ElementState::Released, _, Some(keycode)) => {
175
+            match keycode {
176
+                VirtualKeyCode::LControl => {
177
+                    input_state.lctrl_pressed = false;
178
+                    Action::Nothing
179
+                },
180
+                VirtualKeyCode::RControl => {
181
+                    input_state.rctrl_pressed = false;
182
+                    Action::Nothing
183
+                },
184
+                _ => Action::Nothing,
185
+            }
186
+        },
150
         Event::Refresh => {
187
         Event::Refresh => {
151
             Action::Redraw
188
             Action::Redraw
152
         },
189
         },
223
     let mut input_state = InputState {
260
     let mut input_state = InputState {
224
         mouse_position: (0, 0),
261
         mouse_position: (0, 0),
225
         mouse_pressed: false,
262
         mouse_pressed: false,
263
+        lctrl_pressed: false,
264
+        rctrl_pressed: false,
226
     };
265
     };
227
 
266
 
228
     let fps: f64 = matches.value_of("fps").map(|s| s.parse().unwrap()).unwrap_or(config.fps());
267
     let fps: f64 = matches.value_of("fps").map(|s| s.parse().unwrap()).unwrap_or(config.fps());

+ 11
- 2
src/map_view.rs View File

8
     pub tile_size: u32,
8
     pub tile_size: u32,
9
     pub center: MapCoord,
9
     pub center: MapCoord,
10
     pub zoom2: f64,
10
     pub zoom2: f64,
11
+    pub render_zoom_level_offset: f64,
11
 }
12
 }
12
 
13
 
13
 #[derive(Clone, Debug)]
14
 #[derive(Clone, Debug)]
24
             tile_size: tile_size,
25
             tile_size: tile_size,
25
             center: MapCoord::new(0.5, 0.5),
26
             center: MapCoord::new(0.5, 0.5),
26
             zoom2: 0.0,
27
             zoom2: 0.0,
28
+            render_zoom_level_offset: 0.0,
27
         }
29
         }
28
     }
30
     }
29
 
31
 
91
         visible_tiles
93
         visible_tiles
92
     }
94
     }
93
 
95
 
94
-    //TODO make zoom level configurable
95
     pub fn render_zoom_level(&self) -> u32 {
96
     pub fn render_zoom_level(&self) -> u32 {
96
-        self.zoom2.floor().max(0.0) as u32
97
+        (self.zoom2 + self.render_zoom_level_offset).floor().max(0.0) as u32
98
+    }
99
+
100
+    pub fn render_zoom_level_offset(&self) -> f64 {
101
+        self.render_zoom_level_offset
102
+    }
103
+
104
+    pub fn set_render_zoom_level_offset(&mut self, offset: f64) {
105
+        self.render_zoom_level_offset = offset;
97
     }
106
     }
98
 
107
 
99
     pub fn set_size(&mut self, width: f64, height: f64) {
108
     pub fn set_size(&mut self, width: f64, height: f64) {

+ 5
- 0
src/map_view_gl.rs View File

193
         self.map_view.center.normalize_xy();
193
         self.map_view.center.normalize_xy();
194
     }
194
     }
195
 
195
 
196
+    pub fn change_zoom_level_offset(&mut self, delta_offset: f64) {
197
+        let offset = self.map_view.render_zoom_level_offset();
198
+        self.map_view.set_render_zoom_level_offset(offset + delta_offset);
199
+    }
200
+
196
     pub fn move_pixel(&mut self, delta_x: f64, delta_y: f64) {
201
     pub fn move_pixel(&mut self, delta_x: f64, delta_y: f64) {
197
         self.map_view.move_pixel(delta_x, delta_y);
202
         self.map_view.move_pixel(delta_x, delta_y);
198
         self.map_view.center.normalize_xy();
203
         self.map_view.center.normalize_xy();