aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-03-30 12:21:51 +0100
committerAkshay <[email protected]>2021-03-30 12:21:51 +0100
commita76cd56b9f8cce132555f6c3b59d76da5ae86f6b (patch)
treefa4be0bf498a55ae936f07b8ad88a48f66f48a57 /src/app.rs
parentc3498ef7e2c5f5f1dfafb07e50370c4f62f4d69e (diff)
add new catch-all error types
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/app.rs b/src/app.rs
index ffa73dd..fb6e9df 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -2,14 +2,15 @@ use crate::{
2 bitmap::{positive_angle_with_x, MapPoint, Pixmap}, 2 bitmap::{positive_angle_with_x, MapPoint, Pixmap},
3 brush::{Brush, CircleBrush, LineBrush}, 3 brush::{Brush, CircleBrush, LineBrush},
4 command::CommandBox, 4 command::CommandBox,
5 consts::{colors::*, FONT_PATH}, 5 consts::{colors::*, FONT_PATH, STDLIB_PATH},
6 dither, 6 dither,
7 error::AppError,
7 lisp::{eval, lex::Lexer, parse::Parser, prelude, EnvList}, 8 lisp::{eval, lex::Lexer, parse::Parser, prelude, EnvList},
8 message::Message, 9 message::Message,
9 rect, 10 rect,
10 symmetry::Symmetry, 11 symmetry::Symmetry,
11 undo::{ModifyRecord, OpKind, PaintRecord, UndoStack}, 12 undo::{ModifyRecord, OpKind, PaintRecord, UndoStack},
12 utils::{draw_text, handle_error, is_copy_event, is_paste_event}, 13 utils::{draw_text, handle_error, is_copy_event, is_paste_event, load_script},
13}; 14};
14 15
15use std::{convert::From, fs::File, io::prelude::*, path::Path}; 16use std::{convert::From, fs::File, io::prelude::*, path::Path};
@@ -284,7 +285,7 @@ impl<'ctx, 'file> AppState<'ctx, 'file> {
284 Ok(val) => self.message.set_info(format!("{}", val)), 285 Ok(val) => self.message.set_info(format!("{}", val)),
285 Err(eval_err) => self.message.set_error(format!("{}", eval_err)), 286 Err(eval_err) => self.message.set_error(format!("{}", eval_err)),
286 }, 287 },
287 Err(err) => self.message = handle_error(err, &lisp_expr), 288 Err(err) => self.message = handle_error(err, &lisp_expr, "repl"),
288 } 289 }
289 self.command_box.hist_append(); 290 self.command_box.hist_append();
290 291
@@ -510,8 +511,8 @@ impl<'ctx, 'file> AppState<'ctx, 'file> {
510 ttf_context: &'ctx Sdl2TtfContext, 511 ttf_context: &'ctx Sdl2TtfContext,
511 start_data: Option<Vec<bool>>, 512 start_data: Option<Vec<bool>>,
512 file_name: Option<&'file Path>, 513 file_name: Option<&'file Path>,
513 ) -> Self { 514 ) -> Result<Self, AppError> {
514 let video_subsystem = context.video().unwrap(); 515 let video_subsystem = context.video().map_err(AppError::Sdl)?;
515 516
516 let window = video_subsystem 517 let window = video_subsystem
517 .window("Pixel editor", 500, 500) 518 .window("Pixel editor", 500, 500)
@@ -519,18 +520,16 @@ impl<'ctx, 'file> AppState<'ctx, 'file> {
519 .resizable() 520 .resizable()
520 .opengl() 521 .opengl()
521 .build() 522 .build()
522 .map_err(|e| e.to_string()) 523 .map_err(|e| AppError::Sdl(e.to_string()))?;
523 .unwrap();
524 524
525 let canvas = window 525 let canvas = window
526 .into_canvas() 526 .into_canvas()
527 .build() 527 .build()
528 .map_err(|e| e.to_string()) 528 .map_err(|e| AppError::Sdl(e.to_string()))?;
529 .unwrap();
530 529
531 let data = start_data.unwrap_or(vec![false; (width * height) as usize]); 530 let data = start_data.unwrap_or(vec![false; (width * height) as usize]);
532 let pixmap = Pixmap::new_with(width, height, data); 531 let pixmap = Pixmap::new_with(width, height, data);
533 Self { 532 let mut app = Self {
534 active_color: true, 533 active_color: true,
535 brush: Brush::new(0), 534 brush: Brush::new(0),
536 canvas, 535 canvas,
@@ -540,7 +539,7 @@ impl<'ctx, 'file> AppState<'ctx, 'file> {
540 dither_level: 16, 539 dither_level: 16,
541 file_name, 540 file_name,
542 grid: Grid::new(), 541 grid: Grid::new(),
543 lisp_env: vec![prelude::new_env()], 542 lisp_env: vec![prelude::new_env().map_err(AppError::Lisp)?],
544 message: Message::new().text(" "), 543 message: Message::new().text(" "),
545 mode: Mode::Draw, 544 mode: Mode::Draw,
546 mouse: (0, 0), 545 mouse: (0, 0),
@@ -550,7 +549,9 @@ impl<'ctx, 'file> AppState<'ctx, 'file> {
550 ttf_context, 549 ttf_context,
551 undo_stack: UndoStack::new(), 550 undo_stack: UndoStack::new(),
552 zoom: 5, 551 zoom: 5,
553 } 552 };
553 load_script(STDLIB_PATH, &mut app).map_err(AppError::Lisp)?;
554 Ok(app)
554 } 555 }
555 556
556 pub fn export(&self) -> Image { 557 pub fn export(&self) -> Image {