use capi::scgraphics::{HTEXT, HIMG, HPATH};
use capi::scgraphics::{SC_ANGLE, SC_COLOR, SC_COLOR_STOP, SC_DIM, SC_POS};
use capi::sctypes::{BOOL, LPCBYTE, LPVOID, POINT, SIZE, UINT};
use std::ptr::{null_mut, null};
use value::{FromValue, Value};
use dom::Element;
use _GAPI;
pub use capi::scgraphics::{HGFX, GRAPHIN_RESULT};
pub use capi::scgraphics::{DRAW_PATH, LINE_CAP, LINE_JOIN};
#[derive(Clone, Copy)]
#[derive(Debug, PartialEq)]
pub enum SaveImageEncoding {
Raw,
Png,
Jpeg(u8),
Webp(u8),
}
macro_rules! ok_or {
($rv:expr, $ok:ident) => {
if $ok == GRAPHIN_RESULT::OK {
Ok($rv)
} else {
Err($ok)
}
};
}
pub type Result<T> = ::std::result::Result<T, GRAPHIN_RESULT>;
pub type Color = SC_COLOR;
pub type Pos = (SC_POS, SC_POS);
pub type Size = (SC_DIM, SC_DIM);
pub type Angle = SC_ANGLE;
pub type Dim = SC_DIM;
pub fn rgb(red: u8, green: u8, blue: u8) -> Color {
(_GAPI.RGBA)(u32::from(red), u32::from(green), u32::from(blue), 255)
}
pub fn rgba((r, g, b): (u8, u8, u8), opacity: u8) -> Color {
let color = rgb(r, g, b);
u32::from(opacity) | color << 24
}
#[derive(Debug, Default)]
pub struct TextMetrics {
pub min_width: Dim,
pub max_width: Dim,
pub height: Dim,
pub ascent: Dim,
pub descent: Dim,
pub lines: u32,
}
pub struct Text(HTEXT);
impl Drop for Text {
fn drop(&mut self) {
(_GAPI.textRelease)(self.0);
}
}
impl Clone for Text {
fn clone(&self) -> Self {
let dst = Text(self.0);
(_GAPI.textAddRef)(dst.0);
dst
}
}
impl FromValue for Text {
fn from_value(v: &Value) -> Option<Text> {
let mut h = null_mut();
let ok = (_GAPI.vUnWrapText)(v.as_cptr(), &mut h);
if ok == GRAPHIN_RESULT::OK {
(_GAPI.textAddRef)(h);
Some(Text(h))
} else {
None
}
}
}
impl From<Text> for Value {
fn from(i: Text) -> Value {
let mut v = Value::new();
let ok = (_GAPI.vWrapText)(i.0, v.as_ptr());
assert!(ok == GRAPHIN_RESULT::OK);
v
}
}
impl Text {
pub fn create(e: &Element, text: &str) -> Result<Text> {
let (t, tn) = s2wn!(text);
let mut h = null_mut();
let ok = (_GAPI.textCreateForElement)(&mut h, t.as_ptr(), tn, e.as_ptr(), null());
ok_or!(Text(h), ok)
}
pub fn with_class(e: &Element, text: &str, class: &str) -> Result<Text> {
let (t, tn) = s2wn!(text);
let (c, _cn) = s2wn!(class);
let mut h = null_mut();
let ok = (_GAPI.textCreateForElement)(&mut h, t.as_ptr(), tn, e.as_ptr(), c.as_ptr() );
ok_or!(Text(h), ok)
}
pub fn with_style(e: &Element, text: &str, styles: &str) -> Result<Text> {
let (t, tn) = s2wn!(text);
let (s, sn) = s2wn!(styles);
let mut h = null_mut();
let ok = (_GAPI.textCreateForElementAndStyle)(&mut h, t.as_ptr(), tn, e.as_ptr(), s.as_ptr(), sn);
ok_or!(Text(h), ok)
}
pub fn set_box(&mut self, size: Size) -> Result<()> {
let ok = (_GAPI.textSetBox)(self.0, size.0, size.1);
ok_or!((), ok)
}
pub fn get_metrics(&self) -> Result<TextMetrics> {
let mut tm = TextMetrics::default();
let ok = (_GAPI.textGetMetrics)(self.0,
&mut tm.min_width, &mut tm.max_width,
&mut tm.height,
&mut tm.ascent, &mut tm.descent,
&mut tm.lines,
);
ok_or!(tm, ok)
}
}
pub struct Image(HIMG);
impl Drop for Image {
fn drop(&mut self) {
(_GAPI.imageRelease)(self.0);
}
}
impl Clone for Image {
fn clone(&self) -> Self {
let dst = Image(self.0);
(_GAPI.imageAddRef)(dst.0);
dst
}
}
impl FromValue for Image {
fn from_value(v: &Value) -> Option<Image> {
let mut h = null_mut();
let ok = (_GAPI.vUnWrapImage)(v.as_cptr(), &mut h);
if ok == GRAPHIN_RESULT::OK {
(_GAPI.imageAddRef)(h);
Some(Image(h))
} else {
None
}
}
}
impl From<Image> for Value {
fn from(i: Image) -> Value {
let mut v = Value::new();
let ok = (_GAPI.vWrapImage)(i.0, v.as_ptr());
assert!(ok == GRAPHIN_RESULT::OK);
v
}
}
impl Image {
pub fn create((width, height): (u32, u32), with_alpha: bool) -> Result<Image> {
let mut h = null_mut();
let ok = (_GAPI.imageCreate)(&mut h, width, height, with_alpha as BOOL);
ok_or!(Image(h), ok)
}
#[deprecated(note="Use `Image::create` instead.")]
pub fn new((width, height): (u32, u32), with_alpha: bool) -> Result<Image> {
Self::create((width, height), with_alpha)
}
pub fn with_data((width, height): (u32, u32), with_alpha: bool, pixmap: &[u8]) -> Result<Image> {
let mut h = null_mut();
let ok = (_GAPI.imageCreateFromPixmap)(&mut h, width, height, with_alpha as BOOL, pixmap.as_ptr());
ok_or!(Image(h), ok)
}
pub fn load(image_data: &[u8]) -> Result<Image> {
let mut h = null_mut();
let ok = (_GAPI.imageLoad)(image_data.as_ptr(), image_data.len() as UINT, &mut h);
ok_or!(Image(h), ok)
}
pub fn save(&self, encoding: SaveImageEncoding) -> Result<Vec<u8>> {
extern "system" fn on_save(prm: LPVOID, data: LPCBYTE, data_length: UINT) {
assert!(!prm.is_null());
assert!(!data.is_null());
unsafe {
let param = prm as *mut Vec<u8>;
let dst = &mut *param;
let src = ::std::slice::from_raw_parts(data, data_length as usize);
dst.extend_from_slice(src);
}
}
use capi::scgraphics::IMAGE_ENCODING::*;
let (enc, q) = match encoding {
SaveImageEncoding::Raw => (RAW, 0),
SaveImageEncoding::Png => (PNG, 0),
SaveImageEncoding::Jpeg(q) => (JPG, q),
SaveImageEncoding::Webp(q) => (WEBP, q),
};
let mut data = Vec::new();
let ok = (_GAPI.imageSave)(self.0, on_save, &mut data as *mut _ as LPVOID, enc, u32::from(q));
ok_or!(data, ok)
}
pub fn paint<PaintFn>(&mut self, painter: PaintFn) -> Result<()>
where
PaintFn: Fn(&mut Graphics, (f32, f32)) -> Result<()>,
{
#[repr(C)]
struct Payload<PaintFn> {
painter: PaintFn,
result: Result<()>,
}
extern "system" fn on_paint<PaintFn: Fn(&mut Graphics, (f32, f32)) -> Result<()>>(prm: LPVOID, hgfx: HGFX, width: UINT, height: UINT) {
let param = prm as *mut Payload<PaintFn>;
assert!(!param.is_null());
assert!(!hgfx.is_null());
let payload = unsafe { &mut *param };
let ok = if !hgfx.is_null() {
let mut gfx = Graphics::from(hgfx);
(payload.painter)(&mut gfx, (width as f32, height as f32))
} else {
Err(GRAPHIN_RESULT::BAD_PARAM)
};
payload.result = ok;
}
let payload = Payload {
painter: painter,
result: Ok(()),
};
let param = Box::new(payload);
let param = Box::into_raw(param);
let ok = (_GAPI.imagePaint)(self.0, on_paint::<PaintFn>, param as LPVOID);
let ok = ok_or!((), ok);
let param = unsafe { Box::from_raw(param) };
ok.and(param.result)
}
pub fn dimensions(&self) -> Result<(u32, u32)> {
let mut alpha = 0;
let mut w = 0;
let mut h = 0;
let ok = (_GAPI.imageGetInfo)(self.0, &mut w, &mut h, &mut alpha);
ok_or!((w, h), ok)
}
pub fn clear(&mut self) -> Result<()> {
let ok = (_GAPI.imageClear)(self.0, Graphics::NO_COLOR);
ok_or!((), ok)
}
pub fn clear_with(&mut self, color: Color) -> Result<()> {
let ok = (_GAPI.imageClear)(self.0, color);
ok_or!((), ok)
}
}
pub struct Path(HPATH);
impl Drop for Path {
fn drop(&mut self) {
(_GAPI.pathRelease)(self.0);
}
}
impl Clone for Path {
fn clone(&self) -> Self {
let dst = Path(self.0);
(_GAPI.pathAddRef)(dst.0);
dst
}
}
impl FromValue for Path {
fn from_value(v: &Value) -> Option<Path> {
let mut h = null_mut();
let ok = (_GAPI.vUnWrapPath)(v.as_cptr(), &mut h);
if ok == GRAPHIN_RESULT::OK {
(_GAPI.pathAddRef)(h);
Some(Path(h))
} else {
None
}
}
}
impl From<Path> for Value {
fn from(i: Path) -> Value {
let mut v = Value::new();
let ok = (_GAPI.vWrapPath)(i.0, v.as_ptr());
assert!(ok == GRAPHIN_RESULT::OK);
v
}
}
impl Path {
pub fn create() -> Result<Path> {
let mut h = null_mut();
let ok = (_GAPI.pathCreate)(&mut h);
ok_or!(Path(h), ok)
}
#[deprecated(note="Use `Path::create()` instead.")]
pub fn new() -> Result<Path> {
Self::create()
}
pub fn close(&mut self) -> Result<()> {
let ok = (_GAPI.pathClosePath)(self.0);
ok_or!((), ok)
}
pub fn move_to(&mut self, point: Pos, is_relative: bool) -> Result<&mut Path> {
let ok = (_GAPI.pathMoveTo)(self.0, point.0, point.1, is_relative as BOOL);
ok_or!(self, ok)
}
pub fn line_to(&mut self, point: Pos, is_relative: bool) -> Result<&mut Path> {
let ok = (_GAPI.pathLineTo)(self.0, point.0, point.1, is_relative as BOOL);
ok_or!(self, ok)
}
pub fn arc_to(&mut self, xy: Pos, angle: Angle, rxy: Pos, is_large: bool, is_clockwise: bool, is_relative: bool) -> Result<&mut Path> {
let ok = (_GAPI.pathArcTo)(
self.0,
xy.0,
xy.1,
angle,
rxy.0,
rxy.1,
is_large as BOOL,
is_clockwise as BOOL,
is_relative as BOOL,
);
ok_or!(self, ok)
}
pub fn quadratic_curve_to(&mut self, control: Pos, end: Pos, is_relative: bool) -> Result<&mut Path> {
let ok = (_GAPI.pathQuadraticCurveTo)(self.0, control.0, control.1, end.0, end.1, is_relative as BOOL);
ok_or!(self, ok)
}
pub fn bezier_curve_to(&mut self, control1: Pos, control2: Pos, end: Pos, is_relative: bool) -> Result<&mut Path> {
let ok = (_GAPI.pathBezierCurveTo)(
self.0,
control1.0,
control1.1,
control2.0,
control2.1,
end.0,
end.1,
is_relative as BOOL,
);
ok_or!(self, ok)
}
}
pub struct State<'a>(&'a mut Graphics);
impl<'a> Drop for State<'a> {
fn drop(&mut self) {
self.0.pop_state().ok();
}
}
impl<'a> ::std::ops::Deref for State<'a> {
type Target = Graphics;
fn deref(&self) -> &Graphics {
self.0
}
}
impl<'a> ::std::ops::DerefMut for State<'a> {
fn deref_mut(&mut self) -> &mut Graphics {
self.0
}
}
pub struct Graphics(HGFX);
impl Drop for Graphics {
fn drop(&mut self) {
(_GAPI.gRelease)(self.0);
}
}
impl Clone for Graphics {
fn clone(&self) -> Self {
let dst = Graphics(self.0);
(_GAPI.gAddRef)(dst.0);
dst
}
}
impl FromValue for Graphics {
fn from_value(v: &Value) -> Option<Graphics> {
let mut h = null_mut();
let ok = (_GAPI.vUnWrapGfx)(v.as_cptr(), &mut h);
if ok == GRAPHIN_RESULT::OK {
(_GAPI.gAddRef)(h);
Some(Graphics(h))
} else {
None
}
}
}
impl From<Graphics> for Value {
fn from(i: Graphics) -> Value {
let mut v = Value::new();
let ok = (_GAPI.vWrapGfx)(i.0, v.as_ptr());
assert!(ok == GRAPHIN_RESULT::OK);
v
}
}
impl From<HGFX> for Graphics {
fn from(hgfx: HGFX) -> Graphics {
assert!(!hgfx.is_null());
(_GAPI.gAddRef)(hgfx);
Graphics(hgfx)
}
}
impl Graphics {
pub fn save_state(&mut self) -> Result<State> {
self.push_state().map(|gfx| State(gfx))
}
fn push_state(&mut self) -> Result<&mut Self> {
let ok = (_GAPI.gStateSave)(self.0);
ok_or!(self, ok)
}
fn pop_state(&mut self) -> Result<&mut Self> {
let ok = (_GAPI.gStateRestore)(self.0);
ok_or!(self, ok)
}
pub fn flush(&mut self) -> Result<&mut Self> {
let ok = (_GAPI.gFlush)(self.0);
ok_or!(self, ok)
}
}
impl Graphics {
pub fn line(&mut self, start: Pos, end: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gLine)(self.0, start.0, start.1, end.0, end.1);
ok_or!(self, ok)
}
pub fn rectangle(&mut self, left_top: Pos, right_bottom: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gRectangle)(self.0, left_top.0, left_top.1, right_bottom.0, right_bottom.1);
ok_or!(self, ok)
}
pub fn round_rect(&mut self, left_top: Pos, right_bottom: Pos, radius: Dim) -> Result<&mut Self> {
let rad: [Dim; 8] = [radius; 8usize];
let ok = (_GAPI.gRoundedRectangle)(self.0, left_top.0, left_top.1, right_bottom.0, right_bottom.1, rad.as_ptr());
ok_or!(self, ok)
}
pub fn round_rect4(&mut self, left_top: Pos, right_bottom: Pos, radius: (Dim, Dim, Dim, Dim)) -> Result<&mut Self> {
let r = radius;
let rad: [Dim; 8] = [r.0, r.0, r.1, r.1, r.2, r.2, r.3, r.3];
let ok = (_GAPI.gRoundedRectangle)(self.0, left_top.0, left_top.1, right_bottom.0, right_bottom.1, rad.as_ptr());
ok_or!(self, ok)
}
pub fn ellipse(&mut self, xy: Pos, radii: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gEllipse)(self.0, xy.0, xy.1, radii.0, radii.1);
ok_or!(self, ok)
}
pub fn circle(&mut self, xy: Pos, radius: Dim) -> Result<&mut Self> {
let ok = (_GAPI.gEllipse)(self.0, xy.0, xy.1, radius, radius);
ok_or!(self, ok)
}
pub fn arc(&mut self, xy: Pos, rxy: Pos, start: Angle, sweep: Angle) -> Result<&mut Self> {
let ok = (_GAPI.gArc)(self.0, xy.0, xy.1, rxy.0, rxy.1, start, sweep);
ok_or!(self, ok)
}
pub fn star(&mut self, xy: Pos, r1: Dim, r2: Dim, start: Angle, rays: usize) -> Result<&mut Self> {
let ok = (_GAPI.gStar)(self.0, xy.0, xy.1, r1, r2, start, rays as UINT);
ok_or!(self, ok)
}
pub fn polygon(&mut self, points: &[Pos]) -> Result<&mut Self> {
type PosArray = [Pos; 2];
type FloatArray = [SC_POS; 4];
let _ = ::std::mem::transmute::<FloatArray, PosArray>;
let ok = (_GAPI.gPolygon)(self.0, points.as_ptr() as *const SC_POS, points.len() as UINT);
ok_or!(self, ok)
}
pub fn polyline(&mut self, points: &[Pos]) -> Result<&mut Self> {
type PosArray = [Pos; 2];
type FloatArray = [SC_POS; 4];
let _ = ::std::mem::transmute::<FloatArray, PosArray>;
let ok = (_GAPI.gPolyline)(self.0, points.as_ptr() as *const SC_POS, points.len() as UINT);
ok_or!(self, ok)
}
}
impl Graphics {
const NO_COLOR: Color = 0;
pub fn fill_color(&mut self, color: Color) -> Result<&mut Self> {
let ok = (_GAPI.gFillColor)(self.0, color);
ok_or!(self, ok)
}
pub fn fill_mode(&mut self, is_even: bool) -> Result<&mut Self> {
let ok = (_GAPI.gFillMode)(self.0, is_even as BOOL);
ok_or!(self, ok)
}
pub fn no_fill(&mut self) -> Result<&mut Self> {
self.fill_color(Self::NO_COLOR)
}
pub fn line_color(&mut self, color: Color) -> Result<&mut Self> {
let ok = (_GAPI.gLineColor)(self.0, color);
ok_or!(self, ok)
}
pub fn line_width(&mut self, width: Dim) -> Result<&mut Self> {
let ok = (_GAPI.gLineWidth)(self.0, width);
ok_or!(self, ok)
}
pub fn line_cap(&mut self, style: LINE_CAP) -> Result<&mut Self> {
let ok = (_GAPI.gLineCap)(self.0, style);
ok_or!(self, ok)
}
pub fn line_join(&mut self, style: LINE_JOIN) -> Result<&mut Self> {
let ok = (_GAPI.gLineJoin)(self.0, style);
ok_or!(self, ok)
}
pub fn no_line(&mut self) -> Result<&mut Self> {
self.line_width(0.0)
}
pub fn line_linear_gradient(&mut self, start: Pos, end: Pos, c1: Color, c2: Color) -> Result<&mut Self> {
let stops = [(c1, 0.0), (c2, 1.0)];
self.line_linear_gradients(start, end, &stops)
}
pub fn line_linear_gradients(&mut self, start: Pos, end: Pos, colors: &[(Color, Dim)]) -> Result<&mut Self> {
let _ = ::std::mem::transmute::<SC_COLOR_STOP, (Color, Dim)>;
let ok = (_GAPI.gLineGradientLinear)(
self.0,
start.0,
start.1,
end.0,
end.1,
colors.as_ptr() as *const SC_COLOR_STOP,
colors.len() as UINT,
);
ok_or!(self, ok)
}
pub fn fill_linear_gradient(&mut self, c1: Color, c2: Color, start: Pos, end: Pos) -> Result<&mut Self> {
let stops = [(c1, 0.0), (c2, 1.0)];
self.fill_linear_gradients(&stops, start, end)
}
pub fn fill_linear_gradients(&mut self, colors: &[(Color, Dim)], start: Pos, end: Pos) -> Result<&mut Self> {
let _ = ::std::mem::transmute::<SC_COLOR_STOP, (Color, Dim)>;
let ok = (_GAPI.gFillGradientLinear)(
self.0,
start.0,
start.1,
end.0,
end.1,
colors.as_ptr() as *const SC_COLOR_STOP,
colors.len() as UINT,
);
ok_or!(self, ok)
}
pub fn line_radial_gradient(&mut self, point: Pos, radii: (Dim, Dim), c1: Color, c2: Color) -> Result<&mut Self> {
let stops = [(c1, 0.0), (c2, 1.0)];
self.line_radial_gradients(point, radii, &stops)
}
pub fn line_radial_gradients(&mut self, point: Pos, radii: (Dim, Dim), colors: &[(Color, Dim)]) -> Result<&mut Self> {
let _ = ::std::mem::transmute::<SC_COLOR_STOP, (Color, Dim)>;
let ok = (_GAPI.gLineGradientRadial)(
self.0,
point.0,
point.1,
radii.0,
radii.1,
colors.as_ptr() as *const SC_COLOR_STOP,
colors.len() as UINT,
);
ok_or!(self, ok)
}
pub fn fill_radial_gradient(&mut self, c1: Color, c2: Color, point: Pos, radii: (Dim, Dim)) -> Result<&mut Self> {
let stops = [(c1, 0.0), (c2, 1.0)];
self.fill_radial_gradients(&stops, point, radii)
}
pub fn fill_radial_gradients(&mut self, colors: &[(Color, Dim)], point: Pos, radii: (Dim, Dim)) -> Result<&mut Self> {
let _ = ::std::mem::transmute::<SC_COLOR_STOP, (Color, Dim)>;
let ok = (_GAPI.gFillGradientRadial)(
self.0,
point.0,
point.1,
radii.0,
radii.1,
colors.as_ptr() as *const SC_COLOR_STOP,
colors.len() as UINT,
);
ok_or!(self, ok)
}
}
impl Graphics {
pub fn rotate(&mut self, radians: Angle) -> Result<&mut Self> {
let ok = (_GAPI.gRotate)(self.0, radians, None, None);
ok_or!(self, ok)
}
pub fn rotate_around(&mut self, radians: Angle, center: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gRotate)(self.0, radians, Some(¢er.0), Some(¢er.1));
ok_or!(self, ok)
}
pub fn translate(&mut self, to_xy: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gTranslate)(self.0, to_xy.0, to_xy.1);
ok_or!(self, ok)
}
pub fn scale(&mut self, sc_xy: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gScale)(self.0, sc_xy.0, sc_xy.1);
ok_or!(self, ok)
}
pub fn skew(&mut self, sh_xy: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gSkew)(self.0, sh_xy.0, sh_xy.1);
ok_or!(self, ok)
}
pub fn transform(&mut self, scale_by: Pos, skew_by: Pos, move_to: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gTransform)(self.0, scale_by.0, skew_by.0, skew_by.1, scale_by.0, move_to.0, move_to.1);
ok_or!(self, ok)
}
pub fn transform_matrix(&mut self, m11: Dim, m12: Dim, m21: Dim, m22: Dim, dx: Dim, dy: Dim) -> Result<&mut Self> {
self.transform((m11, m22), (m12, m21), (dx, dy))
}
}
impl Graphics {
pub fn world_to_screen(&self, mut xy: Pos) -> Result<Pos> {
let ok = (_GAPI.gWorldToScreen)(self.0, &mut xy.0, &mut xy.1);
ok_or!(xy, ok)
}
pub fn world_to_screen1(&self, mut length: Dim) -> Result<Dim> {
let mut dummy = 0.0;
let ok = (_GAPI.gWorldToScreen)(self.0, &mut length, &mut dummy);
ok_or!(length, ok)
}
pub fn screen_to_world(&self, mut xy: Pos) -> Result<Pos> {
let ok = (_GAPI.gScreenToWorld)(self.0, &mut xy.0, &mut xy.1);
ok_or!(xy, ok)
}
pub fn screen_to_world1(&self, mut length: Dim) -> Result<Dim> {
let mut dummy = 0.0;
let ok = (_GAPI.gScreenToWorld)(self.0, &mut length, &mut dummy);
ok_or!(length, ok)
}
}
impl Graphics {
pub fn push_clip_box(&mut self, left_top: Pos, right_bottom: Pos, opacity: Option<f32>) -> Result<&mut Self> {
let ok = (_GAPI.gPushClipBox)(
self.0,
left_top.0,
left_top.1,
right_bottom.0,
right_bottom.1,
opacity.unwrap_or(1.0),
);
ok_or!(self, ok)
}
pub fn push_clip_path(&mut self, path: &Path, opacity: Option<f32>) -> Result<&mut Self> {
let ok = (_GAPI.gPushClipPath)(self.0, path.0, opacity.unwrap_or(1.0));
ok_or!(self, ok)
}
pub fn pop_clip(&mut self) -> Result<&mut Self> {
let ok = (_GAPI.gPopClip)(self.0);
ok_or!(self, ok)
}
}
impl Graphics {
pub fn draw_text(&mut self, text: &Text, pos: Pos, point_of: u32) -> Result<&mut Self> {
let ok = (_GAPI.gDrawText)(self.0, text.0, pos.0, pos.1, point_of);
ok_or!(self, ok)
}
pub fn draw_path(&mut self, path: &Path, mode: DRAW_PATH) -> Result<&mut Self> {
let ok = (_GAPI.gDrawPath)(self.0, path.0, mode);
ok_or!(self, ok)
}
pub fn draw_image(&mut self, image: &Image, pos: Pos) -> Result<&mut Self> {
let ok = (_GAPI.gDrawImage)(self.0, image.0, pos.0, pos.1, None, None, None, None, None, None, None);
ok_or!(self, ok)
}
pub fn draw_image_part(&mut self, image: &Image, dst_pos: Pos, dst_size: Size, src_pos: POINT, src_size: SIZE) -> Result<&mut Self> {
let ix = src_pos.x as UINT;
let iy = src_pos.y as UINT;
let iw = src_size.cx as UINT;
let ih = src_size.cy as UINT;
let ok = (_GAPI.gDrawImage)(
self.0,
image.0,
dst_pos.0,
dst_pos.1,
Some(&dst_size.0),
Some(&dst_size.1),
Some(&ix),
Some(&iy),
Some(&iw),
Some(&ih),
None,
);
ok_or!(self, ok)
}
pub fn blend_image(&mut self, image: &Image, dst_pos: Pos, opacity: f32) -> Result<&mut Self> {
let ok = (_GAPI.gDrawImage)(
self.0,
image.0,
dst_pos.0,
dst_pos.1,
None,
None,
None,
None,
None,
None,
Some(&opacity),
);
ok_or!(self, ok)
}
pub fn blend_image_part(&mut self, image: &Image, dst_pos: Pos, opacity: f32, src_pos: POINT, src_size: SIZE) -> Result<&mut Self> {
let ix = src_pos.x as UINT;
let iy = src_pos.y as UINT;
let iw = src_size.cx as UINT;
let ih = src_size.cy as UINT;
let ok = (_GAPI.gDrawImage)(
self.0,
image.0,
dst_pos.0,
dst_pos.1,
None,
None,
Some(&ix),
Some(&iy),
Some(&iw),
Some(&ih),
Some(&opacity),
);
ok_or!(self, ok)
}
}