diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 34 | ||||
-rw-r--r-- | src/bitmap.rs | 3 | ||||
-rw-r--r-- | src/symmetry.rs | 8 | ||||
-rw-r--r-- | src/utils.rs | 2 |
4 files changed, 30 insertions, 17 deletions
@@ -1,17 +1,19 @@ | |||
1 | use crate::{ | 1 | use 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 | ||
10 | use std::convert::From; | 11 | use std::{convert::From, fs::File, io::prelude::*}; |
11 | 12 | ||
13 | use obi::Image; | ||
12 | use sdl2::{ | 14 | use 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(); |
diff --git a/src/bitmap.rs b/src/bitmap.rs index 128a14e..d02cafb 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs | |||
@@ -113,8 +113,7 @@ where | |||
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | pub fn new_with(width: u32, height: u32, start: T) -> Self { | 116 | pub fn new_with(width: u32, height: u32, data: Vec<T>) -> Self { |
117 | let data = vec![start; (width * height) as usize]; | ||
118 | Pixmap { | 117 | Pixmap { |
119 | width, | 118 | width, |
120 | height, | 119 | height, |
diff --git a/src/symmetry.rs b/src/symmetry.rs index 7517317..60ff791 100644 --- a/src/symmetry.rs +++ b/src/symmetry.rs | |||
@@ -33,10 +33,10 @@ impl fmt::Display for Symmetry { | |||
33 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 33 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
34 | let Symmetry { x, y } = self; | 34 | let Symmetry { x, y } = self; |
35 | match (x, y) { | 35 | match (x, y) { |
36 | (None, None) => write!(f, " "), | 36 | (None, None) => write!(f, "OFF"), |
37 | (Some(_), None) => write!(f, "-"), | 37 | (Some(_), None) => write!(f, "HOR"), |
38 | (None, Some(_)) => write!(f, "|"), | 38 | (None, Some(_)) => write!(f, "VER"), |
39 | (Some(_), Some(_)) => write!(f, "+"), | 39 | (Some(_), Some(_)) => write!(f, "RAD"), |
40 | } | 40 | } |
41 | } | 41 | } |
42 | } | 42 | } |
diff --git a/src/utils.rs b/src/utils.rs index e36a8cc..a1b3624 100644 --- a/src/utils.rs +++ b/src/utils.rs | |||
@@ -14,7 +14,7 @@ pub fn draw_text<S: AsRef<str>>( | |||
14 | text: S, | 14 | text: S, |
15 | color: Color, | 15 | color: Color, |
16 | (x, y): (u32, u32), | 16 | (x, y): (u32, u32), |
17 | ) { | 17 | ) -> u32 { |
18 | let text = text.as_ref(); | 18 | let text = text.as_ref(); |
19 | let texture_creator = canvas.texture_creator(); | 19 | let texture_creator = canvas.texture_creator(); |
20 | let mut font = ttf_context.load_font(FONT_PATH, 17).unwrap(); | 20 | let mut font = ttf_context.load_font(FONT_PATH, 17).unwrap(); |