Skip to content

Commit

Permalink
Added rgba to Context
Browse files Browse the repository at this point in the history
  • Loading branch information
bvssvni committed Apr 24, 2014
1 parent 098488a commit 4d9631c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 19 additions & 1 deletion src/context.rs
Expand Up @@ -2,7 +2,7 @@
use {Field, Borrowed, Value};
use vecmath::{rotate_radians, multiply, translate, scale, shear};
use {Transform2d, Matrix2d};
use rectangle_context::RectangleContext;
use {ColorContext, RectangleContext};

/// Drawing 2d context.
pub struct Context<'a> {
Expand Down Expand Up @@ -70,13 +70,24 @@ impl<'a> Context<'a> {
}

/// Creates a rectangle context.
#[inline(always)]
pub fn rect(&'a self, x: f64, y: f64, w: f64, h: f64) -> RectangleContext<'a> {
RectangleContext {
base: Borrowed(self.base.get()),
transform: Borrowed(self.transform.get()),
rect: Value([x, y, w, h]),
}
}

/// Creates a color context.
#[inline(always)]
pub fn rgba(&'a self, r: f64, g: f64, b: f64, a: f64) -> ColorContext<'a> {
ColorContext {
base: Borrowed(self.base.get()),
transform: Borrowed(self.transform.get()),
color: Value([r, g, b, a]),
}
}
}

#[test]
Expand Down Expand Up @@ -110,3 +121,10 @@ fn test_rect() {
let d = c.rect(0.0, 0.0, 100.0, 50.0);
assert_eq!(d.rect.get()[2], 100.0);
}

#[test]
fn test_color() {
let c = Context::new();
let d = c.rgba(1.0, 0.0, 0.0, 1.0);
assert_eq!(d.color.get()[0], 1.0);
}
10 changes: 5 additions & 5 deletions src/lib.rs
Expand Up @@ -4,11 +4,11 @@
//! Attempt of creating a cheap drawing context.

pub use context::Context;
pub use back_end::BackEnd;
pub use transform2d::Transform2d;
pub use color_context::ColorContext;
pub use rectangle_context::RectangleContext;
pub use rectangle_color_context::RectangleColorContext;
pub use BackEnd = back_end::BackEnd;
pub use Transform2d = transform2d::Transform2d;
pub use ColorContext = color_context::ColorContext;
pub use RectangleContext = rectangle_context::RectangleContext;
pub use RectangleColorContext = rectangle_color_context::RectangleColorContext;

mod context;
mod back_end;
Expand Down

0 comments on commit 4d9631c

Please sign in to comment.