Example #1
0
class IconImageNode(PXImage):
    """Just like PImage, except it semantically zooms
    (i.e., at low scales, it does not paint its bitmap).

    """
    TEMP_ELLIPSE = Ellipse2D.Float()

    ENABLE_SEMANTIC_ZOOM = False

    def __init__(self, image_or_string=None):
        PXImage.__init__(self, image_or_string)
        self.path = GeneralPath()  # transient???
        self.original_bounds = self.bounds
        self.prev_scale = 0

    def updatePath(self, scale):
        origWidth = self.original_bounds.width
        origHeight = self.original_bounds.height
        width = origWidth * scale
        height = origWidth * scale
        offsetX = (origWidth - width) / 2.
        offsetY = (origHeight - height) / 2.

        self.path.reset()
        self.TEMP_ELLIPSE.setFrame(offsetX, offsetY, width, height)
        self.path.append(self.TEMP_ELLIPSE, False)

    def paint(self, context):
        s = context.scale
        g2 = context.graphics

        if self.ENABLE_SEMANTIC_ZOOM and s < uienvironment['SEMANTIC_ZOOM_LEVEL']:
            if s != self.prev_scale:
                delta = 1 - ((uienvironment['SEMANTIC_ZOOM_LEVEL'] - s)
                             / uienvironment['SEMANTIC_ZOOM_LEVEL'])
                self.updatePath(1. / delta)

            g2.setPaint(NengoStyle.COLOR_FOREGROUND)
            g2.fill(self.path)

            # g2.fill(self.boundsReference)

        else:
            self.super__setPaint(context)
Example #2
0
class TrimorphicUI(PolygonTileUI):
  def __init__(self, t, wiggle=CubicCurve2D.Double(0, 0, 0.5, 0.5, 0.5, -0.5, 1, 0)):
    self.preTransform = t
    self.wiggle = wiggle
    PolygonTileUI.__init__(self, Color(64, 183, 185), t)
    self.initialiseGraphics()

  def initialiseGraphics(self):
    self.polygonalTilePath = GeneralPath() 
    self.polygonalTilePath.append(self.wiggle, 1)

    t = AffineTransform.getTranslateInstance(1, 0)
    t.rotate(math.pi / 2)
    wiggle2 = GeneralPath(self.wiggle)
    wiggle2.transform(t)
    self.polygonalTilePath.append(wiggle2, 1)

    t = AffineTransform.getTranslateInstance(1, 1)
    t.rotate(3 * math.pi / 4)
    t.scale(1 / math.sqrt(2), 1 / math.sqrt(2))
    wiggle3 = GeneralPath(self.wiggle)
    wiggle3.transform(t)
    self.polygonalTilePath.append(wiggle3, 1)

    t = AffineTransform.getTranslateInstance(0.5, 1.5)
    t.rotate(5 * math.pi / 4)
    t.scale(1 / math.sqrt(2), 1 / math.sqrt(2))
    wiggle4 = GeneralPath(self.wiggle)
    wiggle4.transform(t)
    self.polygonalTilePath.append(wiggle4, 1)

    t = AffineTransform.getTranslateInstance(0, 1)
    t.rotate(3 * math.pi / 2)
    wiggle5 = GeneralPath(self.wiggle)
    wiggle5.transform(t)
    self.polygonalTilePath.append(wiggle5, 1)

    self.polygonalTilePath.closePath()
    self.polygonalTilePath.transform(self.preTransform)
Example #3
0
class SHornUI(PolygonTileUI):
  def __init__(self, t, n):
    self.preTransform = t
    self.n = n
    PolygonTileUI.__init__(self, Color(210, 83, 185), t)
    self.initialiseGraphics()

  def initialiseGraphics(self):
    wiggle=CubicCurve2D.Double(0, 0, 0.3, -0.3, 0.7, 0.3, 1, 0)
    reverseWiggle=CubicCurve2D.Double(1, 0, 0.7, 0.3, 0.3, -0.3, 0, 0)

    self.polygonalTilePath = GeneralPath() 
    self.polygonalTilePath.append(wiggle, 1)

    self.polygonalTilePath.lineTo(math.cos(math.pi / self.n), math.sin(math.pi / self.n))

    t = AffineTransform.getRotateInstance(math.pi / self.n)
    wiggle2 = GeneralPath(reverseWiggle)
    wiggle2.transform(t)
    self.polygonalTilePath.append(wiggle2, 1)

    self.polygonalTilePath.closePath()
    self.polygonalTilePath.transform(self.preTransform)