aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs35
1 files changed, 5 insertions, 30 deletions
diff --git a/src/app.rs b/src/app.rs
index 03389fb..059635a 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,11 +1,13 @@
1use crate::{ 1use crate::{
2 bitmap::{MapPoint, Pixmap}, 2 bitmap::{MapPoint, Pixmap},
3 consts::{colors::*, FONT_PATH}, 3 consts::colors::*,
4 rect,
4 symmetry::Symmetry, 5 symmetry::Symmetry,
5 undo::{ModifyRecord, OpKind, Operation, UndoStack}, 6 undo::{ModifyRecord, OpKind, Operation, UndoStack},
7 utils::draw_text,
6}; 8};
7 9
8use std::convert::{From, TryFrom}; 10use std::convert::From;
9 11
10use sdl2::{ 12use sdl2::{
11 event::Event, 13 event::Event,
@@ -19,12 +21,6 @@ use sdl2::{
19 Sdl, 21 Sdl,
20}; 22};
21 23
22macro_rules! quick_rect(
23 ($x:expr, $y:expr, $w:expr, $h:expr) => (
24 Rect::new($x as i32, $y as i32, $w as u32, $h as u32)
25 )
26);
27
28pub struct AppState<'ctx> { 24pub struct AppState<'ctx> {
29 active_color: bool, 25 active_color: bool,
30 brush_size: u8, 26 brush_size: u8,
@@ -260,7 +256,7 @@ impl<'ctx> AppState<'ctx> {
260 let status_width = winsize_x; 256 let status_width = winsize_x;
261 self.canvas.set_draw_color(WHITE); 257 self.canvas.set_draw_color(WHITE);
262 self.canvas 258 self.canvas
263 .fill_rect(quick_rect!( 259 .fill_rect(rect!(
264 0, 260 0,
265 winsize_y - status_height, 261 winsize_y - status_height,
266 status_width, 262 status_width,
@@ -520,24 +516,3 @@ impl<'ctx> AppState<'ctx> {
520 } 516 }
521 } 517 }
522} 518}
523
524fn draw_text<S: AsRef<str>>(
525 canvas: &mut Canvas<Window>,
526 ttf_context: &Sdl2TtfContext,
527 text: S,
528 color: Color,
529 (x, y): (u32, u32),
530) {
531 let text = text.as_ref();
532 let texture_creator = canvas.texture_creator();
533 let mut font = ttf_context.load_font(FONT_PATH, 17).unwrap();
534 font.set_style(sdl2::ttf::FontStyle::NORMAL);
535 font.set_hinting(sdl2::ttf::Hinting::Mono);
536 let surface = font.render(text.as_ref()).blended(color).unwrap();
537 let texture = texture_creator
538 .create_texture_from_surface(&surface)
539 .unwrap();
540 let (width, height) = font.size_of_latin1(text.as_bytes()).unwrap();
541 let area = quick_rect!(x, y, width, height);
542 canvas.copy(&texture, None, area).unwrap();
543}