-
Notifications
You must be signed in to change notification settings - Fork 16
/
draw.py
45 lines (30 loc) · 1.06 KB
/
draw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Drawing commands
-------------------
Operations on a Canvas may be specified by command objects.
This allows one to flexibly filter or modify a stream of drawing operations.
"""
from __future__ import division
from tmxlib import helpers
class DrawCommand(object):
"""A draw command
"""
def draw(self, canvas):
"""Apply this operation to the given Canvas"""
raise NotImplementedError('DrawOperation.draw() is abstract')
class DrawImageCommand(DrawCommand):
"""Command to draw an image
init arguments that become attributes:
.. attribute:: image
The image to draw
.. attribute:: pos
Position at which to draw the image.
Will also available as ``x`` and ``y`` attributes.
"""
x, y = helpers.unpacked_properties('pos')
def __init__(self, image, pos=(0, 0), opacity=1):
self.image = image
self.pos = pos
self.opacity = opacity
def draw(self, canvas):
canvas.draw_image(self.image, self.pos,
opacity=self.opacity)