[oden] Colors

But they don't work
This commit is contained in:
John Doty 2023-08-26 08:58:00 -07:00
parent db0f22b1db
commit 106db89e9b
5 changed files with 77 additions and 24 deletions

View file

@ -22,11 +22,20 @@ pub struct CreateTextureCommand {
pub label: Option<String>,
}
#[derive(Debug)]
pub struct CircleCommand {
pub center: [f32; 2],
pub radius: f32,
pub stroke_width: f32,
}
#[derive(Debug)]
pub enum GraphicsCommand {
Clear(ClearCommand),
FillColor([f32; 4]),
StrokeColor([f32; 4]),
Print(PrintCommand),
Circle(crate::CircleInstance),
Circle(CircleCommand),
Sprite(crate::SpriteInstance),
CreateTexture(CreateTextureCommand),
CreateWritableTexture {
@ -66,6 +75,14 @@ impl GraphicsImpl {
}));
}
fn color(&self, r: f32, g: f32, b: f32, a: f32) -> () {
let _ = self.sender.send(GraphicsCommand::FillColor([r, g, b, a]));
}
fn stroke(&self, r: f32, g: f32, b: f32, a: f32) -> () {
let _ = self.sender.send(GraphicsCommand::StrokeColor([r, g, b, a]));
}
fn spr(&self, x: f32, y: f32, w: f32, h: f32, u: f32, v: f32, sw: f32, sh: f32) {
let _ = self
.sender
@ -78,15 +95,11 @@ impl GraphicsImpl {
}
fn circle(&self, x: f32, y: f32, r: f32, s: f32) {
let _ = self
.sender
.send(GraphicsCommand::Circle(crate::CircleInstance {
center: [x, y],
radius: r,
stroke_width: s,
stroke_color: [1.0, 0.0, 0.0, 1.0],
fill_color: [1.0, 1.0, 1.0, 1.0],
}));
let _ = self.sender.send(GraphicsCommand::Circle(CircleCommand {
center: [x, y],
radius: r,
stroke_width: s,
}));
}
fn create_texture(
@ -165,6 +178,24 @@ impl GraphicsAPI {
ctx.new_fn(move |_: &ContextRef, r: f64, g: f64, b: f64| gfx.cls(r, g, b))?,
)?;
}
{
let gfx = gfx.clone();
builder.export(
"color",
ctx.new_fn(move |_: &ContextRef, r: f32, g: f32, b: f32, a: f32| {
gfx.color(r, g, b, a)
})?,
)?;
}
{
let gfx = gfx.clone();
builder.export(
"stroke",
ctx.new_fn(move |_: &ContextRef, r: f32, g: f32, b: f32, a: f32| {
gfx.stroke(r, g, b, a)
})?,
)?;
}
{
let gfx = gfx.clone();
builder.export(