pub struct Canvas2dContext {
pub surface: Surface,
pub path: PathBuilder,
pub state: DrawState,
stack: Vec<DrawState>,
}Expand description
1 つの <canvas> に対する 2D コンテキストの全状態。
JS 側のオブジェクトは軽いハンドルだけを持ち、実体はこれを指す。 パスと面はどちらもここに持たせて、描画の途中経過が JS オブジェクトの寿命に左右されないようにする。
Fields§
§surface: Surface§path: PathBuilder§state: DrawState§stack: Vec<DrawState>save() の退避スタック。
Implementations§
Source§impl Canvas2dContext
impl Canvas2dContext
pub fn new(width: u32, height: u32) -> Option<Self>
Sourcepub fn apply_alpha(&self, argb: u32) -> u32
pub fn apply_alpha(&self, argb: u32) -> u32
globalAlpha を適用した色を返す。
アルファは掛け算で合成する。globalAlpha=0.5 の半透明色は
さらに薄くなる(仕様どおり)。
Sourcepub fn fill_rect(&mut self, x: f32, y: f32, w: f32, h: f32)
pub fn fill_rect(&mut self, x: f32, y: f32, w: f32, h: f32)
現在の変換を適用して矩形を塗る。
変換が平行移動と拡大だけなら矩形のまま塗れるが、回転が入ると 軸平行でなくなる。判定を分けず、常にパス経由で塗ることで 回転時も正しくなるようにしている。
Sourcepub fn clear_rect(&mut self, x: f32, y: f32, w: f32, h: f32)
pub fn clear_rect(&mut self, x: f32, y: f32, w: f32, h: f32)
矩形を透明で消す。globalAlpha の影響は受けない(仕様どおり)。
回転が入っていると軸平行に消せないため、パスの外接矩形を消す。
厳密ではないが、clearRect に回転を掛ける使い方は稀。
Sourcepub fn set_transform(&mut self, m: Matrix)
pub fn set_transform(&mut self, m: Matrix)
変換行列を直接置き換える(setTransform)。
Sourcepub fn reset_transform(&mut self)
pub fn reset_transform(&mut self)
変換を単位行列へ戻す(resetTransform)。
Source§impl Canvas2dContext
impl Canvas2dContext
Sourcepub fn stroke_with_width(&mut self)
pub fn stroke_with_width(&mut self)
現在のパスを、lineWidth を反映して線描する。
Source§impl Canvas2dContext
impl Canvas2dContext
Sourcepub fn apply_dash(&self, subpaths: &[SubPath]) -> Vec<SubPath>
pub fn apply_dash(&self, subpaths: &[SubPath]) -> Vec<SubPath>
現在の破線設定をパスへ適用する。実線ならそのまま返す。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Canvas2dContext
impl RefUnwindSafe for Canvas2dContext
impl Send for Canvas2dContext
impl Sync for Canvas2dContext
impl Unpin for Canvas2dContext
impl UnsafeUnpin for Canvas2dContext
impl UnwindSafe for Canvas2dContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more