示例#1
0
 def packToText(self, margin = 4):
   """Packs the box around the text default, with given margin."""
   self._margin = margin
   textSprite = TextManager.renderText(self.text, self.style)
   rect = textSprite.local_bounds
   self._w = rect.width + self._margin*2
   self._h = rect.height + self._margin*2
示例#2
0
  def drawButton(self, view, bacgroundColour, outlineColour, style):
    r = RectangleShape()
    r.outline_color = outlineColour
    r.outline_thickness = 1
    r.fill_color = bacgroundColour
    r.position = (self._ax, self._ay)
    r.size = (self._w, self._h)
    view.drawSprite(r)
    
    textSprite = TextManager.renderText(self.text, style)
    rect = textSprite.local_bounds
    # Needs rect.left and stuff because text local bounds are apparently non-0.
    # Something to do with text alignment, perhaps? :)
    textSprite.position = (self._ax + self._w // 2 - (rect.width // 2) - rect.left,
                           self._ay + self._h // 2 - (rect.height // 2) - rect.top)

    view.drawSprite(textSprite)