Created
February 21, 2019 15:02
-
-
Save Enerccio/9702f420eaacfad2f2b90f8767129229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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