gui state test

gui-branch
an 2019-03-18 08:21:30 -04:00
parent 422a7989f5
commit 9c02fba968
5 changed files with 191 additions and 44 deletions

View File

@ -0,0 +1,5 @@
.first-start-window {
background-color: #000000;
color: #AAAAAA;
font: 16px "FixedSys", "Monospace";
}

View File

@ -98,6 +98,7 @@ Author: Alison Sanderson
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">The name of the map. Unicode symbols that are supported by the Mac OS Roman encoding are converted automatically when saved.</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
@ -109,7 +110,6 @@ Author: Alison Sanderson
<object class="GtkEntry" id="ent-map-name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">The name of the map. Unicode symbols that are supported by the Mac OS Roman encoding are converted automatically when saved.</property>
</object>
</child>
</object>
@ -144,6 +144,7 @@ Author: Alison Sanderson
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">The texture collection to use for the map. This is one of five bitmap collections stored in the Shapes file.</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
@ -158,7 +159,6 @@ Author: Alison Sanderson
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">The texture collection to use for the map. This is one of five bitmap collections stored in the Shapes file.</property>
<property name="active">0</property>
<items>
<item translatable="yes">Water</item>
@ -189,6 +189,7 @@ Author: Alison Sanderson
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">The sky to display on sides which are marked as "Landscape." This is the sole bitmap of one of four collections in the Shapes file.</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
@ -203,7 +204,6 @@ Author: Alison Sanderson
<object class="GtkComboBoxText">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">The sky to display on sides which are marked as "Landscape." This is the sole bitmap of one of four collections in the Shapes file.</property>
<property name="active">0</property>
<items>
<item translatable="yes">Lh'owon Day</item>
@ -627,41 +627,96 @@ Author: Alison Sanderson
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkFrame">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment">
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="left_padding">12</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkSpinButton">
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">This field is unused and must be either 0 or 1. It used to be used to give different physics to the map editor and low gravity before it was made into an environment flag.</property>
<property name="text" translatable="yes">0</property>
<property name="truncate_multiline">True</property>
<property name="adjustment">adj-phys-id</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="left_padding">12</property>
<child>
<object class="GtkSpinButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">This field is unused and must be either 0 or 1. It used to be used to give different physics to the map editor and low gravity before it was made into an environment flag.</property>
<property name="text" translatable="yes">0</property>
<property name="truncate_multiline">True</property>
<property name="adjustment">adj-phys-id</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Physics ID</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child type="label">
<object class="GtkLabel">
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Physics ID</property>
<property name="tooltip_text" translatable="yes">This field overrides the Landscape value, since Marathon 1 used that field for the music number.</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="left_padding">12</property>
<child>
<object class="GtkSpinButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">0</property>
<property name="truncate_multiline">True</property>
<property name="adjustment">adj-phys-id</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="wrap">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Song ID</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
@ -679,7 +734,6 @@ Author: Alison Sanderson
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">These flags were added by Aleph One but are hidden and probably not meant to be used.</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
@ -745,7 +799,7 @@ Author: Alison Sanderson
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Hidden Mission Flags</property>
<property name="label" translatable="yes">Aleph Mission Flags</property>
</object>
</child>
</object>
@ -759,7 +813,6 @@ Author: Alison Sanderson
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">These flags were added by Aleph One but are hidden and probably not meant to be used.</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
@ -885,7 +938,7 @@ Author: Alison Sanderson
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Hidden Environment Flags</property>
<property name="label" translatable="yes">Aleph Environment Flags</property>
</object>
</child>
</object>
@ -1079,6 +1132,44 @@ Author: Alison Sanderson
</object>
</child>
</object>
<object class="GtkWindow" id="win-first-start">
<property name="can_focus">False</property>
<property name="title" translatable="yes">First Startup</property>
<property name="resizable">False</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">10</property>
<property name="bottom_padding">10</property>
<property name="left_padding">10</property>
<property name="right_padding">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">II. A word from the Programmer:
This entire program was written in Vim. Emacs users beware,
IDEs beware, all beware! For I have the power of Vim! Hahahaha
hahahahahaha! Anyway, hopefully you enjoy the program. It's
my first serious effort at writing a GUI program. This toolset
is made to encourage people to try out Marathon and hopefully
start making stuff. Modding should be a fun journey for
every one just as it has helped me to further my abilities at
many things, including programming.
Also, 3 space tabs win. --- Alison Sanderson
Programmer of Maraiah</property>
<property name="angle">4</property>
</object>
</child>
</object>
</child>
<style>
<class name="first-start-window"/>
</style>
</object>
<object class="GtkWindow" id="win-main">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Tycho</property>

View File

@ -7,5 +7,6 @@
<file compressed="true" alias="lines">data/lines.png</file>
<file compressed="true" alias="points">data/points.png</file>
<file compressed="true" preprocess="xml-stripblanks" alias="ui">data/tycho.xml</file>
<file compressed="true" alias="css">data/tycho.css</file>
</gresource>
</gresources>

View File

@ -17,23 +17,22 @@ pub fn draw_map_none<D, I>(d: &D, im: &I)
d.text((4, d.h() - 4), "CAS.qterm//CyberAcme Systems Inc.", CR_RED);
}
pub fn new_map() -> MapState
pub fn new_map() -> MapEditorState
{
let info = Default::default();
let ed = EditorState{};
let ma = MapState{ed, info};
let ed = MapEditorState{info};
ma
ed
}
pub struct EditorState
impl Drop for MapEditorState
{
fn drop(&mut self) {eprintln!("dropping MapEditorState");}
}
pub struct MapState
pub struct MapEditorState
{
ed: EditorState,
info: map::Minf,
}

View File

@ -5,6 +5,9 @@ use crate::{hiddenprotocol::*, noroom::*};
use gio::prelude::*;
use gtk::prelude::*;
use maraiah::durandal::err::*;
use std::{os::raw::c_char, rc::Rc};
const DATA_NAME: *const c_char = b"tycho data\0".as_ptr() as *const c_char;
fn hide_on_delete(win: &gtk::Window, _: &gdk::Event) -> Inhibit
{
@ -43,9 +46,20 @@ fn run_app(app: &gtk::Application)
{
let b = &gtk::Builder::new_from_resource("/net/greyserv/maraiah/tycho/ui");
let app_ = app.clone();
let prv = gtk::CssProvider::new();
prv.load_from_resource("/net/greyserv/maraiah/tycho/css");
let scr = gdk::Screen::get_default().expect("no screen found");
let pri = gtk::STYLE_PROVIDER_PRIORITY_APPLICATION;
gtk::StyleContext::add_provider_for_screen(&scr, &prv, pri);
let app_ = app.downgrade();
let btn: gtk::MenuItem = get_obj(b, "btn-quit");
btn.connect_activate(move |_| app_.quit());
btn.connect_activate(move |_| {
if let Some(app) = app_.upgrade() {
app.quit();
}
});
let btn: gtk::MenuItem = get_obj(b, "btn-about");
let win: gtk::AboutDialog = get_obj(b, "win-about");
@ -74,6 +88,9 @@ fn run_app(app: &gtk::Application)
win.set_website(env!("CARGO_PKG_HOMEPAGE"));
win.set_logo(&load_img("/net/greyserv/maraiah/tycho/tycho2"));
let win: gtk::Window = get_obj(b, "win-first-start");
win.show_all();
let win: gtk::Window = get_obj(b, "win-main");
win.set_application(app);
win.show_all();
@ -95,6 +112,7 @@ fn main() -> ResultS<()>
// get jacked, punk. opaque data structures are for nerds.
const RESOURCE_DATA: &[u8] = include_bytes!("data/tycho.res");
// first we create the static resource header, which is really simple
let mut static_resource =
gio_sys::GStaticResource{data: RESOURCE_DATA.as_ptr(),
data_len: RESOURCE_DATA.len(),
@ -102,21 +120,54 @@ fn main() -> ResultS<()>
next: std::ptr::null_mut(),
padding: std::ptr::null_mut()};
// init it, now we can use it throughout the entire app without copying!
unsafe {
gio_sys::g_static_resource_init(&mut static_resource);
}
let app = gtk::Application::new("net.greyserv.maraiah.tycho",
gio::ApplicationFlags::empty())?;
let ret = {
// create the application first
let app = gtk::Application::new("net.greyserv.maraiah.tycho",
gio::ApplicationFlags::empty())?;
app.connect_activate(run_app);
app.connect_activate(run_app);
let ret = if app.run(&[]) == 0 {
Ok(())
} else {
Err(err_msg("bad return"))
// then we can attach the editor state to the app's hashtable
let app_ptr = app.clone().upcast::<glib::Object>().as_ptr();
let dat = Rc::new(None::<MapEditorState>);
unsafe {
// this ref will be dropped after the app is run
let ptr = Rc::into_raw(dat.clone()) as glib_sys::gpointer;
gobject_sys::g_object_set_data(app_ptr, DATA_NAME, ptr);
}
// run the application and save the return
let ret = if app.run(&[]) == 0 {
Ok(())
} else {
Err(err_msg("bad return"))
};
// unref the editor state so it will go away
unsafe {
let ptr = gobject_sys::g_object_get_data(app_ptr, DATA_NAME);
let ptr = Rc::from_raw(ptr);
std::mem::drop(ptr);
}
// destroy the editor state first, and make sure there are no dangling
// references to the application.
std::mem::drop(dat);
assert_eq!(app.ref_count(), 1);
ret
};
// finally, deinit the "static" data, and everything will be done
unsafe {
gio_sys::g_static_resource_fini(&mut static_resource);
}