diff options
-rw-r--r-- | src/app.rs | 52 |
1 files changed, 35 insertions, 17 deletions
@@ -225,6 +225,30 @@ impl<'ctx> AppState<'ctx> { | |||
225 | self.zoom += 1; | 225 | self.zoom += 1; |
226 | } | 226 | } |
227 | 227 | ||
228 | fn zoom_out(&mut self, p: (i32, i32)) { | ||
229 | if self.zoom > 1 { | ||
230 | // attempt to center around cursor | ||
231 | if let Some(p) = self.idx_at_coord(p) { | ||
232 | let (x1, y1) = (p.0 * (self.zoom as u32), p.1 * (self.zoom as u32)); | ||
233 | let (x2, y2) = (p.0 * (self.zoom as u32 - 1), p.1 * (self.zoom as u32 - 1)); | ||
234 | let diffx = x2 as i32 - x1 as i32; | ||
235 | let diffy = y2 as i32 - y1 as i32; | ||
236 | self.start = self.start - Point::from((diffx, diffy)); | ||
237 | } | ||
238 | self.zoom -= 1; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | fn center_grid(&mut self) { | ||
243 | let (winsize_x, winsize_y) = self.canvas.window().size(); | ||
244 | let grid_width = self.width() * self.zoom as u32; | ||
245 | let grid_height = self.height() * self.zoom as u32; | ||
246 | self.start = Point::new( | ||
247 | (winsize_x as i32 - grid_width as i32) / 2, | ||
248 | (winsize_y as i32 - grid_height as i32) / 2, | ||
249 | ); | ||
250 | } | ||
251 | |||
228 | fn increase_brush_size(&mut self) { | 252 | fn increase_brush_size(&mut self) { |
229 | self.brush_size += 1; | 253 | self.brush_size += 1; |
230 | } | 254 | } |
@@ -263,20 +287,6 @@ impl<'ctx> AppState<'ctx> { | |||
263 | self.mode = Mode::Draw; | 287 | self.mode = Mode::Draw; |
264 | } | 288 | } |
265 | 289 | ||
266 | fn zoom_out(&mut self, p: (i32, i32)) { | ||
267 | if self.zoom > 1 { | ||
268 | // attempt to center around cursor | ||
269 | if let Some(p) = self.idx_at_coord(p) { | ||
270 | let (x1, y1) = (p.0 * (self.zoom as u32), p.1 * (self.zoom as u32)); | ||
271 | let (x2, y2) = (p.0 * (self.zoom as u32 - 1), p.1 * (self.zoom as u32 - 1)); | ||
272 | let diffx = x2 as i32 - x1 as i32; | ||
273 | let diffy = y2 as i32 - y1 as i32; | ||
274 | self.start = self.start - Point::from((diffx, diffy)); | ||
275 | } | ||
276 | self.zoom -= 1; | ||
277 | } | ||
278 | } | ||
279 | |||
280 | fn draw_grid(&mut self) { | 290 | fn draw_grid(&mut self) { |
281 | let cs = self.zoom as u32; | 291 | let cs = self.zoom as u32; |
282 | let (width, height) = (self.width(), self.height()); | 292 | let (width, height) = (self.width(), self.height()); |
@@ -523,7 +533,9 @@ impl<'ctx> AppState<'ctx> { | |||
523 | Mode::Draw => { | 533 | Mode::Draw => { |
524 | match event { | 534 | match event { |
525 | Event::KeyDown { | 535 | Event::KeyDown { |
526 | keycode: Some(k), .. | 536 | keycode: Some(k), |
537 | keymod, | ||
538 | .. | ||
527 | } => { | 539 | } => { |
528 | match k { | 540 | match k { |
529 | // pan | 541 | // pan |
@@ -532,6 +544,9 @@ impl<'ctx> AppState<'ctx> { | |||
532 | Keycode::S => self.pan((0, -10)), | 544 | Keycode::S => self.pan((0, -10)), |
533 | Keycode::D => self.pan((-10, 0)), | 545 | Keycode::D => self.pan((-10, 0)), |
534 | // zoom | 546 | // zoom |
547 | Keycode::C if keymod == Mod::LSHIFTMOD => { | ||
548 | self.center_grid(); | ||
549 | } | ||
535 | Keycode::C => { | 550 | Keycode::C => { |
536 | let cursor = (mouse.x(), mouse.y()); | 551 | let cursor = (mouse.x(), mouse.y()); |
537 | self.zoom_in(cursor); | 552 | self.zoom_in(cursor); |
@@ -647,11 +662,14 @@ impl<'ctx> AppState<'ctx> { | |||
647 | let video = self.context.video().unwrap(); | 662 | let video = self.context.video().unwrap(); |
648 | let clipboard = video.clipboard(); | 663 | let clipboard = video.clipboard(); |
649 | if is_copy_event(keycode, keymod) { | 664 | if is_copy_event(keycode, keymod) { |
650 | clipboard.set_clipboard_text(&self.command_box.text); | 665 | clipboard |
666 | .set_clipboard_text(&self.command_box.text) | ||
667 | .unwrap(); | ||
651 | } else if is_paste_event(keycode, keymod) | 668 | } else if is_paste_event(keycode, keymod) |
652 | && clipboard.has_clipboard_text() | 669 | && clipboard.has_clipboard_text() |
653 | { | 670 | { |
654 | self.command_box.text = clipboard.clipboard_text().unwrap(); | 671 | self.command_box |
672 | .push_str(&clipboard.clipboard_text().unwrap()); | ||
655 | } | 673 | } |
656 | } | 674 | } |
657 | if let Event::KeyDown { | 675 | if let Event::KeyDown { |