diff --git a/tycho/source/gui/mapmodel.rs b/tycho/source/gui/mapmodel.rs index e209320..3a7cbaa 100644 --- a/tycho/source/gui/mapmodel.rs +++ b/tycho/source/gui/mapmodel.rs @@ -1,9 +1,36 @@ //! Map model. use super::qobj::*; -use maraiah::{backtrace, err::*, map::{self, data::*}}; +use maraiah::{backtrace, err::*, fixed, map::{self, data::*}}; use crate::cc; +fn to_screen(coord: fixed::Unit) -> i16 +{ + let long = fixed::FixedLong::from_unit(coord); + (long * 10).integ() as i16 +} + +fn draw_points<'a, P>(paint: *mut cc::QPainter, pnts: &'a [P]) + where P: Into, + map::pnts::Point: From<&'a P> +{ + for p in pnts.iter() { + let p: map::pnts::Point = p.into(); + cc::paint_point(paint, to_screen(p.x), to_screen(p.y)); + } +} + +fn draw_map(paint: *mut cc::QPainter, entry: &EntryData) +{ + cc::paint_fg(paint, 0, 255, 0, 255); + + if let Some(pnts) = &entry.pnts { + draw_points(paint, pnts.as_slice()); + } else if let Some(epnt) = &entry.epnt { + draw_points(paint, epnt.as_slice()); + } +} + impl IMapModel { pub fn open_map(path: String) -> ResultS @@ -61,10 +88,6 @@ impl IMapModelTrait for IMapModel /// Opens the map file at `path`. fn open(&mut self, path: String) -> bool { - if cfg!(debug_assertions) { - eprintln!("opening project: {}", &path); - } - match Self::open_map(path) { Ok(map) => { self.map = map; @@ -107,28 +130,18 @@ impl IMapModelTrait for IMapModel fn select(&mut self, index: u16) { - if cfg!(debug_assertions) { - eprintln!("selecting map {}", index); - } - self.selected = Some(index); } fn draw_view(&self, paint: *mut cc::QPainter) { - cc::paint_fg(paint, 0, 255, 0, 255); - cc::paint_arc(paint, 30, 30, 100, 100, 77, 440); - cc::paint_chord(paint, 50, 50, 100, 100, 77, 440); - cc::paint_ellipse(paint, 80, 80, 30, 30); - cc::paint_image(paint, 200, 10, ":/tycho/images/tycho1.png"); - cc::paint_line(paint, 100, 60, 140, 100); - cc::paint_point(paint, 20, 20); - cc::paint_polygon(paint, &[cc::Int2{x: 250, y: 170}, - cc::Int2{x: 270, y: 190}, - cc::Int2{x: 230, y: 190}]); - cc::paint_rect(paint, 150, 170, 20, 20); - cc::paint_squircle(paint, 90, 170, 30, 30, 7, 9); - cc::paint_text(paint, 50, 50, "hello, world"); + if let Some(selected) = self.selected { + if let Some(entry) = self.map.get(&selected) { + if entry.get_type() == EntryType::Map { + draw_map(paint, entry); + } + } + } } }