diff options
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 33 |
1 files changed, 28 insertions, 5 deletions
@@ -1,7 +1,7 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | bitmap::{MapPoint, Pixmap}, | 2 | bitmap::{MapPoint, Pixmap}, |
3 | command::CommandBox, | 3 | command::CommandBox, |
4 | consts::colors::*, | 4 | consts::{colors::*, FONT_PATH}, |
5 | dither, rect, | 5 | dither, rect, |
6 | symmetry::Symmetry, | 6 | symmetry::Symmetry, |
7 | undo::{ModifyRecord, OpKind, Operation, UndoStack}, | 7 | undo::{ModifyRecord, OpKind, Operation, UndoStack}, |
@@ -352,6 +352,20 @@ impl<'ctx> AppState<'ctx> { | |||
352 | BLACK, | 352 | BLACK, |
353 | (0, winsize_y - cmd_height), | 353 | (0, winsize_y - cmd_height), |
354 | ); | 354 | ); |
355 | |||
356 | self.canvas.set_draw_color(PINK); | ||
357 | let mut font = self.ttf_context.load_font(FONT_PATH, 17).unwrap(); | ||
358 | font.set_style(sdl2::ttf::FontStyle::NORMAL); | ||
359 | font.set_hinting(sdl2::ttf::Hinting::Mono); | ||
360 | let prev_text = &self.command_box.text[..self.command_box.cursor]; | ||
361 | let prev_text_dim = font.size_of_latin1(prev_text.as_bytes()).unwrap(); | ||
362 | let cursor = rect!( | ||
363 | prev_text_dim.0, | ||
364 | winsize_y - cmd_height + 2, | ||
365 | 2, | ||
366 | cmd_height - 4 | ||
367 | ); | ||
368 | self.canvas.fill_rect(cursor).unwrap(); | ||
355 | } | 369 | } |
356 | 370 | ||
357 | fn draw_mouse(&mut self) { | 371 | fn draw_mouse(&mut self) { |
@@ -641,7 +655,9 @@ impl<'ctx> AppState<'ctx> { | |||
641 | } | 655 | } |
642 | } | 656 | } |
643 | if let Event::KeyDown { | 657 | if let Event::KeyDown { |
644 | keycode: Some(k), .. | 658 | keycode: Some(k), |
659 | keymod, | ||
660 | .. | ||
645 | } = event | 661 | } = event |
646 | { | 662 | { |
647 | match k { | 663 | match k { |
@@ -651,9 +667,16 @@ impl<'ctx> AppState<'ctx> { | |||
651 | Keycode::Right => self.command_box.forward(), | 667 | Keycode::Right => self.command_box.forward(), |
652 | Keycode::Up => self.command_box.hist_prev(), | 668 | Keycode::Up => self.command_box.hist_prev(), |
653 | Keycode::Down => self.command_box.hist_next(), | 669 | Keycode::Down => self.command_box.hist_next(), |
654 | Keycode::Return => { | 670 | _ if keymod == Mod::LCTRLMOD => match k { |
655 | self.eval_command(); | 671 | Keycode::A => self.command_box.cursor_start(), |
656 | } | 672 | Keycode::E => self.command_box.cursor_end(), |
673 | Keycode::F => self.command_box.forward(), | ||
674 | Keycode::B => self.command_box.backward(), | ||
675 | Keycode::K => self.command_box.delete_to_end(), | ||
676 | Keycode::U => self.command_box.delete_to_start(), | ||
677 | _ => (), | ||
678 | }, | ||
679 | Keycode::Return => self.eval_command(), | ||
657 | Keycode::Escape => { | 680 | Keycode::Escape => { |
658 | self.command_box.clear(); | 681 | self.command_box.clear(); |
659 | self.mode = Mode::Draw; | 682 | self.mode = Mode::Draw; |