From a7fb392c5ede5178de0be8f972f4ec3970180013 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sat, 2 Mar 2019 20:49:35 -0500 Subject: [PATCH] more crap for tycho --- source/tycho/hiddenprotocol.rs | 15 +++--- source/tycho/main.rs | 95 ++++++++-------------------------- source/tycho/noroom.rs | 25 +++++++-- source/tycho/stoneage.rs | 70 +++++-------------------- 4 files changed, 64 insertions(+), 141 deletions(-) diff --git a/source/tycho/hiddenprotocol.rs b/source/tycho/hiddenprotocol.rs index b0bd036..f2c6b0a 100644 --- a/source/tycho/hiddenprotocol.rs +++ b/source/tycho/hiddenprotocol.rs @@ -1,19 +1,18 @@ use crate::stoneage::*; +use maraiah::durandal::image::*; -pub fn draw_map_none(d: &impl DrawArea) +pub fn draw_map_none(d: &D, im: &I) + where D: DrawArea, + I: CacheImage { - // TODO: draw middle image + d.clear(Color16::new(0, 0, 0)); + + d.image((d.w() / 2 - im.w() / 2, d.h() / 2 - im.h() / 2), im); - // draw top border (these are separate so the bottom draws over the top) d.rect(Rect{x: 0, y: 0, w: d.w(), h: 18}, CR_DARK_RED); - - // draw top text d.text((4, 14), CR_RED, "Map Required To Proceed"); - // draw bottom border d.rect(Rect{x: 0, y: d.h() - 18, w: d.w(), h: 18}, CR_DARK_RED); - - // draw bottom text d.text((4, d.h() - 4), CR_RED, "CAS.qterm//CyberAcme Systems Inc."); } diff --git a/source/tycho/main.rs b/source/tycho/main.rs index 1982d6e..d2ddd82 100644 --- a/source/tycho/main.rs +++ b/source/tycho/main.rs @@ -4,12 +4,9 @@ mod stoneage; use crate::hiddenprotocol::*; use crate::noroom::*; -use crate::stoneage::*; -//use gdk::prelude::*; use gio::prelude::*; use gtk::prelude::*; use maraiah::durandal::err::*; -use maraiah::durandal::image::*; fn hide_on_delete(win: >k::Window, _: &gdk::Event) -> Inhibit { @@ -24,6 +21,8 @@ fn mk_draw_area(b: >k::Builder) 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()); @@ -36,95 +35,47 @@ fn mk_draw_area(b: >k::Builder) let d = CairoDrawArea::new(cr.clone(), w, h); - d.clear(Color16::new(0, 0, 0)); - draw_map_none(&d); + draw_map_none(&d, &im); Inhibit(true) }); } -fn mk_win_map_tools(b: >k::Builder) +fn run_app(app: >k::Application) { - let win: gtk::Window = get_obj(b, "win-map-tools"); + let b = >k::Builder::new_from_resource("/net/greyserv/maraiah/tycho/ui"); - win.connect_delete_event(hide_on_delete); -} + let app_ = app.clone(); + let btn: gtk::MenuItem = get_obj(b, "btn-quit"); + btn.connect_activate(move |_| app_.quit()); -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 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();}); + let btn: gtk::MenuItem = get_obj(b, "btn-show-map-view"); + let win: gtk::Window = get_obj(b, "win-map-view"); + win.connect_delete_event(hide_on_delete); + btn.connect_activate(move |_| win.show_all()); + + let btn: gtk::MenuItem = get_obj(b, "btn-show-map-tools"); + let win: gtk::Window = get_obj(b, "win-map-tools"); + win.connect_delete_event(hide_on_delete); + btn.connect_activate(move |_| win.show_all()); + + mk_draw_area(b); + + 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(); } -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()); -} - -fn run_app(app: >k::Application) -{ - // one fallible call, which should never fail anyhow - let b = gtk::Builder::new_from_resource("/net/greyserv/maraiah/tycho/ui"); - - 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); -} - fn load_img(path: &'static str) -> gdk_pixbuf::Pixbuf { gdk_pixbuf::Pixbuf::new_from_resource(path).unwrap() diff --git a/source/tycho/noroom.rs b/source/tycho/noroom.rs index 11379f3..99f1f2d 100644 --- a/source/tycho/noroom.rs +++ b/source/tycho/noroom.rs @@ -8,18 +8,26 @@ fn flt_color(cr: impl Color) -> (f64, f64, f64) (flt_color(cr.r()), flt_color(cr.g()), flt_color(cr.b())) } +impl CacheImage for gdk_pixbuf::Pixbuf +{ + fn w(&self) -> Coord {self.get_width() as Coord} + fn h(&self) -> Coord {self.get_height() as Coord} +} + impl CairoDrawArea { pub const fn new(ctx: cairo::Context, w: f64, h: f64) -> Self { - CairoDrawArea{ctx, w: w as u32, h: h as u32} + CairoDrawArea{ctx, w: w as Coord, h: h as Coord} } } impl DrawArea for CairoDrawArea { - fn w(&self) -> u32 {self.w} - fn h(&self) -> u32 {self.h} + type NativeImage = gdk_pixbuf::Pixbuf; + + fn w(&self) -> Coord {self.w} + fn h(&self) -> Coord {self.h} fn clear(&self, cr: impl Color) { @@ -53,13 +61,20 @@ impl DrawArea for CairoDrawArea self.ctx.move_to(f64::from(pos.0), f64::from(pos.1)); self.ctx.show_text(text); } + + fn image(&self, pos: Point, im: &Self::NativeImage) + { + use gdk::prelude::*; + self.ctx.set_source_pixbuf(im, f64::from(pos.0), f64::from(pos.1)); + self.ctx.paint(); + } } pub struct CairoDrawArea { ctx: cairo::Context, - w: u32, - h: u32, + w: Coord, + h: Coord, } // EOF diff --git a/source/tycho/stoneage.rs b/source/tycho/stoneage.rs index 309d33f..cd897b7 100644 --- a/source/tycho/stoneage.rs +++ b/source/tycho/stoneage.rs @@ -1,73 +1,31 @@ use maraiah::durandal::image::*; -use std::collections::HashMap; -#[derive(Copy, Clone, Debug)] -pub struct Rect {pub x: u32, pub y: u32, pub w: u32, pub h: u32} - -pub type Point = (u32, u32); +pub trait CacheImage +{ + fn w(&self) -> Coord; + fn h(&self) -> Coord; +} pub trait DrawArea { - fn w(&self) -> u32; - fn h(&self) -> u32; + type NativeImage: CacheImage; + + fn w(&self) -> Coord; + fn h(&self) -> Coord; fn clear(&self, cr: impl Color); fn rect(&self, rect: Rect, cr: impl Color); fn text(&self, pos: Point, cr: impl Color, text: &str); + fn image(&self, pos: Point, im: &Self::NativeImage); } -pub trait Resource -{ - fn as_dir(&self) -> Option<&ResDir> {None} - fn as_file(&self) -> Option<&ResFile> {None} -} +pub type Coord = i32; +pub type Point = (Coord, Coord); -impl ResDir -{ - pub fn new() -> ResDir - { - ResDir{hash: HashMap::new()} - } - - pub fn insert(&mut self, name: &str, res: Box) - { - self.hash.insert(name.to_string(), res); - } - - pub fn get(&self, name: &str) -> Option<&Box> - { - self.hash.get(name) - } -} - -impl Resource for ResDir -{ - fn as_dir(&self) -> Option<&ResDir> {Some(self)} -} - -impl Resource for ResFile -{ - fn as_file(&self) -> Option<&ResFile> {Some(self)} -} - -pub struct ResDir -{ - hash: HashMap>, -} - -struct ResFile -{ -} +#[derive(Copy, Clone, Debug)] +pub struct Rect {pub x: Coord, pub y: Coord, pub w: Coord, pub h: Coord} pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0); pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 0, 0); -#[test] -fn resources() -{ - let mut top = ResDir::new(); - top.insert(":basic_sub:resource", Box::new(ResFile{})); - top.get(":basic_sub:resource").unwrap(); -} - // EOF