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

Polar test card to use odd/even for track demo.

parent 5aa165ba
......@@ -13,9 +13,9 @@ use composit::{
};
use controller::input::{ register_startup_events, initial_events, events_run };
use controller::global::AppRunner;
use debug::{ DebugComponentSource, DebugBling, create_interactors };
use debug::{ DebugComponentSource, DebugBling, MiniBling, create_interactors };
use debug::debug_stick_manager;
use dom::{ domutil, NoBling, Bling };
use dom::{ domutil, Bling };
pub struct GlobalImpl {
apps: HashMap<String,AppRunner>,
......@@ -94,7 +94,7 @@ impl Global {
let bling : Box<Bling> = if debug {
Box::new(DebugBling::new(create_interactors()))
} else {
Box::new(NoBling::new())
Box::new(MiniBling::new())
};
let ar = AppRunner::new(&GlobalWeak::new(&self),&el,bling);
{
......
......@@ -2,12 +2,12 @@ use std::sync::{ Arc, Mutex };
use stdweb::unstable::TryInto;
use composit::StateValue;
use controller::global::Global;
use controller::input::Event;
use dom::domutil;
use dom::event::{ EventListener, EventType, EventData, EventControl, Target };
use dom::AppEventData;
use types::Dot;
pub struct StartupEventListener {
......@@ -52,6 +52,10 @@ pub fn register_startup_events(g: &Arc<Mutex<Global>>) {
pub fn initial_events() -> Vec<Event> {
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.)
......
......@@ -2,14 +2,10 @@ mod pane;
mod testcards;
pub use debug::pane::{
DebugConsole,
DebugBling,
create_interactors,
DebugConsole, DebugBling, MiniBling, create_interactors,
debug_panel_entry_add,
};
pub use debug::testcards::{
DebugComponentSource,
debug_stick_manager,
testcard_base
DebugComponentSource, debug_stick_manager, testcard_base
};
......@@ -29,8 +29,6 @@ pub const DEBUGSTAGE : &str = r##"
<select class="testcard">
<option value="">- testcards -</option>
<option value="polar">Polar Testcard</option>
<option value="draw">Jank Testcard</option>
<option value="onoff">On/Off Testcard</option>
<option value="button">Button Testcard</option>
<option value="text">Text Testcard</option>
<option value="ruler">Ruler Testcard</option>
......
use std::sync::{ Arc, Mutex };
use stdweb::web::HtmlElement;
use composit::StateValue;
use controller::global::App;
use controller::input::{ Event, events_run };
use dom::{ Bling, NoBling };
pub struct MiniBling {
nobling: NoBling
}
impl MiniBling {
pub fn new() -> MiniBling {
MiniBling{
nobling: NoBling::new()
}
}
}
impl Bling for MiniBling {
fn apply_bling(&self, el: &HtmlElement) -> HtmlElement {
self.nobling.apply_bling(el)
}
fn key(&mut self, app: &Arc<Mutex<App>>, key: &str) {
let action = match key {
"q" => Event::SetState("odd".to_string(),StateValue::On()),
"Q" => Event::SetState("odd".to_string(),StateValue::OffCold()),
"w" => Event::SetState("even".to_string(),StateValue::On()),
"W" => Event::SetState("even".to_string(),StateValue::OffCold()),
_ => Event::Noop
};
events_run(&mut app.lock().unwrap(),&vec! { action });
}
}
mod console;
mod debugbling;
mod minibling;
pub use self::debugbling::{
DebugBling,
......@@ -9,3 +9,4 @@ pub use self::debugbling::{
};
pub use self::console::DebugConsole;
pub use self::minibling::MiniBling;
......@@ -12,7 +12,7 @@ use debug::testcards::{ bs_source_main, bs_source_sub, polar_source };
fn debug_source_main() -> DebugSource {
let mut s = DebugSource::new();
s.add_stick("polar",Box::new(polar_source()));
s.add_stick("polar",Box::new(polar_source(None)));
s.add_stick("text",Box::new(text_source()));
s.add_stick("leaf",Box::new(leafcard_source(true)));
s.add_stick("ruler",Box::new(leafcard_source(false)));
......@@ -23,6 +23,7 @@ fn debug_source_main() -> DebugSource {
fn debug_source_sub(even: bool) -> DebugSource {
let mut s = DebugSource::new();
s.add_stick("button",Box::new(bs_source_sub(even)));
s.add_stick("polar",Box::new(polar_source(Some(even))));
s
}
......
mod visual;
mod common;
mod bigscience;
mod polar;
......
......@@ -212,8 +212,9 @@ fn get_blocks(leaf: &Leaf,starts_rng: &Vec<[i32;2]>) -> Vec<(f32,f32,f32,f32)> {
}
/* designed to fill most of 100kb scale */
fn track(lc: &mut SourceResponse, leaf: &Leaf, p: &Palette, t: i32) {
fn track(lc: &mut SourceResponse, leaf: &Leaf, p: &Palette, t: i32, even: bool) {
let is_gene = (t<4 || t%3 == 0);
if is_gene == even { return; }
let name = if t % 7 == 3 { "E" } else { "K" };
let tx = text_texture(name,&p.lato_18,
&Colour(96,96,96),&Colour(255,255,255));
......@@ -367,7 +368,7 @@ fn track(lc: &mut SourceResponse, leaf: &Leaf, p: &Palette, t: i32) {
}
}
pub fn polar_source() -> ClosureSource {
pub fn polar_source(which: Option<bool>) -> ClosureSource {
let p = Palette {
lato_12: FCFont::new(12,"Lato",FontVariety::Normal),
lato_18: FCFont::new(12,"Lato",FontVariety::Bold),
......@@ -375,13 +376,16 @@ pub fn polar_source() -> ClosureSource {
grey: ColourSpec::Spot(Colour(199,208,213))
};
ClosureSource::new(0.,move |ref mut lc,leaf| {
one_offs(lc,&p);
draw_frame(lc,&leaf,AxisSense::Pos,&p);
draw_frame(lc,&leaf,AxisSense::Neg,&p);
measure(lc,&leaf,AxisSense::Pos,&p);
measure(lc,&leaf,AxisSense::Neg,&p);
for t in 0..TRACKS {
track(lc,&leaf,&p,t);
if let Some(even) = which {
for t in 0..TRACKS {
track(lc,&leaf,&p,t,even);
}
} else {
one_offs(lc,&p);
draw_frame(lc,&leaf,AxisSense::Pos,&p);
draw_frame(lc,&leaf,AxisSense::Neg,&p);
measure(lc,&leaf,AxisSense::Pos,&p);
measure(lc,&leaf,AxisSense::Neg,&p);
}
closure_done(lc,TRACKS*PITCH+TOP);
})
......
use std::cell::RefCell;
use std::rc::Rc;
use composit::StateValue;
use controller::input::Event;
use controller::global::App;
struct State {
zoomscale: f32,
hpos: f32,
vpos: f32,
fpos: f32,
call: i32,
old_time: f64,
}
fn animate(time : f64, cg: &mut App, s: Rc<RefCell<State>>) {
let mut state = s.borrow_mut();
if state.old_time < 1. { state.old_time = time; }
let delta = ((time - state.old_time) / 5000.0) as f32;
state.old_time = time;
state.call += 1;
state.zoomscale += delta* 5.0;
state.hpos += delta *3.763;
state.vpos += delta *5.414;
state.fpos += delta *7.21;
/*
cg.with_stage(|s| {
s.set_zoom((state.zoomscale.cos()/2.0)-2.5 as f32);
s.set_pos(&Dot(
((state.hpos.cos())*0.15) as f64,
((state.vpos.sin())*150.-50.) as f64));
});
*/
cg.run_events(&vec!{ Event::ZoomTo((state.zoomscale.cos()/2.0+4.0).into()) });
cg.with_state(|s| {
let odd_state = if state.hpos.cos() > 0. {
StateValue::OffWarm()
} else {
StateValue::On()
};
let even_state = if state.vpos.sin() > 0. {
StateValue::OffCold()
} else {
StateValue::On()
};
s.set_atom_state("odd",odd_state);
s.set_atom_state("even",even_state);
});
}
/*
fn testcard_visual(ar: &mut AppRunner, onoff: bool) {
let a = ar.state();
let mut a = a.lock().unwrap();
//big_science(&mut a,onoff);
let state = Rc::new(RefCell::new(State {
hpos: 0.0,
vpos: 0.0,
fpos: 0.0,
zoomscale: 0.0,
old_time: 0.0,
call: 0,
}));
ar.add_timer(move |cg,t| {
let st = state.clone();
animate(t,cg,st);
});
}
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment