diff --git a/.gitignore b/.gitignore index ed1e5e0..c445795 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /target /out -data/*.res +*.res **/*.rs.bk Cargo.lock perf.data* diff --git a/src/tycho/Cargo.toml b/src/tycho/Cargo.toml index a06f161..3903586 100644 --- a/src/tycho/Cargo.toml +++ b/src/tycho/Cargo.toml @@ -21,7 +21,7 @@ gio-sys = "0.8" glib = "0.7" glib-sys = "0.8" gobject-sys = "0.8" -gtk = "0.6" +gtk = {version = "0.6", features = ["v3_16"]} gtk-sys = "0.8" pango = "0.6" pango-sys = "0.8" diff --git a/src/tycho/buttons.rs b/src/tycho/buttons.rs new file mode 100644 index 0000000..e38e715 --- /dev/null +++ b/src/tycho/buttons.rs @@ -0,0 +1,48 @@ +fn mk_btn_new(b: >k::Builder) +{ + let btn: gtk::MenuItem = get_obj(b, "btn-new"); + let tools: gtk::Window = get_obj(b, "win-map-tools"); + let view: gtk::Window = get_obj(b, "win-map-view"); + + btn.connect_activate(move |_| { + // TODO: actually make a new document + tools.show_all(); + view.show_all(); + }); +} + +fn mk_btn_quit(b: >k::Builder, app: gtk::Application) +{ + let btn: gtk::MenuItem = get_obj(b, "btn-quit"); + + btn.connect_activate(move |_| app.quit()); +} + +fn mk_btn_about(b: >k::Builder) +{ + let btn: gtk::MenuItem = get_obj(b, "btn-about"); + let win: gtk::AboutDialog = get_obj(b, "win-about"); + + btn.connect_activate(move |_| { + win.run(); + win.hide(); + }); +} + +fn mk_btn_show_map_view(b: >k::Builder) +{ + let btn: gtk::MenuItem = get_obj(b, "btn-show-map-view"); + let win: gtk::Window = get_obj(b, "win-map-view"); + + btn.connect_activate(move |_| win.show_all()); +} + +fn mk_btn_show_map_tools(b: >k::Builder) +{ + let btn: gtk::MenuItem = get_obj(b, "btn-show-map-tools"); + let win: gtk::Window = get_obj(b, "win-map-tools"); + + btn.connect_activate(move |_| win.show_all()); +} + +// EOF diff --git a/src/tycho/data/tycho.res b/src/tycho/data/tycho.res deleted file mode 100644 index 4d3ec3a..0000000 Binary files a/src/tycho/data/tycho.res and /dev/null differ diff --git a/src/tycho/data/tycho.xml b/src/tycho/data/tycho.xml index 16fd650..5123030 100644 --- a/src/tycho/data/tycho.xml +++ b/src/tycho/data/tycho.xml @@ -27,33 +27,75 @@ Author: Alison Sanderson --> - + - + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + False + Map View + 600 + 400 + + + + + + True + True + always + always + top-right + False + + + True + False + adj-map-horz + adj-map-vert + + + True + False + + + + + + + + True False /net/greyserv/maraiah/tycho/lines - + True False /net/greyserv/maraiah/tycho/points - + True False /net/greyserv/maraiah/tycho/polys - + False Tool Palette 250 True - True @@ -68,14 +110,14 @@ Author: Alison Sanderson False Geometry - + True False Points True - im_points + img-points - + Points Tool The tool that modifies points in the map. push-button @@ -87,14 +129,14 @@ Author: Alison Sanderson - + True False Lines True - im_lines + img-lines - + Lines Tool The tool which modifies line segments on the map. push-button @@ -107,14 +149,14 @@ Author: Alison Sanderson - + True False Polygons True - im_polys + img-polys - + Polygon Tool The tool which modifies polygon shapes on the map. push-button @@ -141,17 +183,16 @@ Author: Alison Sanderson - + Tycho Tool Palette Tycho's tool palette window. window - + False True - True dialog Tycho Map Editor Copyright © 2018-2019 Alison Sanderson @@ -184,18 +225,19 @@ Author: Alison Sanderson - + About Screen The about screen for Tycho. dialog - + False Tycho + False + 120 250 - True @@ -215,39 +257,30 @@ Author: Alison Sanderson True False - - gtk-new + True False + Create a new project. + _New Project True - True - - gtk-open + True False + Opens any type of project file. + _Open True - True - - gtk-save + True False + Saves the currently open project. + _Save True - True - - - - - gtk-save-as - True - False - True - True @@ -257,62 +290,12 @@ Author: Alison Sanderson - - gtk-quit + True False + Quit the application. + _Quit True - True - - - - - - - - - True - False - _Edit - True - - - True - False - - - gtk-cut - True - False - True - True - - - - - gtk-copy - True - False - True - True - - - - - gtk-paste - True - False - True - True - - - - - gtk-delete - True - False - True - True @@ -325,6 +308,30 @@ Author: Alison Sanderson False _View True + + + True + False + + + True + False + Opens the map view window. + Show _Map View + True + + + + + True + False + Opens the map toolbox window. + Show Map _Tools + True + + + + @@ -345,12 +352,12 @@ Author: Alison Sanderson True False - - gtk-about + True False + Opens a window with information about this program. + _About True - True diff --git a/src/tycho/main.rs b/src/tycho/main.rs index 204a322..54680c1 100644 --- a/src/tycho/main.rs +++ b/src/tycho/main.rs @@ -1,53 +1,38 @@ -use gtk::prelude::*; +use gdk::prelude::*; use gio::prelude::*; +use gtk::prelude::*; use maraiah::durandal::err::*; -fn run_app(app: >k::Application) -> ResultS<()> +include!("windows.rs"); +include!("buttons.rs"); +include!("map_draw.rs"); + +fn run_app(app: >k::Application) { - fn load_img(path: &'static str) -> ResultS - { - Ok(gdk_pixbuf::Pixbuf::new_from_resource(path)?) - } - - fn get_obj(b: >k::Builder, name: &str) -> ResultS - where T: glib::object::IsA - { - match b.get_object(name) { - Some(w) => Ok(w), - None => Err(err_msg("no object")), - } - } - + // one fallible call, which should never fail anyhow let b = gtk::Builder::new_from_resource("/net/greyserv/maraiah/tycho/ui"); - let win_menus: gtk::Window = get_obj(&b, "win_menus")?; - let win_tools: gtk::Window = get_obj(&b, "win_tools")?; - let win_about: gtk::AboutDialog = get_obj(&b, "win_about")?; - let btn_about: gtk::MenuItem = get_obj(&b, "btn_about")?; - //t draw_area: gtk::DrawingArea = get_obj(&b, "draw_area")?; - //t btn_point: gtk::ToolButton = get_obj(&b, "btn_point")?; - //t btn_lines: gtk::ToolButton = get_obj(&b, "btn_lines")?; - //t btn_polys: gtk::ToolButton = get_obj(&b, "btn_polys")?; + mk_btn_new(&b); + mk_btn_quit(&b, app.clone()); + mk_btn_about(&b); + mk_btn_show_map_view(&b); + mk_btn_show_map_tools(&b); + mk_draw_area(&b); + mk_win_map_tools(&b); + mk_win_map_view(&b); + mk_win_about(&b); + mk_win_main(&b, app); +} - let authors: Vec<_> = env!("CARGO_PKG_AUTHORS").split(';').collect(); +fn load_img(path: &'static str) -> gdk_pixbuf::Pixbuf +{ + gdk_pixbuf::Pixbuf::new_from_resource(path).unwrap() +} - win_about.set_authors(&authors); - win_about.set_version(env!("CARGO_PKG_VERSION")); - win_about.set_website(env!("CARGO_PKG_HOMEPAGE")); - win_about.set_logo(&load_img("/net/greyserv/maraiah/tycho/tycho2")?); - - btn_about.connect_activate(move |_| { - win_about.run(); - win_about.hide(); - }); - - win_tools.set_deletable(false); - win_tools.show_all(); - - win_menus.set_application(app); - win_menus.show_all(); - - Ok(()) +fn get_obj(b: >k::Builder, name: &str) -> T + where T: glib::object::IsA +{ + b.get_object(name).unwrap() } fn main() -> ResultS<()> @@ -69,21 +54,7 @@ fn main() -> ResultS<()> let app = gtk::Application::new("net.greyserv.maraiah.tycho", gio::ApplicationFlags::empty())?; - app.connect_activate(|app| { - match run_app(app) { - Ok(()) => (), - Err(e) => { - // print out an error if init failed somehow, otherwise the main - // loop will proceed as normal (this is just to prevent panics in - // weird circumstances such as breaking the builder while devving) - gtk::MessageDialog::new(None::<>k::Window>, - gtk::DialogFlags::empty(), - gtk::MessageType::Error, - gtk::ButtonsType::Ok, - &format!("{:?}", e)).run(); - } - } - }); + app.connect_activate(run_app); let ret = if app.run(&[]) == 0 { Ok(()) diff --git a/src/tycho/map_draw.rs b/src/tycho/map_draw.rs new file mode 100644 index 0000000..626c3c5 --- /dev/null +++ b/src/tycho/map_draw.rs @@ -0,0 +1,71 @@ +fn draw_clear(cr: &cairo::Context, w: f64, h: f64) +{ + use cairo::{FontSlant, FontWeight}; + + // set up for text + cr.select_font_face("Sans", FontSlant::Normal, FontWeight::Normal); + cr.set_font_size(14.0); + + // clear view + cr.set_source_rgb(0.0, 0.0, 0.0); + cr.rectangle(0.0, 0.0, w, h); + cr.fill(); +} + +fn draw_map_none(cr: &cairo::Context, im: &gdk_pixbuf::Pixbuf, w: f64, h: f64) +{ + let im_w = f64::from(im.get_width()); + let im_h = f64::from(im.get_height()); + + // draw middle image + cr.set_source_pixbuf(im, w / 2.0 - im_w / 2.0, h / 2.0 - im_h / 2.0); + cr.paint(); + + // draw top border (these are separate so the bottom draws over the top) + cr.set_source_rgb(0.28, 0.0, 0.0); + cr.rectangle(0.0, 0.0, w, 18.0); + cr.fill(); + + // draw top text + cr.set_source_rgb(1.0, 0.0, 0.0); + cr.move_to(4.0, 14.0); + cr.show_text("Map Required To Proceed"); + + // draw bottom border + cr.set_source_rgb(0.28, 0.0, 0.0); + cr.rectangle(0.0, h - 18.0, w, h); + cr.fill(); + + // draw bottom text + cr.set_source_rgb(1.0, 0.0, 0.0); + cr.move_to(4.0, h - 4.0); + cr.show_text("CAS.qterm//CyberAcme Systems Inc."); +} + +fn mk_draw_area(b: >k::Builder) +{ + let area: gtk::DrawingArea = get_obj(b, "draw-area"); + + let ax: gtk::Adjustment = get_obj(b, "adj-map-horz"); + let ay: gtk::Adjustment = get_obj(b, "adj-map-vert"); + + let im = load_img("/net/greyserv/maraiah/tycho/tycho1"); + + area.connect_draw(move |area, cr| { + let w = f64::from(area.get_allocated_width()); + let h = f64::from(area.get_allocated_height()); + + ax.set_lower(0.0); + ax.set_upper(w); + + ay.set_lower(0.0); + ay.set_upper(h); + + draw_clear(&cr, w, h); + draw_map_none(&cr, &im, w, h); + + Inhibit(true) + }); +} + +// EOF diff --git a/src/tycho/windows.rs b/src/tycho/windows.rs new file mode 100644 index 0000000..a995238 --- /dev/null +++ b/src/tycho/windows.rs @@ -0,0 +1,39 @@ +fn hide_on_delete(win: >k::Window, _: &gdk::Event) -> Inhibit +{ + win.hide(); + Inhibit(true) +} + +fn mk_win_map_tools(b: >k::Builder) +{ + let win: gtk::Window = get_obj(b, "win-map-tools"); + + win.connect_delete_event(hide_on_delete); +} + +fn mk_win_map_view(b: >k::Builder) +{ + let win: gtk::Window = get_obj(b, "win-map-view"); + + win.connect_delete_event(hide_on_delete); +} + +fn mk_win_about(b: >k::Builder) +{ + let win: gtk::AboutDialog = get_obj(b, "win-about"); + + win.set_authors(&env!("CARGO_PKG_AUTHORS").split(';').collect::>()); + win.set_version(env!("CARGO_PKG_VERSION")); + win.set_website(env!("CARGO_PKG_HOMEPAGE")); + win.set_logo(&load_img("/net/greyserv/maraiah/tycho/tycho2")); +} + +fn mk_win_main(b: >k::Builder, app: >k::Application) +{ + let win: gtk::Window = get_obj(b, "win-main"); + + win.set_application(app); + win.show_all(); +} + +// EOF