Maraiah/source/rozinante/editor.rs

91 lines
2.1 KiB
Rust

//! Main map editor module.
//!
//! The entry point is responsible for maintaining the lifetime of the editor
//! and human interactions with it, but is otherwise not permitted to directly
//! edit it.
mod block;
mod state;
use crate::durandal::image::*;
use super::{color, draw::*};
impl MapEditor
{
/// Opens the editor with a new empty map.
#[inline]
pub fn open_new(&mut self)
{
self.map = Some(state::OpenMap::default());
}
/// Opens the editor with an existing map.
pub fn open_buf(&mut self, b: &[u8])
{
self.map = Some(state::OpenMap::open_buf(b));
}
/// Draws the screen for this editor state.
pub fn draw<D, I>(&self, d: &mut D, im: &I)
where D: DrawArea<NativeImage = I>,
I: CacheImage
{
let dw = d.w();
let dh = d.h();
let iw = im.w();
let ih = im.h();
match &self.map {
None => {
let tx_top = "Map Required To Proceed";
let tx_bot = "CAS.qterm//CyberAcme Systems Inc.";
d.clear(Color16::new(0, 0, 0));
d.image((dw / 2 - iw / 2, dh / 2 - ih / 2), im);
d.rect(Rect{x: 0, y: 0, w: dw, h: 18}, color::DARK_RED);
d.text((4, 14), tx_top, color::RED);
d.rect(Rect{x: 0, y: dh - 18, w: dw, h: 18}, color::DARK_RED);
d.text((4, dh - 4), tx_bot, color::RED);
}
Some(st) => {
let text = &format!("tool: {:?}", st.tool());
d.clear(Color16::new(0, 0, 0));
d.text((dw/2, dh/2), text, color::RED);
}
}
}
/// Returns `true` if `self` is closed.
#[inline]
pub fn is_closed(&self) -> bool
{
self.map.is_none()
}
/// Returns `true` if `self` is opened.
#[inline]
pub fn is_opened(&self) -> bool
{
self.map.is_some()
}
}
impl Default for MapEditor
{
#[inline]
fn default() -> Self {Self{map: None}}
}
/// An entire map editor, which may be opened or closed. Holds state which
/// outlives the opened map state.
pub struct MapEditor
{
map: Option<state::OpenMap>,
}
// EOF