Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct Surface<'a> {
- //this: cairo::ImageSurface,
- data: std::marker::PhantomData<&'a mut [u8]>,
- pub dimensions: (i32, i32),
- pub scale: i32,
- }
- impl<'a> Surface<'a> {
- // XXX: Should we really hardcode the cairo::Format?
- pub fn new(data: &mut [u8], dimensions: (i32, i32), scale: i32) -> Result<Surface, ()> {
- /*let this = unsafe {
- cairo::ImageSurface::create_for_data::<&mut [u8]>(
- core::mem::transmute(data),
- cairo::Format::ARgb32,
- scale * dimensions.0,
- scale * dimensions.1,
- scale * dimensions.0 * 4,
- )?
- };*/
- Ok(Surface{
- //this: this,
- data: std::marker::PhantomData,
- dimensions: dimensions,
- scale: scale,
- })
- }
- pub fn make_context(&self) -> Context {
- Context::new(self)
- }
- }
- impl<'a> Drop for Surface<'a> {
- fn drop(&mut self) {
- /*let pointer = self.this.to_raw_none();
- unsafe {
- let count = cairo_sys::cairo_surface_get_reference_count(pointer);
- assert_eq!(count, 1, "multiple C references to surface remaining");
- drop(cairo::Surface::from_raw_none(pointer));
- }*/
- println!("Do stuff");
- }
- }
- pub struct Context<'a> {
- //pub this: cairo::Context,
- surface: std::marker::PhantomData<&'a Surface<'a>>,
- }
- impl<'a> Context<'a> {
- fn new(surface: &'a Surface) -> Context<'a> {
- //let this = cairo::Context::new(&surface.this);
- //this.scale(surface.scale.into(), surface.scale.into());
- Context {
- //this: this,
- surface: std::marker::PhantomData,
- }
- }
- }
- impl<'a> Drop for Context<'a> {
- fn drop(&mut self) {
- println!("Dropping context");
- }
- }
- fn main() {
- let mut buf = [0; 4];
- let context: Context;
- {
- let surface = Surface::new(&mut buf, (32, 32), 1).expect("failed to create Cairo surface");
- context = surface.make_context();
- //context.this.set_source_rgba(0.16, 0.16, 0.16, 0.50);
- //context.this.rectangle(0.0, 0.0, 32.0, 32.0);
- //context.this.fill();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement