Maraiah/source/rozinante/editor.rs

96 lines
2.2 KiB
Rust

//! Main map editor module.
//!
//! The entry point is responsible for maintaining the lifetime of the editor
//! state and human interactions with it, but is otherwise not permitted to
//! directly edit it.
pub mod block;
pub mod state;
use crate::durandal::image::*;
use super::{color, draw::*};
impl MapEditor
{
/// Creates a closed map editor.
#[inline]
pub const fn new_closed() -> Self
{
MapEditor::Closed
}
/// Opens the editor with a new empty map.
#[inline]
pub fn open_new(&mut self)
{
*self = MapEditor::Opened(state::State::default());
}
/// 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 {
MapEditor::Closed => {
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);
}
MapEditor::Opened(st) => {
d.clear(Color16::new(0, 0, 0));
d.text((dw/2, dh/2), &format!("tool: {:?}", st.tool), color::RED);
}
}
}
/// Returns `true` if `self` is closed.
#[inline]
pub fn is_closed(&self) -> bool
{
match self {
MapEditor::Closed => true,
MapEditor::Opened(_) => false,
}
}
/// Returns `true` if `self` is opened.
#[inline]
pub fn is_opened(&self) -> bool
{
match self {
MapEditor::Closed => false,
MapEditor::Opened(_) => true,
}
}
}
impl Default for MapEditor
{
#[inline]
fn default() -> Self {Self::new_closed()}
}
/// An entire map editor, which may be opened or closed.
pub enum MapEditor
{
Closed,
Opened(state::State),
}
// EOF