Move drawing code to compositor module

This commit is contained in:
Brian Anderson 2012-04-17 16:05:00 -07:00
parent 897c9dbc07
commit 2d13075f63
3 changed files with 100 additions and 96 deletions

View file

@ -0,0 +1,96 @@
type model = {
x1: int, y1: int, w1: int, h1: int,
x2: int, y2: int, w2: int, h2: int
};
enum msg {
draw(model),
exit(comm::chan<()>)
}
fn compositor(osmain_ch: comm::chan<osmain_msg>) -> comm::chan<msg> {
task::spawn_listener {|po|
let draw_target_po = comm::port();
comm::send(osmain_ch, om_get_draw_target(comm::chan(draw_target_po)));
let draw_target = comm::recv(draw_target_po);
let black_color = {
r: 0f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 1f as azure::AzFloat
};
let black_pattern = AzCreateColorPattern(ptr::addr_of(black_color));
let red_color = {
r: 1f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 0.5f as azure::AzFloat
};
let red_pattern = AzCreateColorPattern(ptr::addr_of(red_color));
let green_color = {
r: 0f as azure::AzFloat,
g: 1f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 0.5f as azure::AzFloat
};
let green_pattern = AzCreateColorPattern(ptr::addr_of(green_color));
let mut exit_confirm_ch = none;
loop {
alt comm::recv::<msg>(po) {
draw(model) {
let black_rect = {
x: 0 as azure::AzFloat,
y: 0 as azure::AzFloat,
width: 800 as azure::AzFloat,
height: 600 as azure::AzFloat,
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(black_rect),
unsafe { unsafe::reinterpret_cast(black_pattern) }
);
let red_rect = {
x: model.x1 as azure::AzFloat,
y: model.y1 as azure::AzFloat,
width: model.w1 as azure::AzFloat,
height: model.h1 as azure::AzFloat
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(red_rect),
unsafe { unsafe::reinterpret_cast(red_pattern) }
);
let green_rect = {
x: model.x2 as azure::AzFloat,
y: model.y2 as azure::AzFloat,
width: model.w2 as azure::AzFloat,
height: model.h2 as azure::AzFloat
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(green_rect),
unsafe { unsafe::reinterpret_cast(green_pattern) }
);
let draw_po = comm::port();
comm::send(osmain_ch, om_draw(comm::chan(draw_po)));
comm::recv(draw_po);
}
exit(response_ch) {
exit_confirm_ch = some(response_ch);
break;
}
}
}
AzReleaseColorPattern(red_pattern);
AzReleaseColorPattern(green_pattern);
assert exit_confirm_ch.is_some();
comm::send(exit_confirm_ch.get(), ());
}
}

View file

@ -18,6 +18,7 @@ mod dom {
mod gfx {
mod geom;
mod surface;
mod compositor;
}
mod image {

View file

@ -33,16 +33,6 @@ enum osmain_msg {
om_exit
}
enum draw_msg {
dm_draw(model),
dm_exit(comm::chan<()>)
}
type model = {
x1: int, y1: int, w1: int, h1: int,
x2: int, y2: int, w2: int, h2: int
};
fn main() {
// The platform event handler thread
let osmain_ch = on_osmain::<osmain_msg> {|po|
@ -119,90 +109,7 @@ fn main() {
};
// The drawing task
let draw_ch = task::spawn_listener {|po|
let draw_target_po = comm::port();
comm::send(osmain_ch, om_get_draw_target(comm::chan(draw_target_po)));
let draw_target = comm::recv(draw_target_po);
let black_color = {
r: 0f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 1f as azure::AzFloat
};
let black_pattern = AzCreateColorPattern(ptr::addr_of(black_color));
let red_color = {
r: 1f as azure::AzFloat,
g: 0f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 0.5f as azure::AzFloat
};
let red_pattern = AzCreateColorPattern(ptr::addr_of(red_color));
let green_color = {
r: 0f as azure::AzFloat,
g: 1f as azure::AzFloat,
b: 0f as azure::AzFloat,
a: 0.5f as azure::AzFloat
};
let green_pattern = AzCreateColorPattern(ptr::addr_of(green_color));
let mut exit_confirm_ch = none;
loop {
alt comm::recv::<draw_msg>(po) {
dm_draw(model) {
let black_rect = {
x: 0 as azure::AzFloat,
y: 0 as azure::AzFloat,
width: 800 as azure::AzFloat,
height: 600 as azure::AzFloat,
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(black_rect),
unsafe { unsafe::reinterpret_cast(black_pattern) }
);
let red_rect = {
x: model.x1 as azure::AzFloat,
y: model.y1 as azure::AzFloat,
width: model.w1 as azure::AzFloat,
height: model.h1 as azure::AzFloat
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(red_rect),
unsafe { unsafe::reinterpret_cast(red_pattern) }
);
let green_rect = {
x: model.x2 as azure::AzFloat,
y: model.y2 as azure::AzFloat,
width: model.w2 as azure::AzFloat,
height: model.h2 as azure::AzFloat
};
AzDrawTargetFillRect(
draw_target,
ptr::addr_of(green_rect),
unsafe { unsafe::reinterpret_cast(green_pattern) }
);
let draw_po = comm::port();
comm::send(osmain_ch, om_draw(comm::chan(draw_po)));
comm::recv(draw_po);
}
dm_exit(response_ch) {
exit_confirm_ch = some(response_ch);
break;
}
}
}
AzReleaseColorPattern(red_pattern);
AzReleaseColorPattern(green_pattern);
assert exit_confirm_ch.is_some();
comm::send(exit_confirm_ch.get(), ());
};
let draw_ch = gfx::compositor::compositor(osmain_ch);
// The model
let model_ch = task::spawn_listener {|po|
@ -220,7 +127,7 @@ fn main() {
x1: x1, y1: y1, w1: w1, h1: h1,
x2: x2, y2: y2, w2: w2, h2: h2
};
comm::send(draw_ch, dm_draw(model));
comm::send(draw_ch, gfx::compositor::draw(model));
sleep();
@ -244,7 +151,7 @@ fn main() {
_ {
comm::send(model_ch, ());
let draw_exit_confirm_po = comm::port();
comm::send(draw_ch, dm_exit(comm::chan(draw_exit_confirm_po)));
comm::send(draw_ch, gfx::compositor::exit(comm::chan(draw_exit_confirm_po)));
comm::recv(draw_exit_confirm_po);
comm::send(osmain_ch, om_exit);
break;