summaryrefslogtreecommitdiffstats
path: root/libdimension-python/dimension.pyx
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-06-17 12:13:15 -0600
committerTavian Barnes <tavianator@gmail.com>2011-06-17 13:28:16 -0600
commit9f0b74d5174c53e38392abeae913ccf25f3f967e (patch)
treec9d07656a471e5dd95223fa51aed32e50ab686f7 /libdimension-python/dimension.pyx
parent8a01c01119d134828c511ee68367b5b0e3bd094f (diff)
downloaddimension-9f0b74d5174c53e38392abeae913ccf25f3f967e.tar.xz
Add pigment= and finish= shorthand to Object.__init__().
Diffstat (limited to 'libdimension-python/dimension.pyx')
-rw-r--r--libdimension-python/dimension.pyx67
1 files changed, 57 insertions, 10 deletions
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index e1aba28..8c25538 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -793,11 +793,19 @@ cdef class Texture:
property pigment:
"""The texture's pigment."""
def __get__(self):
- return _Pigment(self._texture.pigment)
- def __set__(self, Pigment pigment not None):
+ if self._texture.pigment == NULL:
+ return None
+ else:
+ return _Pigment(self._texture.pigment)
+ def __set__(self, pigment):
dmnsn_delete_pigment(self._texture.pigment)
- self._texture.pigment = pigment._pigment
- DMNSN_INCREF(self._texture.pigment)
+ cdef Pigment real_pigment
+ if pigment is None:
+ self._texture.pigment = NULL
+ else:
+ real_pigment = Pigment(pigment)
+ self._texture.pigment = real_pigment._pigment
+ DMNSN_INCREF(self._texture.pigment)
property finish:
"""The texture's finish."""
@@ -859,27 +867,66 @@ cdef class Object:
def __cinit__(self):
self._object = NULL
- def __init__(self, Texture texture = None, Interior interior = None):
+ def __init__(self, Texture texture = None, pigment = None,
+ Finish finish = None, Interior interior = None):
"""
Initialize an Object.
Keyword arguments:
texture -- the object's Texture
+ pigment -- shorthand for specifying the texture's pigment
+ finish -- shorthand for specifying the texture's finish
interior -- the object's Interior
"""
if self._object == NULL:
raise TypeError("attempt to initialize base Object")
- if texture is not None:
- self._object.texture = texture._texture
- DMNSN_INCREF(self._object.texture)
+ self.texture = texture
+ if pigment is not None:
+ if texture is not None:
+ raise TypeError('both texture and pigment specified.')
+ else:
+ if self.texture is None:
+ self.texture = Texture()
+ self.texture.pigment = pigment
+
+ if finish is not None:
+ if texture is not None:
+ raise TypeError('both texture and finish specified.')
+ else:
+ if self.texture is None:
+ self.texture = Texture()
+ self.texture.finish = finish
+
if interior is not None:
- self._object.interior = interior._interior
- DMNSN_INCREF(self._object.interior)
+ self.interior = interior
def __dealloc__(self):
dmnsn_delete_object(self._object)
+ property texture:
+ """The object's Texture."""
+ def __get__(self):
+ if self._object.texture == NULL:
+ return None
+ else:
+ return _Texture(self._object.texture)
+ def __set__(self, Texture texture):
+ dmnsn_delete_texture(self._object.texture)
+ if texture is None:
+ self._object.texture = NULL
+ else:
+ self._object.texture = texture._texture
+ DMNSN_INCREF(self._object.texture)
+
+ property interior:
+ """The object's Interior."""
+ def __get__(self):
+ return _Interior(self._object.interior)
+ def __set__(self, Interior interior not None):
+ self._object.interior = interior._interior
+ DMNSN_INCREF(self._object.interior)
+
def transform(self, Matrix trans not None):
"""Transform an object."""
self._object.trans = dmnsn_matrix_mul(trans._m, self._object.trans)