aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs34
1 files changed, 24 insertions, 10 deletions
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 @@
1use crate::{ 1use crate::{
2 bitmap::{MapPoint, Pixmap}, 2 bitmap::{MapPoint, Pixmap},
3 command::CommandBox,
3 consts::colors::*, 4 consts::colors::*,
4 dither, rect, 5 dither, rect,
5 symmetry::Symmetry, 6 symmetry::Symmetry,
6 undo::{ModifyRecord, OpKind, Operation, UndoStack}, 7 undo::{ModifyRecord, OpKind, Operation, UndoStack},
7 utils::draw_text, 8 utils::{draw_text, is_copy_event, is_paste_event},
8}; 9};
9 10
10use std::convert::From; 11use std::{convert::From, fs::File, io::prelude::*};
11 12
13use obi::Image;
12use sdl2::{ 14use sdl2::{
13 event::Event, 15 event::Event,
14 keyboard::Keycode, 16 keyboard::{Keycode, Mod},
15 mouse::MouseButton, 17 mouse::MouseButton,
16 pixels::Color, 18 pixels::Color,
17 rect::{Point, Rect}, 19 rect::{Point, Rect},
@@ -286,15 +288,17 @@ impl<'ctx> AppState<'ctx> {
286 )) 288 ))
287 .unwrap(); 289 .unwrap();
288 let mouse_coords = if let Some((x, y)) = self.idx_at_coord(self.mouse) { 290 let mouse_coords = if let Some((x, y)) = self.idx_at_coord(self.mouse) {
289 format!("{:3}, {:3}", x, y) 291 format!("{:3}, {:3}", x + 1, y + 1)
290 } else { 292 } else {
291 format!("---, ---") 293 format!("---, ---")
292 }; 294 };
293 let status_text = format!( 295 let status_text = format!(
294 "[BRUSH {}] [SYM {}] {}", 296 "[DITHER {}][BRUSH {}][SYM {}][PT {}][ACTIVE {}]",
297 self.dither_level,
295 self.brush_size + 1, 298 self.brush_size + 1,
296 self.symmetry, 299 self.symmetry,
297 mouse_coords 300 mouse_coords,
301 if self.active_color { "WHT" } else { "BLK" }
298 ); 302 );
299 draw_text( 303 draw_text(
300 &mut self.canvas, 304 &mut self.canvas,
@@ -383,6 +387,7 @@ impl<'ctx> AppState<'ctx> {
383 height: u32, 387 height: u32,
384 context: &'ctx Sdl, 388 context: &'ctx Sdl,
385 ttf_context: &'ctx Sdl2TtfContext, 389 ttf_context: &'ctx Sdl2TtfContext,
390 start_data: Option<Vec<bool>>,
386 ) -> Self { 391 ) -> Self {
387 let video_subsystem = context.video().unwrap(); 392 let video_subsystem = context.video().unwrap();
388 393
@@ -401,26 +406,35 @@ impl<'ctx> AppState<'ctx> {
401 .map_err(|e| e.to_string()) 406 .map_err(|e| e.to_string())
402 .unwrap(); 407 .unwrap();
403 408
404 let pixmap = Pixmap::new_with(width, height, false); 409 let data = start_data.unwrap_or(vec![false; (width * height) as usize]);
410 let pixmap = Pixmap::new_with(width, height, data);
405 Self { 411 Self {
406 active_color: true, 412 active_color: true,
407 brush_size: 0, 413 brush_size: 0,
408 dither_level: 16,
409 canvas, 414 canvas,
410 context, 415 context,
411 ttf_context, 416 command_box: CommandBox::new(),
412 mouse: (0, 0),
413 current_operation: Vec::new(), 417 current_operation: Vec::new(),
418 dither_level: 16,
414 grid: Grid::new(), 419 grid: Grid::new(),
415 last_point: None, 420 last_point: None,
421 mode: Mode::Draw,
422 mouse: (0, 0),
416 pixmap, 423 pixmap,
417 start: Point::new(60, 60), 424 start: Point::new(60, 60),
418 symmetry: Default::default(), 425 symmetry: Default::default(),
426 ttf_context,
419 undo_stack: UndoStack::new(), 427 undo_stack: UndoStack::new(),
420 zoom: 5, 428 zoom: 5,
421 } 429 }
422 } 430 }
423 431
432 pub fn export(&self) -> Image {
433 let mut image = Image::new(self.width(), self.height());
434 image.data = self.pixmap.data.clone();
435 image
436 }
437
424 pub fn run(&mut self) { 438 pub fn run(&mut self) {
425 self.canvas.set_draw_color(BLACK); 439 self.canvas.set_draw_color(BLACK);
426 self.canvas.clear(); 440 self.canvas.clear();