コード例 #1
0
ファイル: icons.py プロジェクト: ctn-waterloo/nengo_java_gui
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)