cogl/auto/
atlas_texture.rs1use crate::{Bitmap, Context, Object, PixelFormat};
2
3use glib::translate::*;
4use std::{fmt, ptr};
5
6glib_wrapper! {
7 pub struct AtlasTexture(Object<ffi::CoglAtlasTexture, AtlasTextureClass>) @extends Object;
8
9 match fn {
10 get_type => || ffi::cogl_atlas_texture_get_gtype(),
11 }
12}
13
14impl AtlasTexture {
15 pub fn from_bitmap(bmp: &Bitmap) -> AtlasTexture {
16 unsafe {
17 from_glib_full(ffi::cogl_atlas_texture_new_from_bitmap(
18 bmp.to_glib_none().0,
19 ))
20 }
21 }
22
23 pub fn from_data(
24 ctx: &Context,
25 width: i32,
26 height: i32,
27 format: PixelFormat,
28 rowstride: i32,
29 data: &[u8],
30 ) -> Result<AtlasTexture, glib::Error> {
31 unsafe {
32 let mut error = ptr::null_mut();
33 let ret = ffi::cogl_atlas_texture_new_from_data(
34 ctx.to_glib_none().0,
35 width,
36 height,
37 format.to_glib(),
38 rowstride,
39 data.as_ptr(),
40 &mut error,
41 );
42 if error.is_null() {
43 Ok(from_glib_full(ret))
44 } else {
45 Err(from_glib_full(error))
46 }
47 }
48 }
49
50 pub fn from_file(ctx: &Context, filename: &str) -> Result<AtlasTexture, glib::Error> {
51 unsafe {
52 let mut error = ptr::null_mut();
53 let ret = ffi::cogl_atlas_texture_new_from_file(
54 ctx.to_glib_none().0,
55 filename.to_glib_none().0,
56 &mut error,
57 );
58 if error.is_null() {
59 Ok(from_glib_full(ret))
60 } else {
61 Err(from_glib_full(error))
62 }
63 }
64 }
65
66 pub fn with_size(ctx: &Context, width: i32, height: i32) -> AtlasTexture {
67 unsafe {
68 from_glib_full(ffi::cogl_atlas_texture_new_with_size(
69 ctx.to_glib_none().0,
70 width,
71 height,
72 ))
73 }
74 }
75}
76
77impl fmt::Display for AtlasTexture {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79 write!(f, "AtlasTexture")
80 }
81}