From 2d4f2b5a8c0ba1dbec8e295a1b5605dd9028d071 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 15 Mar 2021 21:06:20 +0530 Subject: factor out common utils into module --- src/app.rs | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'src/app.rs') 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 @@ use crate::{ bitmap::{MapPoint, Pixmap}, - consts::{colors::*, FONT_PATH}, + consts::colors::*, + rect, symmetry::Symmetry, undo::{ModifyRecord, OpKind, Operation, UndoStack}, + utils::draw_text, }; -use std::convert::{From, TryFrom}; +use std::convert::From; use sdl2::{ event::Event, @@ -19,12 +21,6 @@ use sdl2::{ Sdl, }; -macro_rules! quick_rect( - ($x:expr, $y:expr, $w:expr, $h:expr) => ( - Rect::new($x as i32, $y as i32, $w as u32, $h as u32) - ) -); - pub struct AppState<'ctx> { active_color: bool, brush_size: u8, @@ -260,7 +256,7 @@ impl<'ctx> AppState<'ctx> { let status_width = winsize_x; self.canvas.set_draw_color(WHITE); self.canvas - .fill_rect(quick_rect!( + .fill_rect(rect!( 0, winsize_y - status_height, status_width, @@ -520,24 +516,3 @@ impl<'ctx> AppState<'ctx> { } } } - -fn draw_text>( - canvas: &mut Canvas, - ttf_context: &Sdl2TtfContext, - text: S, - color: Color, - (x, y): (u32, u32), -) { - let text = text.as_ref(); - let texture_creator = canvas.texture_creator(); - let mut font = ttf_context.load_font(FONT_PATH, 17).unwrap(); - font.set_style(sdl2::ttf::FontStyle::NORMAL); - font.set_hinting(sdl2::ttf::Hinting::Mono); - let surface = font.render(text.as_ref()).blended(color).unwrap(); - let texture = texture_creator - .create_texture_from_surface(&surface) - .unwrap(); - let (width, height) = font.size_of_latin1(text.as_bytes()).unwrap(); - let area = quick_rect!(x, y, width, height); - canvas.copy(&texture, None, area).unwrap(); -} -- cgit v1.2.3