# Copyright (c) 2007 SIEGE Development Team
# All rights reserved.
#
# This file is part of libSIEGE.
#
# This software is copyrighted work licensed under the terms of the
# 2-clause BSD license. Please consult the file "license.txt" for
# details.
#
# If you did not recieve the file with this program, please email
# Tim Chas <darkuranium@gmail.com>.

from siege.common cimport *
cimport sprite
from texture cimport Texture

cdef class Sprite:
    #TODO: fix this so that kwargs can be used!
    def __init__(self, item, xoffset = None, yoffset = None):
        assert self.handle is NULL
        
        if isinstance(item, Texture):
            if xoffset is None or yoffset is None:
                self.handle = sgSpriteCreateTexture((<Texture>item).handle)
            else:
                self.handle = sgSpriteCreateTexture2f((<Texture>item).handle, xoffset, yoffset)
        else:
            if xoffset is None or yoffset is None:
                self.handle = sgSpriteCreateFile(item)
            else:
                self.handle = sgSpriteCreateFile2f(item, xoffset, yoffset)
        if self.handle is NULL:
            raise MemoryError()
    
    def __dealloc__(self):
        if self.handle is not NULL:
            self.destroy()
    
    cpdef destroy(self):
        assert self.handle is not NULL
        
        sgSpriteDestroy(self.handle)
        self.handle = NULL
    
    cpdef drawRads(self, x, y, z = 0.0, xscale = 1.0, yscale = 1.0, angle = 0.0):
        assert self.handle is not NULL
        
        sgSpriteDrawRads3f2f1f(self.handle, x, y, z, xscale, yscale, angle)
    cpdef drawDegs(self, x, y, z = 0.0, xscale = 1.0, yscale = 1.0, angle = 0.0):
        assert self.handle is not NULL
        
        sgSpriteDrawDegs3f2f1f(self.handle, x, y, z, xscale, yscale, angle)
    
    cpdef draw(self, x, y, z = 0.0, xscale = 1.0, yscale = 1.0):
        assert self.handle is not NULL
        
        sgSpriteDraw3f2f(self.handle, x, y, z, xscale, yscale)
    
    property size:        
        def __get__(self):
            assert self.handle is not NULL
            
            cdef SGuint width, height
            sgSpriteGetSize(self.handle, &width, &height)
            return (width, height)
    
    property width:
        def __get__(self):
            assert self.handle is not NULL
            
            return sgSpriteGetWidth(self.handle)
    property height:
        def __get__(self):
            assert self.handle is not NULL
            
            return sgSpriteGetHeight(self.handle)
