diff options
author | Akshay <[email protected]> | 2021-03-23 07:38:54 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-03-23 07:38:54 +0000 |
commit | 66c427ef00014f5939ba23f00fbc7f8fd089b66b (patch) | |
tree | a173d27f533ae0ceaa6fa822f725410950d46d4e | |
parent | 6541f29a0eb16ba2a0459376d38466b8563f5d2d (diff) |
add invert function and keybinds
-rw-r--r-- | src/app.rs | 44 | ||||
-rw-r--r-- | src/bitmap.rs | 8 | ||||
-rw-r--r-- | src/lisp/error.rs | 1 |
3 files changed, 33 insertions, 20 deletions
@@ -30,28 +30,30 @@ pub enum Mode { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | pub struct AppState<'ctx> { | 32 | pub struct AppState<'ctx> { |
33 | active_color: bool, | 33 | pub active_color: bool, |
34 | brush_size: u8, | 34 | pub brush_size: u8, |
35 | canvas: Canvas<Window>, | 35 | pub canvas: Canvas<Window>, |
36 | context: &'ctx Sdl, | 36 | pub command_box: CommandBox, |
37 | current_operation: Operation, | 37 | pub context: &'ctx Sdl, |
38 | dither_level: u8, | 38 | pub current_operation: Operation, |
39 | grid: Grid, | 39 | pub dither_level: u8, |
40 | last_point: Option<MapPoint>, | 40 | pub grid: Grid, |
41 | mode: Mode, | 41 | pub last_point: Option<MapPoint>, |
42 | mouse: (i32, i32), | 42 | pub lisp_env: Environment, |
43 | pixmap: Pixmap<bool>, | 43 | pub message: Message, |
44 | start: Point, | 44 | pub mode: Mode, |
45 | symmetry: Symmetry, | 45 | pub mouse: (i32, i32), |
46 | ttf_context: &'ctx Sdl2TtfContext, | 46 | pub pixmap: Pixmap<bool>, |
47 | undo_stack: UndoStack<Operation>, | 47 | pub start: Point, |
48 | command_box: CommandBox, | 48 | pub symmetry: Symmetry, |
49 | zoom: u8, | 49 | pub ttf_context: &'ctx Sdl2TtfContext, |
50 | pub undo_stack: UndoStack<Operation>, | ||
51 | pub zoom: u8, | ||
50 | } | 52 | } |
51 | 53 | ||
52 | struct Grid { | 54 | pub struct Grid { |
53 | enabled: bool, | 55 | pub enabled: bool, |
54 | color: Color, | 56 | pub color: Color, |
55 | } | 57 | } |
56 | 58 | ||
57 | impl Grid { | 59 | impl Grid { |
@@ -563,6 +565,8 @@ impl<'ctx> AppState<'ctx> { | |||
563 | Keycode::X => self.change_active_color(), | 565 | Keycode::X => self.change_active_color(), |
564 | // toggle grid | 566 | // toggle grid |
565 | Keycode::Tab => self.toggle_grid(), | 567 | Keycode::Tab => self.toggle_grid(), |
568 | // invert canvas | ||
569 | Keycode::I => self.pixmap.invert(), | ||
566 | // line drawing | 570 | // line drawing |
567 | Keycode::F => { | 571 | Keycode::F => { |
568 | let end: Point = (mouse.x(), mouse.y()).into(); | 572 | let end: Point = (mouse.x(), mouse.y()).into(); |
diff --git a/src/bitmap.rs b/src/bitmap.rs index d02cafb..c7e8fd4 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs | |||
@@ -231,6 +231,14 @@ where | |||
231 | } | 231 | } |
232 | } | 232 | } |
233 | 233 | ||
234 | impl Pixmap<bool> { | ||
235 | pub fn invert(&mut self) { | ||
236 | for px in self.data.iter_mut() { | ||
237 | *px = !(*px); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | |||
234 | fn abs_difference<T: Sub<Output = T> + Ord>(x: T, y: T) -> T { | 242 | fn abs_difference<T: Sub<Output = T> + Ord>(x: T, y: T) -> T { |
235 | if x < y { | 243 | if x < y { |
236 | y - x | 244 | y - x |
diff --git a/src/lisp/error.rs b/src/lisp/error.rs index b789f7f..7214753 100644 --- a/src/lisp/error.rs +++ b/src/lisp/error.rs | |||
@@ -3,4 +3,5 @@ use crate::lisp::lex::Span; | |||
3 | #[derive(Debug, PartialEq, Copy, Clone)] | 3 | #[derive(Debug, PartialEq, Copy, Clone)] |
4 | pub enum LispError { | 4 | pub enum LispError { |
5 | ParseError, | 5 | ParseError, |
6 | EvalError, | ||
6 | } | 7 | } |