Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/olpcgames/svgsprite.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-03-27 13:15:10 (GMT)
committer Rafael Ortiz <rafael@activitycentral.com>2012-03-28 18:05:22 (GMT)
commit335ad73456ba3ec8f56811abddcaca4650199db1 (patch)
treedb788baba57c7656c9bdb73eb9003a70dc87d59a /olpcgames/svgsprite.py
parent6deeb3f569e6c9a1c02a32a011b7a96a58fa8443 (diff)
Save and restore state of the game
Ability to 'save' (when the user closes the Activity) and 'restore' (when the user launch it from the Journal or the Home without holding Alt) the state of the game. For this ability I had to upgrade 'olpcgames' to 1.6 because 'olpcgames.FILE_READ_REQUEST' and 'olpcgames.FILE_WRITE_REQUEST' events are added in that version and those events are needed for this. The data is saved (as JSON, with json module) in the 'event.metadata["state"]' and the timestamp state is saved in 'event.filename'. This commit solves ticket #2393: * http://bugs.sugarlabs.org/ticket/2393 Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Signed-off-by: Rafael Ortiz <rafael@activitycentral.com>
Diffstat (limited to 'olpcgames/svgsprite.py')
-rw-r--r--olpcgames/svgsprite.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/olpcgames/svgsprite.py b/olpcgames/svgsprite.py
index 2c53178..ad247dd 100644
--- a/olpcgames/svgsprite.py
+++ b/olpcgames/svgsprite.py
@@ -1,10 +1,16 @@
"""RSVG/Cairo-based rendering of SVG into Pygame Images"""
-from pygame import sprite
+from pygame import sprite, Rect
from olpcgames import _cairoimage
-import cairo, rsvg
class SVGSprite( sprite.Sprite ):
- """Sprite class which renders SVG source-code as a Pygame image"""
+ """Sprite class which renders SVG source-code as a Pygame image
+
+ Note:
+
+ Currently this sprite class is a bit over-engineered, it gets in the way
+ if you want to, e.g. animate among a number of SVG drawings, as it
+ assumes that setSVG will always set a single SVG file for rendering.
+ """
rect = image = None
resolution = None
def __init__(
@@ -30,7 +36,7 @@ class SVGSprite( sprite.Sprite ):
width,height = self.size
else:
width,height = None,None
- self.image = self._render( width,height )
+ self.image = self._render( width,height ).convert_alpha()
rect = self.image.get_rect()
if self.rect:
rect.move( self.rect ) # should let something higher-level do that...
@@ -38,6 +44,7 @@ class SVGSprite( sprite.Sprite ):
def _render( self, width, height ):
"""Render our SVG to a Pygame image"""
+ import rsvg
handle = rsvg.Handle( data = self.svg )
originalSize = (width,height)
scale = 1.0
@@ -66,4 +73,12 @@ class SVGSprite( sprite.Sprite ):
handle.render_cairo( ctx )
return _cairoimage.asImage( csrf )
return None
-
+ def copy( self ):
+ """Create a copy of this sprite without reloading the svg image"""
+ result = self.__class__(
+ size = self.size
+ )
+ result.image = self.image
+ result.rect = Rect(self.rect)
+ result.resolution = self.resolution
+ return result