From 66c427ef00014f5939ba23f00fbc7f8fd089b66b Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 23 Mar 2021 13:08:54 +0530 Subject: add invert function and keybinds --- src/app.rs | 44 ++++++++++++++++++++++++-------------------- src/bitmap.rs | 8 ++++++++ src/lisp/error.rs | 1 + 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/app.rs b/src/app.rs index 063f54f..f6e2b96 100644 --- a/src/app.rs +++ b/src/app.rs @@ -30,28 +30,30 @@ pub enum Mode { } pub struct AppState<'ctx> { - active_color: bool, - brush_size: u8, - canvas: Canvas, - context: &'ctx Sdl, - current_operation: Operation, - dither_level: u8, - grid: Grid, - last_point: Option, - mode: Mode, - mouse: (i32, i32), - pixmap: Pixmap, - start: Point, - symmetry: Symmetry, - ttf_context: &'ctx Sdl2TtfContext, - undo_stack: UndoStack, - command_box: CommandBox, - zoom: u8, + pub active_color: bool, + pub brush_size: u8, + pub canvas: Canvas, + pub command_box: CommandBox, + pub context: &'ctx Sdl, + pub current_operation: Operation, + pub dither_level: u8, + pub grid: Grid, + pub last_point: Option, + pub lisp_env: Environment, + pub message: Message, + pub mode: Mode, + pub mouse: (i32, i32), + pub pixmap: Pixmap, + pub start: Point, + pub symmetry: Symmetry, + pub ttf_context: &'ctx Sdl2TtfContext, + pub undo_stack: UndoStack, + pub zoom: u8, } -struct Grid { - enabled: bool, - color: Color, +pub struct Grid { + pub enabled: bool, + pub color: Color, } impl Grid { @@ -563,6 +565,8 @@ impl<'ctx> AppState<'ctx> { Keycode::X => self.change_active_color(), // toggle grid Keycode::Tab => self.toggle_grid(), + // invert canvas + Keycode::I => self.pixmap.invert(), // line drawing Keycode::F => { 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 } } +impl Pixmap { + pub fn invert(&mut self) { + for px in self.data.iter_mut() { + *px = !(*px); + } + } +} + fn abs_difference + Ord>(x: T, y: T) -> T { if x < y { 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; #[derive(Debug, PartialEq, Copy, Clone)] pub enum LispError { ParseError, + EvalError, } -- cgit v1.2.3