Commit 75902027 authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Periodic general tidying and renaming.

parent 8fdc879d
......@@ -25,7 +25,7 @@ fn command_output(c: &Captures) -> String {
fn main() {
/* stdweb */
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("webgl_rendering_context.rs")).unwrap();
let mut file = File::create(&Path::new(&dest).join("webgl.rs")).unwrap();
Registry::new(Api::WebGl, Exts::NONE)
.write_bindings(StdwebGenerator, &mut file)
......
......@@ -69,8 +69,8 @@ impl Position {
pub fn get_edge(&self, which: &Direction) -> f64 {
let delta = self.middle_to_edge(which);
match *which {
LEFT|RIGHT => self.pos.0 + delta,
UP|DOWN => self.pos.1 + delta,
LEFT|RIGHT => self.pos.0 + delta,
UP|DOWN => self.pos.1 + delta,
IN|OUT => self.zoom.get_zoom()
}
}
......@@ -85,8 +85,8 @@ impl Position {
RIGHT => self.max_x,
DOWN => self.max_y as f64,
UP => 0.,
IN => self.zoom.get_limit(&AxisSense::Pos),
OUT => self.zoom.get_limit(&AxisSense::Neg),
IN => self.zoom.get_limit(&AxisSense::Max),
OUT => self.zoom.get_limit(&AxisSense::Min),
}
}
......
......@@ -17,6 +17,7 @@ impl DrawnResponse {
).collect());
}
#[allow(unused)]
pub fn size(&self) -> usize { self.shapes.as_ref().unwrap().len() }
pub fn get_response(&self) -> &SourceResponse { &self.sr }
......
......@@ -25,17 +25,17 @@ impl Zoom {
pub fn get_limit(&self, min_max: &AxisSense) -> f64 {
match *min_max {
AxisSense::Neg => -self.max_bp.log10(),
AxisSense::Pos => -MAX_LIMIT_BP.log10()
AxisSense::Min => -self.max_bp.log10(),
AxisSense::Max => -MAX_LIMIT_BP.log10()
}
}
fn check_min_limit(&self, val: f64) -> f64 {
val.max(self.get_limit(&AxisSense::Neg))
val.max(self.get_limit(&AxisSense::Min))
}
fn check_max_limit(&self, val: f64) -> f64 {
val.min(self.get_limit(&AxisSense::Pos))
val.min(self.get_limit(&AxisSense::Max))
}
pub fn set_zoom(&mut self, val: f64) {
......
......@@ -5,7 +5,7 @@ use stdweb::unstable::TryInto;
use serde_json::Value as JSONValue;
use composit::{ Compositor, StateManager, Stage };
use controller::input::{ Event, events_run, startup_events };
use controller::input::{ Action, actions_run, startup_actions };
use controller::global::{ Global, GlobalWeak };
use controller::output::Report;
use dom::domutil;
......@@ -21,7 +21,6 @@ pub struct App {
pub stage: Arc<Mutex<Stage>>,
pub state: Arc<Mutex<StateManager>>,
pub compo: Arc<Mutex<Compositor>>,
last_boxsize: Option<f64>,
report: Option<Report>
}
......@@ -38,10 +37,9 @@ impl App {
stage: Arc::new(Mutex::new(Stage::new())),
compo: Arc::new(Mutex::new(Compositor::new())),
state: Arc::new(Mutex::new(StateManager::new())),
last_boxsize: None,
report: None
};
out.run_events(&startup_events());
out.run_actions(&startup_actions());
out
}
......@@ -98,15 +96,15 @@ impl App {
out
}
pub fn run_events(self: &mut App, evs: &Vec<Event>) {
events_run(self,evs);
pub fn run_actions(self: &mut App, evs: &Vec<Action>) {
actions_run(self,evs);
}
pub fn check_size(self: &mut App) {
let mut sz = self.printer.lock().unwrap().get_available_size();
sz.0 = ((sz.0+3)/4)*4;
sz.1 = ((sz.1+3)/4)*4;
events_run(self,&vec! { Event::Resize(sz) });
actions_run(self,&vec! { Action::Resize(sz) });
}
pub fn force_size(self: &App) {
......
......@@ -63,7 +63,6 @@ impl AppRunner {
let mut imp = self.0.lock().unwrap();
imp.bling = bling;
let browser_el : HtmlElement = imp.bling.apply_bling(&imp.el);
let report = imp.app.lock().unwrap().get_report().clone();
imp.app = Arc::new(Mutex::new(App::new(&imp.g,&browser_el)));
imp.timers = Timers::new();
imp.projector = None;
......@@ -90,14 +89,7 @@ impl AppRunner {
let state = &mut imp.app.clone();
imp.timers.run(&mut state.lock().unwrap(), time);
}
fn get_element(&self) -> HtmlElement {
let mut imp = self.0.lock().unwrap();
let a = &mut imp.app.clone();
let out : HtmlElement = a.lock().unwrap().get_browser_element().clone();
out
}
pub fn init(&mut self) {
/* register main heartbeat of compositor */
register_compositor_ticks(self);
......
......@@ -11,7 +11,9 @@ use stdweb::web::{ HtmlElement, Element, IHtmlElement };
use composit::{
ComponentSourceList, StickManager, ActiveSource, ComponentSource, Stick
};
use controller::input::{ register_startup_events, initial_events, events_run };
use controller::input::{
register_startup_events, initial_actions, actions_run
};
use controller::global::AppRunner;
use debug::{ DebugComponentSource, DebugBling, MiniBling, create_interactors };
use debug::debug_stick_manager;
......@@ -19,7 +21,6 @@ use dom::{ domutil, Bling };
pub struct GlobalImpl {
apps: HashMap<String,AppRunner>,
elements: HashMap<String,Element>,
csl: ComponentSourceList,
sticks: Box<StickManager>
}
......@@ -28,7 +29,6 @@ impl GlobalImpl {
pub fn new() -> GlobalImpl {
let mut out = GlobalImpl {
apps: HashMap::<String,AppRunner>::new(),
elements: HashMap::<String,Element>::new(),
csl: ComponentSourceList::new(),
sticks: Box::new(debug_stick_manager())
};
......@@ -103,7 +103,7 @@ impl Global {
let ar = self.0.borrow_mut().get_apprunner(key);
if let Some(ar) = ar {
let app = ar.clone().state();
events_run(&mut app.lock().unwrap(),&initial_events());
actions_run(&mut app.lock().unwrap(),&initial_actions());
}
}
......
......@@ -3,7 +3,7 @@ use composit::StateValue;
use controller::global::App;
#[derive(Debug,Clone)]
pub enum Event {
pub enum Action {
Noop,
Pos(Dot<f64,f64>,Option<f64>),
Move(Move<f64,f64>),
......@@ -39,7 +39,7 @@ fn exe_move_event(app: &App, v: Move<f64,f64>) {
});
}
fn exe_zoom_event(app: &App, mut z: f64, by: bool) {
fn exe_zoom_event(app: &App, z: f64, by: bool) {
let z = app.with_stage(|s| {
if by {
s.inc_zoom(z);
......@@ -83,26 +83,26 @@ fn exe_set_state(a: &mut App, name: &str, on: StateValue) {
});
}
pub fn events_run(cg: &mut App, evs: &Vec<Event>) {
pub fn actions_run(cg: &mut App, evs: &Vec<Action>) {
for ev in evs {
let ev = ev.clone();
match ev {
Event::Pos(v,prop) => exe_pos_event(cg,v,prop),
Event::Move(v) => exe_move_event(cg,v),
Event::Zoom(z) => exe_zoom_event(cg,z,true),
Event::ZoomTo(z) => exe_zoom_event(cg,z,false),
Event::Resize(sz) => exe_resize(cg,sz),
Event::AddComponent(name) => exe_component_add(cg,&name),
Event::SetStick(name) => exe_set_stick(cg,&name),
Event::SetState(name,on) => exe_set_state(cg,&name,on),
Event::Noop => ()
Action::Pos(v,prop) => exe_pos_event(cg,v,prop),
Action::Move(v) => exe_move_event(cg,v),
Action::Zoom(z) => exe_zoom_event(cg,z,true),
Action::ZoomTo(z) => exe_zoom_event(cg,z,false),
Action::Resize(sz) => exe_resize(cg,sz),
Action::AddComponent(name) => exe_component_add(cg,&name),
Action::SetStick(name) => exe_set_stick(cg,&name),
Action::SetState(name,on) => exe_set_state(cg,&name,on),
Action::Noop => ()
}
}
}
pub fn startup_events() -> Vec<Event> {
pub fn startup_actions() -> Vec<Action> {
vec! {
Event::Pos(Dot(0_f64,0_f64),None),
//Event::Zoom(-3.)
Action::Pos(Dot(0_f64,0_f64),None),
//Action::Zoom(-3.)
}
}
......@@ -5,80 +5,80 @@ use stdweb::web::{ Element, HtmlElement };
use composit::StateValue;
use controller::global::{ App, AppRunner };
use controller::input::{ events_run, Event };
use controller::input::{ actions_run, Action };
use dom::event::{
EventListener, EventControl, EventType, EventData,
ICustomEvent, Target
};
use types::{ Move, Distance, Units };
fn custom_movement_event(dir: &str, unit: &str, v: &JSONValue) -> Event {
fn custom_movement_event(dir: &str, unit: &str, v: &JSONValue) -> Action {
if let JSONValue::Number(quant) = v {
let quant = quant.as_f64().unwrap() as f64;
let unit = match unit {
"base"|"bases"|"bp" => Units::Bases,
"pixel"|"pixels"|"px" => Units::Pixels,
"screen"|"screens"|"sc" => Units::Screens,
_ => { return Event::Noop; }
_ => { return Action::Noop; }
};
Event::Move(match dir {
Action::Move(match dir {
"left" => Move::Left(Distance(quant,unit)),
"right" => Move::Right(Distance(quant,unit)),
"up" => Move::Up(Distance(quant,unit)),
"down" => Move::Down(Distance(quant,unit)),
_ => { return Event::Noop; }
_ => { return Action::Noop; }
})
} else {
Event::Noop
Action::Noop
}
}
fn custom_zoom_event(kind: &str, v: &JSONValue) -> Event {
fn custom_zoom_event(kind: &str, v: &JSONValue) -> Action {
if let JSONValue::Number(quant) = v {
let quant = quant.as_f64().unwrap();
match kind {
"by" => {
Event::Zoom(quant)
Action::Zoom(quant)
},
_ => Event::Noop
_ => Action::Noop
}
} else {
Event::Noop
Action::Noop
}
}
fn custom_state_event(v: &JSONValue, sv: StateValue) -> Event {
fn custom_state_event(v: &JSONValue, sv: StateValue) -> Action {
if let JSONValue::String(track) = v {
Event::SetState(track.to_string(),sv)
Action::SetState(track.to_string(),sv)
} else {
Event::Noop
Action::Noop
}
}
fn custom_make_one_event(k: &String, v: &JSONValue) -> Event {
fn custom_make_one_event(k: &String, v: &JSONValue) -> Action {
let parts : Vec<&str> = k.split("_").collect();
match parts.len() {
1 => return match parts[0] {
"on" => custom_state_event(v,StateValue::On()),
"standby" => custom_state_event(v,StateValue::OffWarm()),
"off" => custom_state_event(v,StateValue::OffCold()),
_ => Event::Noop
_ => Action::Noop
},
2 => return match parts[0] {
"zoom" => custom_zoom_event(parts[1],v),
_ => Event::Noop
_ => Action::Noop
},
3 => return match parts[0] {
"move" => custom_movement_event(parts[1],parts[2],v),
_ => Event::Noop
_ => Action::Noop
},
_ => ()
}
Event::Noop
Action::Noop
}
fn custom_make_events(j: &JSONValue) -> Vec<Event> {
let mut out = Vec::<Event>::new();
fn custom_make_events(j: &JSONValue) -> Vec<Action> {
let mut out = Vec::<Action>::new();
if let JSONValue::Object(map) = j {
for (k,v) in map {
out.push(custom_make_one_event(k,v));
......@@ -102,10 +102,10 @@ impl EventListener<()> for DirectEventListener {
let evs = match e {
EventData::CustomEvent(_,_,_,c) =>
custom_make_events(&c.details().unwrap()),
_ => Vec::<Event>::new()
_ => Vec::<Action>::new()
};
console!("receive");
events_run(&mut self.cg.lock().unwrap(),&evs);
actions_run(&mut self.cg.lock().unwrap(),&evs);
}
}
......
......@@ -4,7 +4,7 @@ use dom::domutil;
use stdweb::web::{ Element, HtmlElement };
use controller::global::{ App, AppRunner };
use controller::input::{ events_run, Event };
use controller::input::{ actions_run, Action };
use dom::event::{
EventListener, EventControl, EventType, EventData, Target
};
......@@ -24,13 +24,11 @@ impl EventListener<()> for DomEventListener {
fn receive(&mut self, _el: &Target, e: &EventData, _idx: &()) {
let evs = match e {
EventData::GenericEvent(EventType::ResizeEvent,_) => {
vec! {
Event::Resize(domutil::size(&self.el))
}
vec! { Action::Resize(domutil::size(&self.el)) }
}
_ => Vec::<Event>::new()
_ => Vec::<Action>::new()
};
events_run(&mut self.cg.lock().unwrap(),&evs);
actions_run(&mut self.cg.lock().unwrap(),&evs);
}
}
......
mod direct;
mod physics;
mod events;
mod action;
mod timers;
mod user;
mod domevents;
......@@ -9,11 +9,11 @@ mod eggdetector;
mod optical;
pub use self::physics::MousePhysics;
pub use self::events::{ Event, events_run, startup_events };
pub use self::action::{ Action, actions_run, startup_actions };
pub use self::timers::{ Timer, Timers };
pub use self::domevents::register_dom_events;
pub use self::direct::register_direct_events;
pub use self::user::register_user_events;
pub use self::startup::{ register_startup_events, initial_events };
pub use self::startup::{ register_startup_events, initial_actions };
pub use self::eggdetector::EggDetector;
use std::sync::{ Arc, Mutex };
use controller::global::{ App, AppRunner };
use controller::input::{ Event, events_run };
use controller::input::{ Action,actions_run };
use types::CDFraction;
pub struct OpticalImpl {
......@@ -21,9 +21,9 @@ impl OpticalImpl {
fn send_delta(&mut self, app: &mut App, amt: f64) {
if let Some((pos,prop)) = self.pos {
events_run(app,&vec! {
Event::Zoom(amt),
Event::Pos(pos,Some(prop))
actions_run(app,&vec! {
Action::Zoom(amt),
Action::Pos(pos,Some(prop))
});
}
}
......
use std::sync::{ Arc, Mutex };
use types::{ CPixel, CDFraction, cdfraction };
use controller::global::{ App, AppRunner };
use controller::input::{ Event, events_run };
use controller::input::{ Action, actions_run };
use types::{ Move, Distance, Units, ddiv };
pub struct MousePhysicsImpl {
......@@ -63,9 +63,9 @@ impl MousePhysicsImpl {
}
fn make_events(&self, cg: &mut App, dx: &CDFraction) {
events_run(cg,&vec! {
Event::Move(Move::Left(Distance(dx.0,Units::Pixels))),
Event::Move(Move::Up(Distance(dx.1,Units::Pixels)))
actions_run(cg,&vec! {
Action::Move(Move::Left(Distance(dx.0,Units::Pixels))),
Action::Move(Move::Up(Distance(dx.1,Units::Pixels)))
});
}
......
......@@ -4,7 +4,7 @@ use stdweb::unstable::TryInto;
use composit::StateValue;
use controller::global::Global;
use controller::input::Event;
use controller::input::Action;
use dom::domutil;
use dom::event::{ EventListener, EventType, EventData, EventControl, Target };
use dom::AppEventData;
......@@ -49,15 +49,15 @@ pub fn register_startup_events(g: &Arc<Mutex<Global>>) {
ec_start.add_element(&domutil::query_select("body"),());
}
pub fn initial_events() -> Vec<Event> {
pub fn initial_actions() -> Vec<Action> {
vec! {
Event::AddComponent("internal:debug-main".to_string()),
Event::AddComponent("internal:debug-odd".to_string()),
Event::AddComponent("internal:debug-even".to_string()),
Event::SetState("even".to_string(),StateValue::On()),
Event::SetState("odd".to_string(),StateValue::On()),
Event::SetStick("polar".to_string()),
Event::Pos(Dot(0_f64,0_f64),None),
Event::ZoomTo(-5.)
Action::AddComponent("internal:debug-main".to_string()),
Action::AddComponent("internal:debug-odd".to_string()),
Action::AddComponent("internal:debug-even".to_string()),
Action::SetState("even".to_string(),StateValue::On()),
Action::SetState("odd".to_string(),StateValue::On()),
Action::SetStick("polar".to_string()),
Action::Pos(Dot(0_f64,0_f64),None),
Action::ZoomTo(-5.)
}
}
use std::collections::HashMap;
use std::sync::{ Arc, Mutex };
use dom::domutil;
use dom::event::{ EventListener, EventType, EventData, EventControl, Target, MouseData };
use dom::event::{ EventListener, EventType, EventData, EventControl, Target };
use stdweb::web::{ Element, HtmlElement, IHtmlElement };
use stdweb::traits::IEvent;
use controller::global::{ App, AppRunner };
use controller::input::{ Event, events_run, EggDetector };
use controller::input::{ Action, actions_run, EggDetector };
use controller::input::physics::MousePhysics;
use controller::input::optical::Optical;
use types::Dot;
......@@ -85,11 +85,11 @@ impl EventListener<()> for UserEventListener {
}
struct EventEggs {
patterns: Vec<(EggDetector,Vec<Event>)>
patterns: Vec<(EggDetector,Vec<Action>)>
}
impl EventEggs {
pub fn new(actions: HashMap<&str,Vec<Event>>) -> EventEggs {
pub fn new(actions: HashMap<&str,Vec<Action>>) -> EventEggs {
EventEggs {
patterns: actions.iter().map(|(k,v)| {
(EggDetector::new(Some(k)),v.clone())
......@@ -102,7 +102,7 @@ impl EventEggs {
pattern.new_char(key);
if pattern.is_active() {
pattern.reset();
events_run(&mut app.lock().unwrap(),actions);
actions_run(&mut app.lock().unwrap(),actions);
}
}
}
......@@ -119,9 +119,9 @@ impl UserEventListenerBody {
pub fn new(app_runner: &AppRunner, mouse: &Arc<Mutex<MousePhysics>>) -> UserEventListenerBody {
let event_eggs = hashmap! {
"@polar#" => [
Event::AddComponent("internal:debug-main".to_string()),
Event::SetStick("polar".to_string()),
Event::ZoomTo(-5.)
Action::AddComponent("internal:debug-main".to_string()),
Action::SetStick("polar".to_string()),
Action::ZoomTo(-5.)
].to_vec()
};
UserEventListenerBody {
......
......@@ -8,6 +8,7 @@ use serde_json::Value as JSONValue;
use serde_json::Number as JSONNumber;
#[derive(Clone)]
#[allow(unused)]
pub enum StatusJigsawType {
Number,
String,
......@@ -15,6 +16,7 @@ pub enum StatusJigsawType {
}
#[derive(Clone)]
#[allow(unused)]
pub enum StatusJigsaw {
Atom(String,StatusJigsawType),
Array(Vec<StatusJigsaw>),
......@@ -38,7 +40,7 @@ impl StatusOutput {
}
}
fn is_send_now(&self, key: &str, t: f64) -> bool {
fn is_send_now(&self, t: f64) -> bool {
if let Some(interval) = self.send_every {
if interval == 0. { return true; }
if let Some(last_sent) = self.last_sent {
......@@ -163,7 +165,7 @@ impl ReportImpl {
if let Some(ref last_value) = s.last_value {
if last_value == &value { continue; }
}
if s.is_send_now(k,t) {
if s.is_send_now(t) {
out.insert(k.to_string(),value.clone());
}
}
......
......@@ -219,12 +219,4 @@ impl DebugConsole {
out.evctrl.add_element(&el,());
out
}
pub fn add(&mut self, name: &str, value: &str) {
self.imp.borrow_mut().add(name,value);
}
pub fn select(&mut self, name: &str) {
self.imp.borrow_mut().select(name);
}
}
......@@ -127,7 +127,7 @@ fn setup_debug_console(el: &HtmlElement) {
fn setup_testcard_selector(a: &Arc<Mutex<App>>, el: &HtmlElement) {
let a = a.clone();
let sel_el = domutil::query_selector2(&el.clone().into(),".console .testcard").unwrap();
sel_el.add_event_listener(enclose! { (a,el) move |e: ChangeEvent| {
sel_el.add_event_listener(enclose! { (a) move |e: ChangeEvent| {
let mut a = a.lock().unwrap();
let node : SelectElement = e.target().unwrap().try_into().ok().unwrap();