create "closed" and "opened" states for the editor
parent
da542c84e8
commit
3f3900d91c
|
@ -8,34 +8,65 @@ use maraiah::{durandal::image::*,
|
||||||
marathon::map,
|
marathon::map,
|
||||||
rozinante::{color::*, draw::*}};
|
rozinante::{color::*, draw::*}};
|
||||||
|
|
||||||
impl MapEditorState
|
impl MapEditor
|
||||||
{
|
{
|
||||||
/// Creates a new empty map.
|
/// Creates a closed map editor.
|
||||||
pub fn new() -> MapEditorState
|
#[inline]
|
||||||
|
pub const fn new_closed() -> Self
|
||||||
{
|
{
|
||||||
MapEditorState::default()
|
MapEditor::Closed
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws the "no map" screen.
|
/// Creates a new empty map.
|
||||||
pub fn draw_none<D, I>(d: &D, im: &I)
|
#[inline]
|
||||||
|
pub fn new_opened() -> Self
|
||||||
|
{
|
||||||
|
MapEditor::Opened(MapEditorState::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Draws the screen for this editor state.
|
||||||
|
pub fn draw<D, I>(&self, d: &D, im: &I)
|
||||||
where D: DrawArea<NativeImage = I>,
|
where D: DrawArea<NativeImage = I>,
|
||||||
I: CacheImage
|
I: CacheImage
|
||||||
{
|
{
|
||||||
d.clear(Color16::new(0, 0, 0));
|
match self {
|
||||||
|
MapEditor::Closed => {
|
||||||
|
d.clear(Color16::new(0, 0, 0));
|
||||||
|
|
||||||
d.image((d.w() / 2 - im.w() / 2, d.h() / 2 - im.h() / 2), im);
|
d.image((d.w() / 2 - im.w() / 2, d.h() / 2 - im.h() / 2), im);
|
||||||
|
|
||||||
d.rect(Rect{x: 0, y: 0, w: d.w(), h: 18}, CR_DARK_RED);
|
let text = "Map Required To Proceed";
|
||||||
d.text((4, 14), "Map Required To Proceed", CR_RED);
|
d.rect(Rect{x: 0, y: 0, w: d.w(), h: 18}, CR_DARK_RED);
|
||||||
|
d.text((4, 14), text, CR_RED);
|
||||||
|
|
||||||
d.rect(Rect{x: 0, y: d.h() - 18, w: d.w(), h: 18}, CR_DARK_RED);
|
let text = "CAS.qterm//CyberAcme Systems Inc.";
|
||||||
d.text((4, d.h() - 4), "CAS.qterm//CyberAcme Systems Inc.", CR_RED);
|
d.rect(Rect{x: 0, y: d.h() - 18, w: d.w(), h: 18}, CR_DARK_RED);
|
||||||
|
d.text((4, d.h() - 4), text, CR_RED);
|
||||||
|
}
|
||||||
|
MapEditor::Opened(_st) => {
|
||||||
|
d.clear(Color16::new(0, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws the currently open map.
|
/// Returns `true` if `self` is closed.
|
||||||
pub fn draw_some(&self, d: &impl DrawArea)
|
#[inline]
|
||||||
|
pub fn is_closed(&self) -> bool
|
||||||
{
|
{
|
||||||
d.clear(Color16::new(0, 0, 0));
|
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,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +82,7 @@ pub struct MapEditorStateBlock
|
||||||
info: map::Minf,
|
info: map::Minf,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The state of a map editor.
|
/// The state of an opened map editor.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MapEditorState
|
pub struct MapEditorState
|
||||||
{
|
{
|
||||||
|
@ -59,6 +90,13 @@ pub struct MapEditorState
|
||||||
tool: Tool,
|
tool: Tool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An entire map editor, which may be opened or closed.
|
||||||
|
pub enum MapEditor
|
||||||
|
{
|
||||||
|
Closed,
|
||||||
|
Opened(MapEditorState),
|
||||||
|
}
|
||||||
|
|
||||||
/// A tool in the map editor.
|
/// A tool in the map editor.
|
||||||
pub enum Tool
|
pub enum Tool
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod editor;
|
mod editor;
|
||||||
mod interfaces;
|
mod interfaces;
|
||||||
|
|
||||||
use crate::{editor::MapEditorState,
|
use crate::{editor::MapEditor,
|
||||||
interfaces::*};
|
interfaces::*};
|
||||||
use gdk_pixbuf_sys::*;
|
use gdk_pixbuf_sys::*;
|
||||||
use gdk_sys::*;
|
use gdk_sys::*;
|
||||||
|
@ -17,7 +17,7 @@ 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
|
||||||
// the end of this function.
|
// the end of this function.
|
||||||
let edit = Rc::from_raw(edit as *mut Option<MapEditorState>);
|
let edit = Rc::from_raw(edit as *mut MapEditor);
|
||||||
|
|
||||||
setup_css();
|
setup_css();
|
||||||
|
|
||||||
|
@ -35,14 +35,14 @@ unsafe extern "C" fn app_activate(app: *mut GtkApplication, edit: gpointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets up the map view window's drawing area.
|
/// Sets up the map view window's drawing area.
|
||||||
unsafe fn setup_draw_area(b: *mut GtkBuilder, edit: Rc<Option<MapEditorState>>)
|
unsafe fn setup_draw_area(b: *mut GtkBuilder, edit: Rc<MapEditor>)
|
||||||
{
|
{
|
||||||
struct RenderState
|
struct RenderState
|
||||||
{
|
{
|
||||||
im_nomap: *mut GdkPixbuf,
|
im_nomap: *mut GdkPixbuf,
|
||||||
ax: *mut GtkAdjustment,
|
ax: *mut GtkAdjustment,
|
||||||
ay: *mut GtkAdjustment,
|
ay: *mut GtkAdjustment,
|
||||||
edit: Rc<Option<MapEditorState>>,
|
edit: Rc<MapEditor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Callback to finalize the drawing area.
|
/// Callback to finalize the drawing area.
|
||||||
|
@ -78,10 +78,7 @@ unsafe fn setup_draw_area(b: *mut GtkBuilder, edit: Rc<Option<MapEditorState>>)
|
||||||
let im = CrImage(rend.im_nomap);
|
let im = CrImage(rend.im_nomap);
|
||||||
let dr = CrDrawArea::new(ctx, w, h);
|
let dr = CrDrawArea::new(ctx, w, h);
|
||||||
|
|
||||||
match &*rend.edit {
|
rend.edit.draw(&dr, &im);
|
||||||
Some(edit) => edit.draw_some(&dr),
|
|
||||||
None => MapEditorState::draw_none(&dr, &im),
|
|
||||||
}
|
|
||||||
|
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
@ -217,7 +214,7 @@ unsafe fn setup_explicit_drop(b: *mut GtkBuilder, win: *mut GtkWindow)
|
||||||
/// Sets up the main menu window.
|
/// Sets up the main menu window.
|
||||||
unsafe fn setup_win_main(b: *mut GtkBuilder,
|
unsafe fn setup_win_main(b: *mut GtkBuilder,
|
||||||
app: *mut GtkApplication,
|
app: *mut GtkApplication,
|
||||||
edit: Rc<Option<MapEditorState>>)
|
edit: Rc<MapEditor>)
|
||||||
{
|
{
|
||||||
/// Callback to close the window when the "Quit" button is pressed.
|
/// Callback to close the window when the "Quit" button is pressed.
|
||||||
unsafe extern "C" fn c_quit_act(_: *mut GtkWidget, win: gpointer)
|
unsafe extern "C" fn c_quit_act(_: *mut GtkWidget, win: gpointer)
|
||||||
|
@ -228,10 +225,10 @@ unsafe fn setup_win_main(b: *mut GtkBuilder,
|
||||||
/// Callback to create a new editor state when the "New" button is pressed.
|
/// Callback to create a new editor state when the "New" button is pressed.
|
||||||
unsafe extern "C" fn c_new_act(_: *mut GtkWidget, edit: gpointer)
|
unsafe extern "C" fn c_new_act(_: *mut GtkWidget, edit: gpointer)
|
||||||
{
|
{
|
||||||
let edit = edit as *mut Option<MapEditorState>;
|
let edit = edit as *mut MapEditor;
|
||||||
let edit = &mut *edit;
|
let edit = &mut *edit;
|
||||||
|
|
||||||
if edit.is_some() {
|
if edit.is_opened() {
|
||||||
let titl = c_str!("Confirm");
|
let titl = c_str!("Confirm");
|
||||||
let text = c_str!("Are you sure you want to create a new project? \
|
let text = c_str!("Are you sure you want to create a new project? \
|
||||||
Data may be lost.");
|
Data may be lost.");
|
||||||
|
@ -241,7 +238,7 @@ unsafe fn setup_win_main(b: *mut GtkBuilder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*edit = Some(MapEditorState::new());
|
*edit = MapEditor::new_opened();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Callback to finalize the editor state reference.
|
/// Callback to finalize the editor state reference.
|
||||||
|
@ -379,7 +376,7 @@ fn main()
|
||||||
g_static_resource_init(&mut resource);
|
g_static_resource_init(&mut resource);
|
||||||
|
|
||||||
// create a container for the editor state
|
// create a container for the editor state
|
||||||
let edit = Rc::new(None::<MapEditorState>);
|
let edit = Rc::new(MapEditor::new_closed());
|
||||||
let eptr = Rc::into_raw(edit.clone());
|
let eptr = Rc::into_raw(edit.clone());
|
||||||
|
|
||||||
// create and run the app
|
// create and run the app
|
||||||
|
|
Loading…
Reference in New Issue