From 83732aed1a41a713cd8790fcebae90aabe78b789 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 17 Mar 2021 17:52:11 +0530 Subject: read and write to .obi files --- src/app.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index 9a1155e..5b27422 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,17 +1,19 @@ use crate::{ bitmap::{MapPoint, Pixmap}, + command::CommandBox, consts::colors::*, dither, rect, symmetry::Symmetry, undo::{ModifyRecord, OpKind, Operation, UndoStack}, - utils::draw_text, + utils::{draw_text, is_copy_event, is_paste_event}, }; -use std::convert::From; +use std::{convert::From, fs::File, io::prelude::*}; +use obi::Image; use sdl2::{ event::Event, - keyboard::Keycode, + keyboard::{Keycode, Mod}, mouse::MouseButton, pixels::Color, rect::{Point, Rect}, @@ -286,15 +288,17 @@ impl<'ctx> AppState<'ctx> { )) .unwrap(); let mouse_coords = if let Some((x, y)) = self.idx_at_coord(self.mouse) { - format!("{:3}, {:3}", x, y) + format!("{:3}, {:3}", x + 1, y + 1) } else { format!("---, ---") }; let status_text = format!( - "[BRUSH {}] [SYM {}] {}", + "[DITHER {}][BRUSH {}][SYM {}][PT {}][ACTIVE {}]", + self.dither_level, self.brush_size + 1, self.symmetry, - mouse_coords + mouse_coords, + if self.active_color { "WHT" } else { "BLK" } ); draw_text( &mut self.canvas, @@ -383,6 +387,7 @@ impl<'ctx> AppState<'ctx> { height: u32, context: &'ctx Sdl, ttf_context: &'ctx Sdl2TtfContext, + start_data: Option>, ) -> Self { let video_subsystem = context.video().unwrap(); @@ -401,26 +406,35 @@ impl<'ctx> AppState<'ctx> { .map_err(|e| e.to_string()) .unwrap(); - let pixmap = Pixmap::new_with(width, height, false); + let data = start_data.unwrap_or(vec![false; (width * height) as usize]); + let pixmap = Pixmap::new_with(width, height, data); Self { active_color: true, brush_size: 0, - dither_level: 16, canvas, context, - ttf_context, - mouse: (0, 0), + command_box: CommandBox::new(), current_operation: Vec::new(), + dither_level: 16, grid: Grid::new(), last_point: None, + mode: Mode::Draw, + mouse: (0, 0), pixmap, start: Point::new(60, 60), symmetry: Default::default(), + ttf_context, undo_stack: UndoStack::new(), zoom: 5, } } + pub fn export(&self) -> Image { + let mut image = Image::new(self.width(), self.height()); + image.data = self.pixmap.data.clone(); + image + } + pub fn run(&mut self) { self.canvas.set_draw_color(BLACK); self.canvas.clear(); -- cgit v1.2.3