more static strings
parent
f4b0e37542
commit
ad1c4e216b
|
@ -10,11 +10,27 @@ use gtk_sys::*;
|
|||
use maraiah::{c_str, durandal::ffi};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
const ACTIVATE: ffi::NT = c_str!("activate");
|
||||
const APP_ID: ffi::NT = c_str!("net.greyserv.maraiah.tycho");
|
||||
const DELETE_EVENT: ffi::NT = c_str!("delete-event");
|
||||
const DESTROY: ffi::NT = c_str!("destroy");
|
||||
const DRAW: ffi::NT = c_str!("draw");
|
||||
const B_ADJ_M_HORZ: ffi::NT = c_str!("adj-map-horz");
|
||||
const B_ADJ_M_VERT: ffi::NT = c_str!("adj-map-vert");
|
||||
const B_BTN_ABOUT: ffi::NT = c_str!("btn-about");
|
||||
const B_BTN_M_PROP: ffi::NT = c_str!("btn-show-map-prop");
|
||||
const B_BTN_M_TOOL: ffi::NT = c_str!("btn-show-map-tools");
|
||||
const B_BTN_M_VIEW: ffi::NT = c_str!("btn-show-map-view");
|
||||
const B_BTN_NEW: ffi::NT = c_str!("btn-new");
|
||||
const B_BTN_OPEN: ffi::NT = c_str!("btn-open");
|
||||
const B_BTN_QUIT: ffi::NT = c_str!("btn-quit");
|
||||
const B_DLG_ABOUT: ffi::NT = c_str!("dlg-about");
|
||||
const B_DRAW_AREA: ffi::NT = c_str!("draw-area");
|
||||
const B_WIN_MAIN: ffi::NT = c_str!("win-main");
|
||||
const B_WIN_M_PROP: ffi::NT = c_str!("win-map-prop");
|
||||
const B_WIN_M_TOOL: ffi::NT = c_str!("win-map-tools");
|
||||
const B_WIN_M_VIEW: ffi::NT = c_str!("win-map-view");
|
||||
const E_ACTIVATE: ffi::NT = c_str!("activate");
|
||||
const E_DELETE: ffi::NT = c_str!("delete-event");
|
||||
const E_DESTROY: ffi::NT = c_str!("destroy");
|
||||
const E_DRAW: ffi::NT = c_str!("draw");
|
||||
const E_SHUTDOWN: ffi::NT = c_str!("shutdown");
|
||||
const IM_ABOUT: ffi::NT = c_str!("/net/greyserv/maraiah/tycho/tycho2.png");
|
||||
const IM_NOMAP: ffi::NT = c_str!("/net/greyserv/maraiah/tycho/tycho1.png");
|
||||
const PATH_BUILDER: ffi::NT = c_str!("/net/greyserv/maraiah/tycho/ui");
|
||||
|
@ -33,7 +49,7 @@ unsafe extern "C" fn app_activate(app: *mut GtkApplication, _: gpointer)
|
|||
let b = Refc::new(gtk_builder_new_from_resource(PATH_BUILDER));
|
||||
|
||||
let edit = MapEditor{edit: Default::default(),
|
||||
draw: Refc::own(get_obj(&b, c_str!("draw-area")))};
|
||||
draw: Refc::own(get_obj(&b, B_DRAW_AREA))};
|
||||
let edit = RefCell::new(edit);
|
||||
let edit = Rc::new(edit);
|
||||
|
||||
|
@ -45,7 +61,7 @@ unsafe extern "C" fn app_activate(app: *mut GtkApplication, _: gpointer)
|
|||
setup_about_dlg(&b);
|
||||
setup_win_main(&b, app, edit.clone());
|
||||
|
||||
connect(app, c_str!("shutdown"), c_done as _, Rc::into_raw(edit));
|
||||
connect(app, E_SHUTDOWN, c_done as _, Rc::into_raw(edit));
|
||||
}
|
||||
|
||||
/// Sets up the map view window's drawing area.
|
||||
|
@ -91,26 +107,26 @@ unsafe fn setup_draw_area(b: &Refc<GtkBuilder>, edit: Rc<MapEditorRef>)
|
|||
1
|
||||
}
|
||||
|
||||
let wid = get_obj::<GtkDrawingArea>(b, c_str!("draw-area"));
|
||||
let wid = get_obj::<GtkDrawingArea>(b, B_DRAW_AREA);
|
||||
|
||||
// get all of the necessary state and related objects
|
||||
let ax = Refc::own(get_obj(b, c_str!("adj-map-horz")));
|
||||
let ay = Refc::own(get_obj(b, c_str!("adj-map-vert")));
|
||||
let ax = Refc::own(get_obj(b, B_ADJ_M_HORZ));
|
||||
let ay = Refc::own(get_obj(b, B_ADJ_M_VERT));
|
||||
|
||||
let im_nomap = Refc::new(load_img(IM_NOMAP));
|
||||
|
||||
let rend = RenderState{im_nomap, ax, ay, edit};
|
||||
let rend = Box::into_raw(Box::new(rend));
|
||||
|
||||
connect(wid, DESTROY, c_done as _, rend);
|
||||
connect(wid, DRAW, c_draw as _, rend);
|
||||
connect(wid, E_DESTROY, c_done as _, rend);
|
||||
connect(wid, E_DRAW, c_draw as _, rend);
|
||||
}
|
||||
|
||||
/// Sets up the map view window.
|
||||
unsafe fn setup_win_map_view(b: &Refc<GtkBuilder>)
|
||||
{
|
||||
let win = get_obj::<GtkWindow >(b, c_str!("win-map-view"));
|
||||
let btn = get_obj::<GtkMenuItem>(b, c_str!("btn-show-map-view"));
|
||||
let win = get_obj::<GtkWindow >(b, B_WIN_M_VIEW);
|
||||
let btn = get_obj::<GtkMenuItem>(b, B_BTN_M_VIEW);
|
||||
|
||||
connect_hide(win);
|
||||
connect_show(btn, win);
|
||||
|
@ -119,8 +135,8 @@ unsafe fn setup_win_map_view(b: &Refc<GtkBuilder>)
|
|||
/// Sets up the map tools window.
|
||||
unsafe fn setup_win_map_tools(b: &Refc<GtkBuilder>)
|
||||
{
|
||||
let win = get_obj::<GtkWindow >(b, c_str!("win-map-tools"));
|
||||
let btn = get_obj::<GtkMenuItem>(b, c_str!("btn-show-map-tools"));
|
||||
let win = get_obj::<GtkWindow >(b, B_WIN_M_TOOL);
|
||||
let btn = get_obj::<GtkMenuItem>(b, B_BTN_M_TOOL);
|
||||
|
||||
connect_hide(win);
|
||||
connect_show(btn, win);
|
||||
|
@ -129,8 +145,8 @@ unsafe fn setup_win_map_tools(b: &Refc<GtkBuilder>)
|
|||
/// Sets up the map properties window.
|
||||
unsafe fn setup_win_map_prop(b: &Refc<GtkBuilder>)
|
||||
{
|
||||
let win = get_obj::<GtkWindow >(b, c_str!("win-map-prop"));
|
||||
let btn = get_obj::<GtkMenuItem>(b, c_str!("btn-show-map-prop"));
|
||||
let win = get_obj::<GtkWindow >(b, B_WIN_M_PROP);
|
||||
let btn = get_obj::<GtkMenuItem>(b, B_BTN_M_PROP);
|
||||
|
||||
connect_hide(win);
|
||||
connect_show(btn, win);
|
||||
|
@ -147,8 +163,8 @@ unsafe fn setup_about_dlg(b: &Refc<GtkBuilder>)
|
|||
gtk_widget_hide(dlg as _);
|
||||
}
|
||||
|
||||
let dlg = get_obj::<GtkAboutDialog>(b, c_str!("dlg-about"));
|
||||
let btn = get_obj::<GtkMenuItem >(b, c_str!("btn-about"));
|
||||
let dlg = get_obj::<GtkAboutDialog>(b, B_DLG_ABOUT);
|
||||
let btn = get_obj::<GtkMenuItem >(b, B_BTN_ABOUT);
|
||||
|
||||
let it = env!("CARGO_PKG_AUTHORS").split(';');
|
||||
let mut v = ffi::CStringVec::new_from_iter(it).unwrap();
|
||||
|
@ -160,7 +176,7 @@ unsafe fn setup_about_dlg(b: &Refc<GtkBuilder>)
|
|||
gtk_about_dialog_set_logo(dlg, *img);
|
||||
|
||||
connect_hide(dlg);
|
||||
connect(btn, ACTIVATE, c_show_act as _, dlg);
|
||||
connect(btn, E_ACTIVATE, c_show_act as _, dlg);
|
||||
}
|
||||
|
||||
/// Sets up explicit window finalization for the main window.
|
||||
|
@ -212,7 +228,7 @@ unsafe fn setup_explicit_drop(b: &Refc<GtkBuilder>, win: *mut GtkWindow)
|
|||
|
||||
let exp_del = Box::into_raw(Box::new(exp_del));
|
||||
|
||||
connect(win, DESTROY, c_done as _, exp_del);
|
||||
connect(win, E_DESTROY, c_done as _, exp_del);
|
||||
}
|
||||
|
||||
/// Sets up the main menu window.
|
||||
|
@ -272,7 +288,7 @@ unsafe fn setup_win_main(b: &Refc<GtkBuilder>,
|
|||
}
|
||||
|
||||
// set up main window
|
||||
let win = get_obj(b, c_str!("win-main"));
|
||||
let win = get_obj(b, B_WIN_MAIN);
|
||||
|
||||
setup_explicit_drop(b, win);
|
||||
|
||||
|
@ -280,14 +296,14 @@ unsafe fn setup_win_main(b: &Refc<GtkBuilder>,
|
|||
gtk_widget_show_all(win as _);
|
||||
|
||||
// set up buttons
|
||||
let btn = get_obj::<GtkMenuItem>(b, c_str!("btn-quit"));
|
||||
connect(btn, ACTIVATE, c_quit_act as _, win);
|
||||
let btn = get_obj::<GtkMenuItem>(b, B_BTN_QUIT);
|
||||
connect(btn, E_ACTIVATE, c_quit_act as _, win);
|
||||
|
||||
let btn = get_obj::<GtkMenuItem>(b, c_str!("btn-new"));
|
||||
connect(btn, ACTIVATE, c_new_act as _, connect_ref(btn, edit.clone()));
|
||||
let btn = get_obj::<GtkMenuItem>(b, B_BTN_NEW);
|
||||
connect(btn, E_ACTIVATE, c_new_act as _, connect_ref(btn, edit.clone()));
|
||||
|
||||
let btn = get_obj::<GtkMenuItem>(b, c_str!("btn-open"));
|
||||
connect(btn, ACTIVATE, c_open_act as _, connect_ref(btn, edit.clone()));
|
||||
let btn = get_obj::<GtkMenuItem>(b, B_BTN_OPEN);
|
||||
connect(btn, E_ACTIVATE, c_open_act as _, connect_ref(btn, edit.clone()));
|
||||
}
|
||||
|
||||
/// Sets up the CSS styling providers.
|
||||
|
@ -371,7 +387,7 @@ unsafe fn connect_hide<T>(wid: *mut T)
|
|||
gtk_widget_hide(wid);
|
||||
}
|
||||
|
||||
connect(wid, DELETE_EVENT, c_hide_del as _, ffi::null_void());
|
||||
connect(wid, E_DELETE, c_hide_del as _, ffi::null_void());
|
||||
}
|
||||
|
||||
/// Connects a handler that shows a widget when activated.
|
||||
|
@ -383,7 +399,7 @@ unsafe fn connect_show<T, U>(btn: *mut T, wid: *mut U)
|
|||
gtk_widget_show_all(wid as _);
|
||||
}
|
||||
|
||||
connect(btn, ACTIVATE, c_show_act as _, wid);
|
||||
connect(btn, E_ACTIVATE, c_show_act as _, wid);
|
||||
}
|
||||
|
||||
/// Connects the map editor reference to a widget.
|
||||
|
@ -398,7 +414,7 @@ unsafe fn connect_ref<T>(obj: *mut T, rc: Rc<MapEditorRef>)
|
|||
|
||||
let ptr = Rc::into_raw(rc);
|
||||
|
||||
connect(obj, DESTROY, c_done as _, ptr);
|
||||
connect(obj, E_DESTROY, c_done as _, ptr);
|
||||
|
||||
ptr
|
||||
}
|
||||
|
@ -444,7 +460,7 @@ fn main()
|
|||
// create and run the app
|
||||
let app = Refc::new(gtk_application_new(APP_ID, 0));
|
||||
|
||||
connect(*app, ACTIVATE, app_activate as _, ffi::null_void());
|
||||
connect(*app, E_ACTIVATE, app_activate as _, ffi::null_void());
|
||||
|
||||
g_application_run(*app as _, 0, ffi::null_mut());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue