extra comments

gui-branch
an 2019-03-27 07:56:30 -04:00
parent 742f0c1c8e
commit 8693f7605a
2 changed files with 22 additions and 13 deletions

View File

@ -25,20 +25,20 @@ impl MapEditor
}
/// Draws the screen for this editor state.
pub fn draw<D, I>(&self, d: &D, im: &I)
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.";
let dw = d.w();
let dh = d.h();
let iw = im.w();
let ih = im.h();
d.clear(Color16::new(0, 0, 0));
d.image((dw / 2 - iw / 2, dh / 2 - ih / 2), im);
@ -49,8 +49,9 @@ impl MapEditor
d.rect(Rect{x: 0, y: dh - 18, w: dw, h: 18}, CR_DARK_RED);
d.text((4, dh - 4), tx_bot, CR_RED);
}
MapEditor::Opened(_st) => {
MapEditor::Opened(st) => {
d.clear(Color16::new(0, 0, 0));
d.text((dw/2, dh/2), &format!("tool: {:?}", st.tool), CR_RED);
}
}
}
@ -106,6 +107,7 @@ pub enum MapEditor
}
/// A tool in the map editor.
#[derive(Debug)]
pub enum Tool
{
Points,

View File

@ -36,6 +36,7 @@ unsafe extern "C" fn app_activate(app: *mut GtkApplication, edit: gpointer)
/// Sets up the map view window's drawing area.
unsafe fn setup_draw_area(b: *mut GtkBuilder, edit: Rc<MapEditorRef>)
{
/// All of the state necessary for the drawing area.
struct RenderState
{
im_nomap: *mut GdkPixbuf,
@ -84,11 +85,12 @@ unsafe fn setup_draw_area(b: *mut GtkBuilder, edit: Rc<MapEditorRef>)
let wid: *mut GtkDrawingArea = get_obj(b, c_str!("draw-area"));
{
let mut edit = edit.borrow_mut();
edit.call.push(Box::new(move || gtk_widget_queue_draw(wid as _)));
}
// add a callback to draw the area when updated
edit.borrow_mut().call.push(Box::new(move || {
gtk_widget_queue_draw(wid as _);
}));
// get all of the necessary state and related objects
let ax: *mut GtkAdjustment = get_obj(b, c_str!("adj-map-horz"));
let ay: *mut GtkAdjustment = get_obj(b, c_str!("adj-map-vert"));
@ -226,7 +228,7 @@ unsafe fn setup_win_main(b: *mut GtkBuilder,
gtk_window_close(win as _);
}
/// Callback to create a new editor state when the "New" button is pressed.
/// Callback to create a new map when the "New" button is pressed.
unsafe extern "C" fn c_new_act(_: *mut GtkWidget, edit: gpointer)
{
let edit = edit as *const MapEditorRef;
@ -386,7 +388,8 @@ fn main()
let edit = MapEditor{edit: editor::MapEditor::new_closed(),
call: Vec::new(),
done: Vec::new()};
let edit = Rc::new(RefCell::new(edit));
let edit = RefCell::new(edit);
let edit = Rc::new(edit);
let eptr = Rc::into_raw(edit.clone());
// create and run the app
@ -410,11 +413,13 @@ fn main()
impl MapEditor
{
/// Causes all update callbacks to be called.
fn cause_update(&mut self) {for cb in &mut self.call {cb();}}
}
impl Drop for MapEditor
{
/// Calls all finalization callbacks on drop.
fn drop(&mut self) {for cb in &mut self.done {cb();}}
}
@ -430,6 +435,7 @@ impl std::ops::DerefMut for MapEditor
fn deref_mut(&mut self) -> &mut editor::MapEditor {&mut self.edit}
}
/// Specialized map editor which has callbacks for frontend purposes.
struct MapEditor
{
edit: editor::MapEditor,
@ -437,6 +443,7 @@ struct MapEditor
done: Vec<Box<dyn FnMut()>>,
}
/// A runtime reference to the map editor.
type MapEditorRef = RefCell<MapEditor>;
// EOF