Skip to content

Instantly share code, notes, and snippets.

@Enerccio
Created February 21, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Enerccio/9702f420eaacfad2f2b90f8767129229 to your computer and use it in GitHub Desktop.
Save Enerccio/9702f420eaacfad2f2b90f8767129229 to your computer and use it in GitHub Desktop.
class SpritePlaceholder(Placeholder):
def __init__(self, sprite, size, base=None, full=False, flip=None, **properties):
Placeholder.__init__(self, base, full, flip, **properties)
self.sprite = sprite
self.size = size
def get_child(self):
if self.child:
return self.child
image = Image(self.sprite)
size = self.size
textpos = (self.size[0]/2, self.size[1]/2)
# Flip as necessary.
if self.flip:
xzoom = -1
textpos = (size[0] - textpos[0], textpos[1])
else:
xzoom = 1
text = "\n".join(self.name)
# Figure out the child.
rv = Fixed(
image,
Text(text, pos=textpos, xanchor=0.5, yanchor=0.5, style="_default", color="#aaa", text_align=0.5, outlines=[ (absolute(1), "#000", absolute(0), absolute(0)) ]),
xysize=size,
alt="",
)
self.child = rv
return rv
def _duplicate(self, args):
args = args or self._args
rv = SpritePlaceholder(self.sprite, self.size, self.base, self.full, self.flip)
rv.name = list(args.name) + list(args.args)
return rv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment