Skip to content

Commit

Permalink
Hook up a stub layout task to the display lister
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed May 3, 2012
1 parent e089607 commit 9a5f88d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 33 deletions.
6 changes: 5 additions & 1 deletion src/servo/input.rs
@@ -1,17 +1,21 @@
fn input(
osmain_ch: comm::chan<osmain::msg>,
draw_ch: comm::chan<gfx::renderer::msg>,
model_ch: comm::chan<layout::lister::msg>
model_ch: comm::chan<layout::lister::msg>,
layout_ch: comm::chan<layout::layout::msg>
) {
task::spawn {||
let key_po = comm::port();
comm::send(osmain_ch, osmain::add_key_handler(comm::chan(key_po)));
loop {
alt comm::recv(key_po) {
_ {
comm::send(layout_ch, layout::layout::exit);
comm::send(model_ch, layout::lister::exit);

let draw_exit_confirm_po = comm::port();
comm::send(draw_ch, gfx::renderer::exit(comm::chan(draw_exit_confirm_po)));

comm::recv(draw_exit_confirm_po);
comm::send(osmain_ch, osmain::exit);
break;
Expand Down
22 changes: 22 additions & 0 deletions src/servo/layout/layout.rs
@@ -0,0 +1,22 @@
import task::*;
import comm::*;

enum msg {
do_layout,
exit
}

fn layout(lister: chan<lister::msg>) -> chan<msg> {
spawn_listener::<msg> {|po|
loop {
alt recv(po) {
do_layout {
send(lister, lister::build)
}
exit {
break;
}
}
}
}
}
67 changes: 36 additions & 31 deletions src/servo/layout/lister.rs
Expand Up @@ -18,7 +18,7 @@ enum msg {

fn lister(renderer: chan<renderer::msg>) -> chan<msg> {

spawn_listener {|po|
spawn_listener::<msg> {|po|
let mut x1 = 100;
let mut y1 = 100;
let mut w1 = 200;
Expand All @@ -28,38 +28,43 @@ fn lister(renderer: chan<renderer::msg>) -> chan<msg> {
let mut w2 = 300;
let mut h2 = 300;

while !peek(po) {
let dlist = [
display_item({
item_type: solid_color,
bounds: geom::box(
int_to_au(x1),
int_to_au(y1),
int_to_au(w1),
int_to_au(h1))
}),
display_item({
item_type: solid_color,
bounds: geom::box(
int_to_au(x2),
int_to_au(y2),
int_to_au(w2),
int_to_au(h2))
})
];
loop {
alt recv(po) {
build {
let dlist = [
display_item({
item_type: solid_color,
bounds: geom::box(
int_to_au(x1),
int_to_au(y1),
int_to_au(w1),
int_to_au(h1))
}),
display_item({
item_type: solid_color,
bounds: geom::box(
int_to_au(x2),
int_to_au(y2),
int_to_au(w2),
int_to_au(h2))
})
];

send(renderer, gfx::renderer::draw(dlist));
send(renderer, gfx::renderer::draw(dlist));

std::timer::sleep(100u);

x1 += 1;
y1 += 1;
x2 -= 1;
y2 -= 1;
if x1 > 800 { x1 = 0 }
if y1 > 600 { y1 = 0 }
if x2 < 0 { x2 = 800 }
if y2 < 0 { y2 = 600 }
x1 += 1;
y1 += 1;
x2 -= 1;
y2 -= 1;
if x1 > 800 { x1 = 0 }
if y1 > 600 { y1 = 0 }
if x2 < 0 { x2 = 800 }
if y2 < 0 { y2 = 600 }
}
exit {
break;
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/servo/servo.rc
Expand Up @@ -31,6 +31,7 @@ mod layout {
mod base;
mod display_list;
mod lister;
mod layout;
}

mod widget {
Expand Down
11 changes: 10 additions & 1 deletion src/servo/servo.rs
@@ -1,3 +1,4 @@
import comm::*;
import libc::c_double;
import azure::*;
import azure::bindgen::*;
Expand All @@ -14,6 +15,14 @@ fn main() {
// The display list builder
let lister = layout::lister::lister(renderer);

// The layout task
let layout = layout::layout::layout(lister);

// The keyboard handler
input::input(osmain_ch, renderer, lister);
input::input(osmain_ch, renderer, lister, layout);

loop {
std::timer::sleep(10u);
send(layout, layout::layout::do_layout);
}
}

0 comments on commit 9a5f88d

Please sign in to comment.