move sources to source/
|
@ -12,7 +12,7 @@ edition = "2018"
|
|||
publish = false
|
||||
|
||||
[workspace]
|
||||
members = ["src/leela", "src/tycho"]
|
||||
members = ["source/leela", "source/tycho"]
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
||||
|
@ -28,4 +28,4 @@ lto = true
|
|||
|
||||
[lib]
|
||||
name = "maraiah"
|
||||
path = "src/lib.rs"
|
||||
path = "source/lib.rs"
|
||||
|
|
Before Width: | Height: | Size: 226 B After Width: | Height: | Size: 226 B |
Before Width: | Height: | Size: 205 B After Width: | Height: | Size: 205 B |
Before Width: | Height: | Size: 538 B After Width: | Height: | Size: 538 B |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
@ -0,0 +1,20 @@
|
|||
use crate::stoneage::*;
|
||||
|
||||
pub fn draw_map_none(d: &impl DrawArea)
|
||||
{
|
||||
// TODO: draw middle image
|
||||
|
||||
// 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.");
|
||||
}
|
||||
|
||||
// EOF
|
|
@ -0,0 +1,173 @@
|
|||
mod hiddenprotocol;
|
||||
mod noroom;
|
||||
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
|
||||
{
|
||||
win.hide();
|
||||
Inhibit(true)
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
let d = CairoDrawArea::new(cr.clone(), w, h);
|
||||
|
||||
d.clear(Color16::new(0, 0, 0));
|
||||
draw_map_none(&d);
|
||||
|
||||
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::<Vec<_>>());
|
||||
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()
|
||||
}
|
||||
|
||||
fn get_obj<T>(b: >k::Builder, name: &str) -> T
|
||||
where T: glib::object::IsA<glib::object::Object>
|
||||
{
|
||||
b.get_object(name).unwrap()
|
||||
}
|
||||
|
||||
fn main() -> ResultS<()>
|
||||
{
|
||||
// get jacked, punk. opaque data structures are for nerds.
|
||||
const RESOURCE_DATA: &'static [u8] = include_bytes!("data/tycho.res");
|
||||
|
||||
let mut static_resource =
|
||||
gio_sys::GStaticResource{data: RESOURCE_DATA.as_ptr(),
|
||||
data_len: RESOURCE_DATA.len(),
|
||||
resource: std::ptr::null_mut(),
|
||||
next: std::ptr::null_mut(),
|
||||
padding: std::ptr::null_mut()};
|
||||
|
||||
unsafe {
|
||||
gio_sys::g_static_resource_init(&mut static_resource);
|
||||
}
|
||||
|
||||
let app = gtk::Application::new("net.greyserv.maraiah.tycho",
|
||||
gio::ApplicationFlags::empty())?;
|
||||
|
||||
app.connect_activate(run_app);
|
||||
|
||||
let ret = if app.run(&[]) == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(err_msg("bad return"))
|
||||
};
|
||||
|
||||
unsafe {
|
||||
gio_sys::g_static_resource_fini(&mut static_resource);
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
// EOF
|
|
@ -0,0 +1,65 @@
|
|||
use crate::stoneage::*;
|
||||
use maraiah::durandal::image::*;
|
||||
|
||||
fn flt_color(cr: impl Color) -> (f64, f64, f64)
|
||||
{
|
||||
fn flt_color(n: u16) -> f64 {f64::from(n) / f64::from(u16::max_value())}
|
||||
|
||||
(flt_color(cr.r()), flt_color(cr.g()), flt_color(cr.b()))
|
||||
}
|
||||
|
||||
impl CairoDrawArea
|
||||
{
|
||||
pub const fn new(ctx: cairo::Context, w: f64, h: f64) -> Self
|
||||
{
|
||||
CairoDrawArea{ctx, w: w as u32, h: h as u32}
|
||||
}
|
||||
}
|
||||
|
||||
impl DrawArea for CairoDrawArea
|
||||
{
|
||||
fn w(&self) -> u32 {self.w}
|
||||
fn h(&self) -> u32 {self.h}
|
||||
|
||||
fn clear(&self, cr: impl Color)
|
||||
{
|
||||
use cairo::{FontSlant, FontWeight};
|
||||
|
||||
self.rect(Rect{x: 0, y: 0, w: self.w(), h: self.h()}, cr);
|
||||
|
||||
self.ctx.select_font_face("Sans", FontSlant::Normal, FontWeight::Normal);
|
||||
self.ctx.set_font_size(14.0);
|
||||
}
|
||||
|
||||
fn rect(&self, rect: Rect, cr: impl Color)
|
||||
{
|
||||
let x1 = f64::from(rect.x);
|
||||
let y1 = f64::from(rect.y);
|
||||
let x2 = f64::from(rect.w) + x1;
|
||||
let y2 = f64::from(rect.h) + y1;
|
||||
|
||||
let (r, g, b) = flt_color(cr);
|
||||
|
||||
self.ctx.set_source_rgb(r, g, b);
|
||||
self.ctx.rectangle(x1, y1, x2, y2);
|
||||
self.ctx.fill();
|
||||
}
|
||||
|
||||
fn text(&self, pos: Point, cr: impl Color, text: &str)
|
||||
{
|
||||
let (r, g, b) = flt_color(cr);
|
||||
|
||||
self.ctx.set_source_rgb(r, g, b);
|
||||
self.ctx.move_to(f64::from(pos.0), f64::from(pos.1));
|
||||
self.ctx.show_text(text);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CairoDrawArea
|
||||
{
|
||||
ctx: cairo::Context,
|
||||
w: u32,
|
||||
h: u32,
|
||||
}
|
||||
|
||||
// EOF
|
|
@ -0,0 +1,73 @@
|
|||
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 DrawArea
|
||||
{
|
||||
fn w(&self) -> u32;
|
||||
fn h(&self) -> u32;
|
||||
|
||||
fn clear(&self, cr: impl Color);
|
||||
fn rect(&self, rect: Rect, cr: impl Color);
|
||||
fn text(&self, pos: Point, cr: impl Color, text: &str);
|
||||
}
|
||||
|
||||
pub trait Resource
|
||||
{
|
||||
fn as_dir(&self) -> Option<&ResDir> {None}
|
||||
fn as_file(&self) -> Option<&ResFile> {None}
|
||||
}
|
||||
|
||||
impl ResDir
|
||||
{
|
||||
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_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
|
|
@ -1,48 +0,0 @@
|
|||
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
|
|
@ -1,72 +0,0 @@
|
|||
use gdk::prelude::*;
|
||||
use gio::prelude::*;
|
||||
use gtk::prelude::*;
|
||||
use maraiah::durandal::err::*;
|
||||
|
||||
include!("windows.rs");
|
||||
include!("buttons.rs");
|
||||
include!("map_draw.rs");
|
||||
|
||||
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_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);
|
||||
}
|
||||
|
||||
fn load_img(path: &'static str) -> gdk_pixbuf::Pixbuf
|
||||
{
|
||||
gdk_pixbuf::Pixbuf::new_from_resource(path).unwrap()
|
||||
}
|
||||
|
||||
fn get_obj<T>(b: >k::Builder, name: &str) -> T
|
||||
where T: glib::object::IsA<glib::object::Object>
|
||||
{
|
||||
b.get_object(name).unwrap()
|
||||
}
|
||||
|
||||
fn main() -> ResultS<()>
|
||||
{
|
||||
// get jacked, punk. opaque data structures are for nerds.
|
||||
const RESOURCE_DATA: &'static [u8] = include_bytes!("data/tycho.res");
|
||||
|
||||
let mut static_resource =
|
||||
gio_sys::GStaticResource{data: RESOURCE_DATA.as_ptr(),
|
||||
data_len: RESOURCE_DATA.len(),
|
||||
resource: std::ptr::null_mut(),
|
||||
next: std::ptr::null_mut(),
|
||||
padding: std::ptr::null_mut()};
|
||||
|
||||
unsafe {
|
||||
gio_sys::g_static_resource_init(&mut static_resource);
|
||||
}
|
||||
|
||||
let app = gtk::Application::new("net.greyserv.maraiah.tycho",
|
||||
gio::ApplicationFlags::empty())?;
|
||||
|
||||
app.connect_activate(run_app);
|
||||
|
||||
let ret = if app.run(&[]) == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(err_msg("bad return"))
|
||||
};
|
||||
|
||||
unsafe {
|
||||
gio_sys::g_static_resource_fini(&mut static_resource);
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
// EOF
|
|
@ -1,71 +0,0 @@
|
|||
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
|
|
@ -1,39 +0,0 @@
|
|||
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::<Vec<_>>());
|
||||
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
|