move editor to rozinante

gui-branch
an 2019-03-27 14:07:33 -04:00
parent b427f4c99d
commit d56b3db1fe
7 changed files with 92 additions and 43 deletions

View File

@ -50,6 +50,11 @@ impl CStringVec
} }
} }
impl Default for CStringVec
{
fn default() -> Self {Self::new()}
}
/// An owned null-terminated string vector. /// An owned null-terminated string vector.
#[derive(Debug)] #[derive(Debug)]
pub struct CStringVec pub struct CStringVec

View File

@ -2,5 +2,6 @@
pub mod color; pub mod color;
pub mod draw; pub mod draw;
pub mod editor;
// EOF // EOF

View File

@ -2,7 +2,7 @@
use crate::durandal::image::Color16; use crate::durandal::image::Color16;
pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0); pub const RED: Color16 = Color16::new(0xFFFF, 0, 0);
pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 0, 0); pub const DARK_RED: Color16 = Color16::new(0x4700, 0, 0);
// EOF // EOF

View File

@ -4,9 +4,11 @@
//! state and human interactions with it, but is otherwise not permitted to //! state and human interactions with it, but is otherwise not permitted to
//! directly edit it. //! directly edit it.
use maraiah::{durandal::image::*, pub mod block;
marathon::map, pub mod state;
rozinante::{color::*, draw::*}};
use crate::durandal::image::*;
use super::{color, draw::*};
impl MapEditor impl MapEditor
{ {
@ -21,7 +23,7 @@ impl MapEditor
#[inline] #[inline]
pub fn open_new(&mut self) pub fn open_new(&mut self)
{ {
*self = MapEditor::Opened(MapEditorState::default()); *self = MapEditor::Opened(state::State::default());
} }
/// Draws the screen for this editor state. /// 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.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.rect(Rect{x: 0, y: 0, w: dw, h: 18}, color::DARK_RED);
d.text((4, 14), tx_top, CR_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.rect(Rect{x: 0, y: dh - 18, w: dw, h: 18}, color::DARK_RED);
d.text((4, dh - 4), tx_bot, CR_RED); d.text((4, dh - 4), tx_bot, color::RED);
} }
MapEditor::Opened(st) => { MapEditor::Opened(st) => {
d.clear(Color16::new(0, 0, 0)); 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. /// Returns `true` if `self` is closed.
#[allow(dead_code)]
#[inline] #[inline]
pub fn is_closed(&self) -> bool pub fn is_closed(&self) -> bool
{ {
@ -68,7 +69,6 @@ impl MapEditor
} }
/// Returns `true` if `self` is opened. /// Returns `true` if `self` is opened.
#[allow(dead_code)]
#[inline] #[inline]
pub fn is_opened(&self) -> bool 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} #[inline]
} fn default() -> Self {Self::new_closed()}
/// 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<MapEditorStateBlock>,
tool: Tool,
} }
/// An entire map editor, which may be opened or closed. /// An entire map editor, which may be opened or closed.
pub enum MapEditor pub enum MapEditor
{ {
Closed, Closed,
Opened(MapEditorState), Opened(state::State),
}
/// A tool in the map editor.
#[derive(Debug)]
pub enum Tool
{
Points,
Lines,
Polygons,
} }
// EOF // EOF

View File

@ -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

View File

@ -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<block::Block>,
pub(super) tool: Tool,
}
/// A tool in the map editor.
#[derive(Debug)]
pub(super) enum Tool
{
Points,
Lines,
Polygons,
}
// EOF

View File

@ -1,4 +1,3 @@
mod editor;
mod interfaces; mod interfaces;
use crate::interfaces::*; use crate::interfaces::*;
@ -8,10 +7,10 @@ use gio_sys::*;
use glib_sys::*; use glib_sys::*;
use gobject_sys::*; use gobject_sys::*;
use gtk_sys::*; use gtk_sys::*;
use maraiah::{c_str, durandal::ffi}; use maraiah::{c_str, durandal::ffi, rozinante::editor};
use std::{cell::RefCell, rc::Rc}; 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) 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 // this ref will be cloned around a bit, but will ultimately be dropped at