2 Module extending the Pixmap class with .gfx submodule and its drawing functions.
4 Use as in "import gfxprim.gfx; pixmap_foo.gfx.Line(...)"
7 # Import the SWIG wrapper
14 "Extend Pixmap with gfx submodule"
16 from ..utils
import extend
, add_swig_getmethod
, add_swig_setmethod
17 from ..core
import Pixmap
as _pixmap
19 # New Pixmap submodule
20 class GfxSubmodule(object):
21 def __init__(self
, ctx
):
25 _pixmap
._submodules
['gfx'] = GfxSubmodule
27 # Imports from the SWIG module
28 from ..utils
import import_members
, extend_submodule
31 return re
.sub('^GP_', '', s
)
36 import_members(c_gfx
, C
, include
=const_regexes
, sub
=strip_GP
)
39 'ArcSegment', 'Circle', 'Ellipse', 'FillCircle', 'FillEllipse',
40 'FillRect', 'FillRing',
41 'FillTetragon', 'FillTriangle', 'HLine', 'HLineAA', 'Line', 'LineAA',
42 'PutPixelAA', 'Rect', 'Ring', 'Tetragon',
43 'Triangle', 'VLine', 'VLineAA']:
44 extend_submodule(GfxSubmodule
, name
, c_gfx
.__getattribute
__('GP_' + name
))
47 def Fill(self
, color
):
50 def flatten_coords(points
):
51 "Helper for Polygon and FillPolygon coordinates"
54 if hasattr(p
, '__iter__'):
59 assert isinstance(i
, int)
63 def Polygon(self
, points
, pixel
):
65 Polygon(pixmap, coordinates, pixel)
67 Draw a polygon with color `pixel`.
68 `coordinates` is either an iterable of `int` coordinates `(x0, y0, x1, y1, ...)`
69 or an iterable of tuples `[(x0, y0), (x1, y1), ...]`.
71 c_gfx
.GP_Polygon_wrap(self
.ctx
, flatten_coords(points
), pixel
)
74 def FillPolygon(self
, points
, pixel
):
76 FillPolygon(pixmap, coordinates, pixel)
78 Draw a filled polygon with color `pixel`.
79 `coordinates` is either an iterable of `int` coordinates `(x0, y0, x1, y1, ...)`
80 or an iterable of tuples `[(x0, y0), (x1, y1), ...]`.
82 c_gfx
.GP_FillPolygon_wrap(self
.ctx
, flatten_coords(points
), pixel
)