Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _location_to_x_y(self, location):
if location == TextAlign.CENTER:
return (self.viewport_size[0] / 2.0, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_LEFT:
return (TEXT_PADDING, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] / 2.0)
elif location == TextAlign.BOTTOM_LEFT:
return (TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_CENTER:
return (self.viewport_size[0] / 2.0, TEXT_PADDING)
elif location == TextAlign.TOP_LEFT:
return (TEXT_PADDING, self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_CENTER:
return (self.viewport_size[0] / 2.0,
self.viewport_size[1] - TEXT_PADDING)
def _location_to_x_y(self, location):
if location == TextAlign.CENTER:
return (self.viewport_size[0] / 2.0, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_LEFT:
return (TEXT_PADDING, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] / 2.0)
elif location == TextAlign.BOTTOM_LEFT:
return (TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_CENTER:
return (self.viewport_size[0] / 2.0, TEXT_PADDING)
elif location == TextAlign.TOP_LEFT:
return (TEXT_PADDING, self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_CENTER:
return (self.viewport_size[0] / 2.0,
self.viewport_size[1] - TEXT_PADDING)
def _location_to_x_y(self, location):
if location == TextAlign.CENTER:
return (self.viewport_size[0] / 2.0, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_LEFT:
return (TEXT_PADDING, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] / 2.0)
elif location == TextAlign.BOTTOM_LEFT:
return (TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_CENTER:
return (self.viewport_size[0] / 2.0, TEXT_PADDING)
elif location == TextAlign.TOP_LEFT:
return (TEXT_PADDING, self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_CENTER:
def render_string(self, text, x, y, scale=1.0,
align=TextAlign.BOTTOM_LEFT):
"""Render a string to the current view buffer.
Note
----
Assumes correct shader program already bound w/ uniforms set.
Parameters
----------
text : str
The text to render.
x : int
Horizontal pixel location of text.
y : int
Vertical pixel location of text.
scale : int
Scaling factor for text.
def _location_to_x_y(self, location):
if location == TextAlign.CENTER:
return (self.viewport_size[0] / 2.0, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_LEFT:
return (TEXT_PADDING, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] / 2.0)
elif location == TextAlign.BOTTOM_LEFT:
return (TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_CENTER:
return (self.viewport_size[0] / 2.0, TEXT_PADDING)
elif location == TextAlign.TOP_LEFT:
return (TEXT_PADDING, self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_CENTER:
return (self.viewport_size[0] / 2.0,
self.viewport_size[1] - TEXT_PADDING)
if location == TextAlign.CENTER:
return (self.viewport_size[0] / 2.0, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_LEFT:
return (TEXT_PADDING, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] / 2.0)
elif location == TextAlign.BOTTOM_LEFT:
return (TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_CENTER:
return (self.viewport_size[0] / 2.0, TEXT_PADDING)
elif location == TextAlign.TOP_LEFT:
return (TEXT_PADDING, self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_CENTER:
return (self.viewport_size[0] / 2.0,
self.viewport_size[1] - TEXT_PADDING)
if align == TextAlign.BOTTOM_RIGHT:
xoff = -width
elif align == TextAlign.BOTTOM_CENTER:
xoff = -width / 2.0
elif align == TextAlign.TOP_LEFT:
yoff = -height
elif align == TextAlign.TOP_RIGHT:
yoff = -height
xoff = -width
elif align == TextAlign.TOP_CENTER:
yoff = -height
xoff = -width / 2.0
elif align == TextAlign.CENTER:
xoff = -width / 2.0
yoff = -height / 2.0
elif align == TextAlign.CENTER_LEFT:
yoff = -height / 2.0
elif align == TextAlign.CENTER_RIGHT:
xoff = -width
yoff = -height / 2.0
x += xoff
y += yoff
ch = None
for c in text:
ch = self._character_map[c]
xpos = x + ch.bearing[0] * scale
ypos = y - (ch.size[1] - ch.bearing[1]) * scale
w = ch.size[0] * scale
h = ch.size[1] * scale
def _location_to_x_y(self, location):
if location == TextAlign.CENTER:
return (self.viewport_size[0] / 2.0, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_LEFT:
return (TEXT_PADDING, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] / 2.0)
elif location == TextAlign.BOTTOM_LEFT:
return (TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_CENTER:
return (self.viewport_size[0] / 2.0, TEXT_PADDING)
elif location == TextAlign.TOP_LEFT:
return (TEXT_PADDING, self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_CENTER:
return (self.viewport_size[0] / 2.0,
self.viewport_size[1] - TEXT_PADDING)
def _location_to_x_y(self, location):
if location == TextAlign.CENTER:
return (self.viewport_size[0] / 2.0, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_LEFT:
return (TEXT_PADDING, self.viewport_size[1] / 2.0)
elif location == TextAlign.CENTER_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,
self.viewport_size[1] / 2.0)
elif location == TextAlign.BOTTOM_LEFT:
return (TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING, TEXT_PADDING)
elif location == TextAlign.BOTTOM_CENTER:
return (self.viewport_size[0] / 2.0, TEXT_PADDING)
elif location == TextAlign.TOP_LEFT:
return (TEXT_PADDING, self.viewport_size[1] - TEXT_PADDING)
elif location == TextAlign.TOP_RIGHT:
return (self.viewport_size[0] - TEXT_PADDING,