From 892efbdb13dc3cb751055e97081ed655db801612 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sun, 3 Mar 2019 00:45:04 -0500 Subject: [PATCH] rozinante --- source/lib.rs | 1 + source/rozinante/color.rs | 8 ++++++ .../{tycho/stoneage.rs => rozinante/draw.rs} | 9 +++---- source/rozinante/mod.rs | 6 +++++ source/tycho/hiddenprotocol.rs | 27 ++++++++++++++++--- source/tycho/main.rs | 5 ++-- source/tycho/noroom.rs | 16 ++++++----- 7 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 source/rozinante/color.rs rename source/{tycho/stoneage.rs => rozinante/draw.rs} (69%) create mode 100644 source/rozinante/mod.rs diff --git a/source/lib.rs b/source/lib.rs index b9aaa9c..69156dd 100644 --- a/source/lib.rs +++ b/source/lib.rs @@ -52,5 +52,6 @@ #[macro_use] pub mod durandal; pub mod marathon; +pub mod rozinante; // EOF diff --git a/source/rozinante/color.rs b/source/rozinante/color.rs new file mode 100644 index 0000000..939f7d8 --- /dev/null +++ b/source/rozinante/color.rs @@ -0,0 +1,8 @@ +//! Color presets. + +use crate::durandal::image::Color16; + +pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0); +pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 0, 0); + +// EOF diff --git a/source/tycho/stoneage.rs b/source/rozinante/draw.rs similarity index 69% rename from source/tycho/stoneage.rs rename to source/rozinante/draw.rs index cd897b7..e6bf0b2 100644 --- a/source/tycho/stoneage.rs +++ b/source/rozinante/draw.rs @@ -1,4 +1,6 @@ -use maraiah::durandal::image::*; +//! GUI drawing capabilities. + +use crate::durandal::image::Color; pub trait CacheImage { @@ -15,7 +17,7 @@ pub trait DrawArea 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 text(&self, pos: Point, text: &str, cr: impl Color); fn image(&self, pos: Point, im: &Self::NativeImage); } @@ -25,7 +27,4 @@ pub type Point = (Coord, Coord); #[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); - // EOF diff --git a/source/rozinante/mod.rs b/source/rozinante/mod.rs new file mode 100644 index 0000000..96e17cb --- /dev/null +++ b/source/rozinante/mod.rs @@ -0,0 +1,6 @@ +//! Library for GUI programs. + +pub mod color; +pub mod draw; + +// EOF diff --git a/source/tycho/hiddenprotocol.rs b/source/tycho/hiddenprotocol.rs index f2c6b0a..fc8929f 100644 --- a/source/tycho/hiddenprotocol.rs +++ b/source/tycho/hiddenprotocol.rs @@ -1,5 +1,6 @@ -use crate::stoneage::*; use maraiah::durandal::image::*; +use maraiah::marathon::*; +use maraiah::rozinante::{color::*, draw::*}; pub fn draw_map_none(d: &D, im: &I) where D: DrawArea, @@ -10,10 +11,30 @@ pub fn draw_map_none(d: &D, im: &I) 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); - d.text((4, 14), CR_RED, "Map Required To Proceed"); + d.text((4, 14), "Map Required To Proceed", 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), CR_RED, "CAS.qterm//CyberAcme Systems Inc."); + d.text((4, d.h() - 4), "CAS.qterm//CyberAcme Systems Inc.", CR_RED); +} + +pub fn new_map() -> MapState +{ + let info = Default::default(); + + let ed = EditorState{}; + let ma = MapState{ed, info}; + + ma +} + +pub struct EditorState +{ +} + +pub struct MapState +{ + ed: EditorState, + info: map::Minf, } // EOF diff --git a/source/tycho/main.rs b/source/tycho/main.rs index d2ddd82..04b4573 100644 --- a/source/tycho/main.rs +++ b/source/tycho/main.rs @@ -1,6 +1,5 @@ mod hiddenprotocol; mod noroom; -mod stoneage; use crate::hiddenprotocol::*; use crate::noroom::*; @@ -21,7 +20,7 @@ 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"); + let im = CairoPixbuf(load_img("/net/greyserv/maraiah/tycho/tycho1")); area.connect_draw(move |area, cr| { let w = f64::from(area.get_allocated_width()); @@ -90,7 +89,7 @@ fn get_obj(b: >k::Builder, name: &str) -> T fn main() -> ResultS<()> { // get jacked, punk. opaque data structures are for nerds. - const RESOURCE_DATA: &'static [u8] = include_bytes!("data/tycho.res"); + const RESOURCE_DATA: &[u8] = include_bytes!("data/tycho.res"); let mut static_resource = gio_sys::GStaticResource{data: RESOURCE_DATA.as_ptr(), diff --git a/source/tycho/noroom.rs b/source/tycho/noroom.rs index 99f1f2d..e2b6072 100644 --- a/source/tycho/noroom.rs +++ b/source/tycho/noroom.rs @@ -1,4 +1,4 @@ -use crate::stoneage::*; +use maraiah::rozinante::draw::*; use maraiah::durandal::image::*; fn flt_color(cr: impl Color) -> (f64, f64, f64) @@ -8,10 +8,10 @@ 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 +impl CacheImage for CairoPixbuf { - fn w(&self) -> Coord {self.get_width() as Coord} - fn h(&self) -> Coord {self.get_height() as Coord} + fn w(&self) -> Coord {self.0.get_width() as Coord} + fn h(&self) -> Coord {self.0.get_height() as Coord} } impl CairoDrawArea @@ -24,7 +24,7 @@ impl CairoDrawArea impl DrawArea for CairoDrawArea { - type NativeImage = gdk_pixbuf::Pixbuf; + type NativeImage = CairoPixbuf; fn w(&self) -> Coord {self.w} fn h(&self) -> Coord {self.h} @@ -53,7 +53,7 @@ impl DrawArea for CairoDrawArea self.ctx.fill(); } - fn text(&self, pos: Point, cr: impl Color, text: &str) + fn text(&self, pos: Point, text: &str, cr: impl Color) { let (r, g, b) = flt_color(cr); @@ -65,11 +65,13 @@ impl DrawArea for CairoDrawArea 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.set_source_pixbuf(&im.0, f64::from(pos.0), f64::from(pos.1)); self.ctx.paint(); } } +pub struct CairoPixbuf(pub gdk_pixbuf::Pixbuf); + pub struct CairoDrawArea { ctx: cairo::Context,