diff --git a/source/durandal/ffi.rs b/source/durandal/ffi.rs index 37ee01c..4931034 100644 --- a/source/durandal/ffi.rs +++ b/source/durandal/ffi.rs @@ -50,6 +50,11 @@ impl CStringVec } } +impl Default for CStringVec +{ + fn default() -> Self {Self::new()} +} + /// An owned null-terminated string vector. #[derive(Debug)] pub struct CStringVec diff --git a/source/rozinante.rs b/source/rozinante.rs index 96e17cb..260c5eb 100644 --- a/source/rozinante.rs +++ b/source/rozinante.rs @@ -2,5 +2,6 @@ pub mod color; pub mod draw; +pub mod editor; // EOF diff --git a/source/rozinante/color.rs b/source/rozinante/color.rs index 939f7d8..790c9ee 100644 --- a/source/rozinante/color.rs +++ b/source/rozinante/color.rs @@ -2,7 +2,7 @@ use crate::durandal::image::Color16; -pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0); -pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 0, 0); +pub const RED: Color16 = Color16::new(0xFFFF, 0, 0); +pub const DARK_RED: Color16 = Color16::new(0x4700, 0, 0); // EOF diff --git a/source/tycho/editor.rs b/source/rozinante/editor.rs similarity index 65% rename from source/tycho/editor.rs rename to source/rozinante/editor.rs index 25745c9..3192f0d 100644 --- a/source/tycho/editor.rs +++ b/source/rozinante/editor.rs @@ -4,9 +4,11 @@ //! state and human interactions with it, but is otherwise not permitted to //! directly edit it. -use maraiah::{durandal::image::*, - marathon::map, - rozinante::{color::*, draw::*}}; +pub mod block; +pub mod state; + +use crate::durandal::image::*; +use super::{color, draw::*}; impl MapEditor { @@ -21,7 +23,7 @@ impl MapEditor #[inline] pub fn open_new(&mut self) { - *self = MapEditor::Opened(MapEditorState::default()); + *self = MapEditor::Opened(state::State::default()); } /// Draws the screen for this editor state. @@ -43,21 +45,20 @@ impl MapEditor d.image((dw / 2 - iw / 2, dh / 2 - ih / 2), im); - d.rect(Rect{x: 0, y: 0, w: dw, h: 18}, CR_DARK_RED); - d.text((4, 14), tx_top, CR_RED); + 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}, CR_DARK_RED); - d.text((4, dh - 4), tx_bot, CR_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), CR_RED); + d.text((dw/2, dh/2), &format!("tool: {:?}", st.tool), color::RED); } } } /// Returns `true` if `self` is closed. - #[allow(dead_code)] #[inline] pub fn is_closed(&self) -> bool { @@ -68,7 +69,6 @@ impl MapEditor } /// Returns `true` if `self` is opened. - #[allow(dead_code)] #[inline] pub fn is_opened(&self) -> bool { @@ -79,40 +79,17 @@ impl MapEditor } } -impl Default for Tool +impl Default for MapEditor { - fn default() -> Tool {Tool::Points} -} - -/// Copyable map state. -#[derive(Clone, Default)] -pub struct MapEditorStateBlock -{ - info: map::Minf, -} - -/// The state of an opened map editor. -#[derive(Default)] -pub struct MapEditorState -{ - edit_stack: Vec, - tool: Tool, + #[inline] + fn default() -> Self {Self::new_closed()} } /// An entire map editor, which may be opened or closed. pub enum MapEditor { Closed, - Opened(MapEditorState), -} - -/// A tool in the map editor. -#[derive(Debug)] -pub enum Tool -{ - Points, - Lines, - Polygons, + Opened(state::State), } // EOF diff --git a/source/rozinante/editor/block.rs b/source/rozinante/editor/block.rs new file mode 100644 index 0000000..9f03e7b --- /dev/null +++ b/source/rozinante/editor/block.rs @@ -0,0 +1,19 @@ +use crate::marathon::map; + +impl Default for Block +{ + #[inline] + fn default() -> Self + { + Self{info: map::Minf::default()} + } +} + +/// Copyable map state. +#[derive(Clone)] +pub struct Block +{ + info: map::Minf, +} + +// EOF diff --git a/source/rozinante/editor/state.rs b/source/rozinante/editor/state.rs new file mode 100644 index 0000000..61bfe4f --- /dev/null +++ b/source/rozinante/editor/state.rs @@ -0,0 +1,48 @@ +use super::block; + +impl State +{ + fn cur_block(&self) -> &block::Block + { + self.blocks.last().unwrap() + } + + fn cur_block_mut(&mut self) -> &mut block::Block + { + self.blocks.last_mut().unwrap() + } +} + +impl Default for State +{ + #[inline] + fn default() -> Self + { + Self{blocks: vec![block::Block::default()], + tool: Tool::default()} + } +} + +impl Default for Tool +{ + #[inline] + fn default() -> Self {Tool::Points} +} + +/// The state of an opened map editor. +pub struct State +{ + pub(super) blocks: Vec, + pub(super) tool: Tool, +} + +/// A tool in the map editor. +#[derive(Debug)] +pub(super) enum Tool +{ + Points, + Lines, + Polygons, +} + +// EOF diff --git a/source/tycho/main.rs b/source/tycho/main.rs index 0c00292..7e9f2ef 100644 --- a/source/tycho/main.rs +++ b/source/tycho/main.rs @@ -1,4 +1,3 @@ -mod editor; mod interfaces; use crate::interfaces::*; @@ -8,10 +7,10 @@ use gio_sys::*; use glib_sys::*; use gobject_sys::*; use gtk_sys::*; -use maraiah::{c_str, durandal::ffi}; +use maraiah::{c_str, durandal::ffi, rozinante::editor}; use std::{cell::RefCell, rc::Rc}; -/// Called whne the application activates in order to set everything up. +/// Called when the application activates in order to set everything up. unsafe extern "C" fn app_activate(app: *mut GtkApplication, edit: gpointer) { // this ref will be cloned around a bit, but will ultimately be dropped at