| 1 | use skia_bindings::{self as sb, C_SkTiledImageUtils_DrawImageRect}; |
| 2 | |
| 3 | use crate::{canvas, prelude::*, scalar, Canvas, Image, Paint, Point, Rect, SamplingOptions}; |
| 4 | |
| 5 | pub fn draw_image_rect( |
| 6 | canvas: &Canvas, |
| 7 | image: &Image, |
| 8 | src: impl AsRef<Rect>, |
| 9 | dst: impl AsRef<Rect>, |
| 10 | sampling: Option<SamplingOptions>, |
| 11 | paint: Option<&Paint>, |
| 12 | constraint: impl Into<Option<canvas::SrcRectConstraint>>, |
| 13 | ) { |
| 14 | let sampling: SamplingOptions = sampling.unwrap_or_default(); |
| 15 | let constraint: SkCanvas_SrcRectConstraint = constraint.into().unwrap_or(canvas::SrcRectConstraint::Fast); |
| 16 | unsafe { |
| 17 | C_SkTiledImageUtils_DrawImageRect( |
| 18 | canvas.native_mut(), |
| 19 | image.native(), |
| 20 | src.as_ref().native(), |
| 21 | dst.as_ref().native(), |
| 22 | sampling.native(), |
| 23 | paint.native_ptr_or_null(), |
| 24 | constraint, |
| 25 | ) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | pub fn draw_image( |
| 30 | canvas: &Canvas, |
| 31 | image: &Image, |
| 32 | xy: impl Into<Point>, |
| 33 | sampling: Option<SamplingOptions>, |
| 34 | paint: Option<&Paint>, |
| 35 | constraint: impl Into<Option<canvas::SrcRectConstraint>>, |
| 36 | ) { |
| 37 | let p = xy.into(); |
| 38 | let src: Rect = Rect::from_iwh(w:image.width(), h:image.height()); |
| 39 | let dst: Rect = Rect::from_xywh(p.x, p.y, w:image.width() as scalar, h:image.height() as scalar); |
| 40 | |
| 41 | draw_image_rect(canvas, image, src, dst, sampling, paint, constraint) |
| 42 | } |
| 43 | |
| 44 | pub const NUM_IMAGE_KEY_VALUES: usize = 6; |
| 45 | |
| 46 | pub fn get_image_key_values(image: &Image) -> [u32; NUM_IMAGE_KEY_VALUES] { |
| 47 | let mut key_values: [u32; 6] = [0u32; NUM_IMAGE_KEY_VALUES]; |
| 48 | unsafe { sb::C_SkTiledImageUtils_GetImageKeyValues(image.native(), keyValues:key_values.as_mut_ptr()) } |
| 49 | key_values |
| 50 | } |
| 51 | |