|
|
@@ -46,6 +46,14 @@ enum Action {
|
|
46
|
46
|
struct InputState {
|
|
47
|
47
|
mouse_position: (i32, i32),
|
|
48
|
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
|
59
|
fn handle_event(event: &Event, map: &mut MapViewGl, input_state: &mut InputState, sources: &mut TileSources) -> Action {
|
|
|
@@ -112,6 +120,14 @@ fn handle_event(event: &Event, map: &mut MapViewGl, input_state: &mut InputState
|
|
112
|
120
|
VirtualKeyCode::Escape => {
|
|
113
|
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
|
131
|
VirtualKeyCode::PageUp => {
|
|
116
|
132
|
sources.switch_to_prev();
|
|
117
|
133
|
Action::Redraw
|
|
|
@@ -137,16 +153,37 @@ fn handle_event(event: &Event, map: &mut MapViewGl, input_state: &mut InputState
|
|
137
|
153
|
Action::Redraw
|
|
138
|
154
|
},
|
|
139
|
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
|
161
|
Action::Redraw
|
|
142
|
162
|
},
|
|
143
|
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
|
169
|
Action::Redraw
|
|
146
|
170
|
},
|
|
147
|
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
|
187
|
Event::Refresh => {
|
|
151
|
188
|
Action::Redraw
|
|
152
|
189
|
},
|
|
|
@@ -223,6 +260,8 @@ fn main() {
|
|
223
|
260
|
let mut input_state = InputState {
|
|
224
|
261
|
mouse_position: (0, 0),
|
|
225
|
262
|
mouse_pressed: false,
|
|
|
263
|
+ lctrl_pressed: false,
|
|
|
264
|
+ rctrl_pressed: false,
|
|
226
|
265
|
};
|
|
227
|
266
|
|
|
228
|
267
|
let fps: f64 = matches.value_of("fps").map(|s| s.parse().unwrap()).unwrap_or(config.fps());
|