summaryrefslogtreecommitdiffstats
path: root/libdimension-python
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-07-10 18:36:46 -0600
committerTavian Barnes <tavianator@gmail.com>2011-07-13 22:24:10 -0600
commitde659b311b756b75cbe06cf2ed02c7ab779915bd (patch)
treefa05783bfc185406f57b9afdcfaecbb63d6d3f63 /libdimension-python
parent3ec26ddd28cbcc279a4fa65de8d68c68b3950576 (diff)
downloaddimension-de659b311b756b75cbe06cf2ed02c7ab779915bd.tar.xz
Support flags-style syntax for --quality.
Diffstat (limited to 'libdimension-python')
-rw-r--r--libdimension-python/dimension.pyx63
1 files changed, 59 insertions, 4 deletions
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index addba7e..ff97f73 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -884,7 +884,7 @@ cdef class Object:
self.texture = texture
if pigment is not None:
if texture is not None:
- raise TypeError('both texture and pigment specified.')
+ raise TypeError("both texture and pigment specified.")
else:
if self.texture is None:
self.texture = Texture()
@@ -892,7 +892,7 @@ cdef class Object:
if finish is not None:
if texture is not None:
- raise TypeError('both texture and finish specified.')
+ raise TypeError("both texture and finish specified.")
else:
if self.texture is None:
self.texture = Texture()
@@ -1401,9 +1401,9 @@ cdef class Scene:
property quality:
"""The render quality."""
def __get__(self):
- return self._scene.quality
+ return _quality_to_string(self._scene.quality)
def __set__(self, q):
- self._scene.quality = q
+ self._scene.quality = _string_to_quality(q)
property bounding_timer:
"""The Timer for building the bounding hierarchy."""
@@ -1432,3 +1432,58 @@ cdef class Scene:
def __dealloc__(self):
dmnsn_delete_scene(self._scene)
+
+def _quality_to_string(int quality):
+ cdef str s = ""
+
+ if quality & DMNSN_RENDER_PIGMENT:
+ s += 'p'
+ if quality & DMNSN_RENDER_LIGHTS:
+ s += 'l'
+ if quality & DMNSN_RENDER_FINISH:
+ s += 'f'
+ if quality & DMNSN_RENDER_TRANSLUCENCY:
+ s += 't'
+ if quality & DMNSN_RENDER_REFLECTION:
+ s += 'r'
+
+ if s == "":
+ return "0"
+ else:
+ return s
+
+def _string_to_quality(str quality not None):
+ cdef int q = DMNSN_RENDER_NONE
+ inverse = False
+
+ if quality[0] == '^':
+ inverse = True
+ quality = quality[1:]
+
+ if quality != "0":
+ while len(quality) > 0:
+ ch = quality[0]
+ quality = quality[1:]
+
+ if ch == 'p':
+ flag = DMNSN_RENDER_PIGMENT
+ elif ch == 'l':
+ flag = DMNSN_RENDER_LIGHTS
+ elif ch == 'f':
+ flag = DMNSN_RENDER_FINISH
+ elif ch == 't':
+ flag = DMNSN_RENDER_TRANSLUCENCY
+ elif ch == 'r':
+ flag = DMNSN_RENDER_REFLECTION
+ else:
+ raise ValueError("unknown quality flag '%c'" % ch)
+
+ if q & flag:
+ raise ValueError("flag '%c' specified twice" % ch)
+ else:
+ q |= flag
+
+ if inverse:
+ q = ~q
+
+ return q