more crap for tycho
parent
b9e1a3d3f6
commit
a7fb392c5e
|
@ -1,19 +1,18 @@
|
||||||
use crate::stoneage::*;
|
use crate::stoneage::*;
|
||||||
|
use maraiah::durandal::image::*;
|
||||||
|
|
||||||
pub fn draw_map_none(d: &impl DrawArea)
|
pub fn draw_map_none<D, I>(d: &D, im: &I)
|
||||||
|
where D: DrawArea<NativeImage = I>,
|
||||||
|
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);
|
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");
|
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);
|
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.");
|
d.text((4, d.h() - 4), CR_RED, "CAS.qterm//CyberAcme Systems Inc.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,9 @@ mod stoneage;
|
||||||
|
|
||||||
use crate::hiddenprotocol::*;
|
use crate::hiddenprotocol::*;
|
||||||
use crate::noroom::*;
|
use crate::noroom::*;
|
||||||
use crate::stoneage::*;
|
|
||||||
//use gdk::prelude::*;
|
|
||||||
use gio::prelude::*;
|
use gio::prelude::*;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use maraiah::durandal::err::*;
|
use maraiah::durandal::err::*;
|
||||||
use maraiah::durandal::image::*;
|
|
||||||
|
|
||||||
fn hide_on_delete(win: >k::Window, _: &gdk::Event) -> Inhibit
|
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 ax: gtk::Adjustment = get_obj(b, "adj-map-horz");
|
||||||
let ay: gtk::Adjustment = get_obj(b, "adj-map-vert");
|
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| {
|
area.connect_draw(move |area, cr| {
|
||||||
let w = f64::from(area.get_allocated_width());
|
let w = f64::from(area.get_allocated_width());
|
||||||
let h = f64::from(area.get_allocated_height());
|
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);
|
let d = CairoDrawArea::new(cr.clone(), w, h);
|
||||||
|
|
||||||
d.clear(Color16::new(0, 0, 0));
|
draw_map_none(&d, &im);
|
||||||
draw_map_none(&d);
|
|
||||||
|
|
||||||
Inhibit(true)
|
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 btn: gtk::MenuItem = get_obj(b, "btn-about");
|
||||||
{
|
|
||||||
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");
|
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::<Vec<_>>());
|
win.set_authors(&env!("CARGO_PKG_AUTHORS").split(';').collect::<Vec<_>>());
|
||||||
win.set_version(env!("CARGO_PKG_VERSION"));
|
win.set_version(env!("CARGO_PKG_VERSION"));
|
||||||
win.set_website(env!("CARGO_PKG_HOMEPAGE"));
|
win.set_website(env!("CARGO_PKG_HOMEPAGE"));
|
||||||
win.set_logo(&load_img("/net/greyserv/maraiah/tycho/tycho2"));
|
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");
|
let win: gtk::Window = get_obj(b, "win-main");
|
||||||
|
|
||||||
win.set_application(app);
|
win.set_application(app);
|
||||||
win.show_all();
|
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
|
fn load_img(path: &'static str) -> gdk_pixbuf::Pixbuf
|
||||||
{
|
{
|
||||||
gdk_pixbuf::Pixbuf::new_from_resource(path).unwrap()
|
gdk_pixbuf::Pixbuf::new_from_resource(path).unwrap()
|
||||||
|
|
|
@ -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()))
|
(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
|
impl CairoDrawArea
|
||||||
{
|
{
|
||||||
pub const fn new(ctx: cairo::Context, w: f64, h: f64) -> Self
|
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
|
impl DrawArea for CairoDrawArea
|
||||||
{
|
{
|
||||||
fn w(&self) -> u32 {self.w}
|
type NativeImage = gdk_pixbuf::Pixbuf;
|
||||||
fn h(&self) -> u32 {self.h}
|
|
||||||
|
fn w(&self) -> Coord {self.w}
|
||||||
|
fn h(&self) -> Coord {self.h}
|
||||||
|
|
||||||
fn clear(&self, cr: impl Color)
|
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.move_to(f64::from(pos.0), f64::from(pos.1));
|
||||||
self.ctx.show_text(text);
|
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
|
pub struct CairoDrawArea
|
||||||
{
|
{
|
||||||
ctx: cairo::Context,
|
ctx: cairo::Context,
|
||||||
w: u32,
|
w: Coord,
|
||||||
h: u32,
|
h: Coord,
|
||||||
}
|
}
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -1,73 +1,31 @@
|
||||||
use maraiah::durandal::image::*;
|
use maraiah::durandal::image::*;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
pub trait CacheImage
|
||||||
pub struct Rect {pub x: u32, pub y: u32, pub w: u32, pub h: u32}
|
{
|
||||||
|
fn w(&self) -> Coord;
|
||||||
pub type Point = (u32, u32);
|
fn h(&self) -> Coord;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait DrawArea
|
pub trait DrawArea
|
||||||
{
|
{
|
||||||
fn w(&self) -> u32;
|
type NativeImage: CacheImage;
|
||||||
fn h(&self) -> u32;
|
|
||||||
|
fn w(&self) -> Coord;
|
||||||
|
fn h(&self) -> Coord;
|
||||||
|
|
||||||
fn clear(&self, cr: impl Color);
|
fn clear(&self, cr: impl Color);
|
||||||
fn rect(&self, rect: Rect, 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, cr: impl Color, text: &str);
|
||||||
|
fn image(&self, pos: Point, im: &Self::NativeImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Resource
|
pub type Coord = i32;
|
||||||
{
|
pub type Point = (Coord, Coord);
|
||||||
fn as_dir(&self) -> Option<&ResDir> {None}
|
|
||||||
fn as_file(&self) -> Option<&ResFile> {None}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResDir
|
#[derive(Copy, Clone, Debug)]
|
||||||
{
|
pub struct Rect {pub x: Coord, pub y: Coord, pub w: Coord, pub h: Coord}
|
||||||
pub fn new() -> ResDir
|
|
||||||
{
|
|
||||||
ResDir{hash: HashMap::new()}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert(&mut self, name: &str, res: Box<dyn Resource>)
|
|
||||||
{
|
|
||||||
self.hash.insert(name.to_string(), res);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self, name: &str) -> Option<&Box<dyn Resource>>
|
|
||||||
{
|
|
||||||
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<String, Box<dyn Resource>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ResFile
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0);
|
pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0);
|
||||||
pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 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
|
// EOF
|
||||||
|
|
Loading…
Reference in New Issue