Example #1
0
 def DrawOutline(self, margin = 0):
     if self.outline:
         outline = self.outline
     else:
         outline = VectorLineTrace(parent=self, lineWidth=1, idx=0)
         outline.isLoop = True
         self.outline = outline
     outline.Flush()
     self.cornerPoints = []
     colors = [(1, 0, 0, 1),
      (1, 1, 1, 1),
      (0, 1, 0, 1),
      (1, 1, 1, 1),
      (0, 0, 1, 1),
      (1, 1, 1, 1)]
     for i in xrange(6):
         if self.isFlatTop:
             outlineRad = self.displayWidth * 0.5 - margin
             angle = 2.0 * math.pi / 6.0 * i
         else:
             outlineRad = self.displayHeight * 0.5 - margin
             angle = 2.0 * math.pi / 6.0 * (i + 0.5)
         x_i = ReverseScaleDpi(self.displayWidth * 0.5 + outlineRad * math.cos(angle))
         y_i = ReverseScaleDpi(self.displayHeight * 0.5 + outlineRad * math.sin(angle))
         outline.AddPoint((x_i, y_i), colors[i])
         self.cornerPoints.append((x_i, y_i))
Example #2
0
 def DrawOutline(self):
     if self.outline:
         outline = self.outline
     else:
         outline = VectorLineTrace(parent=self, lineWidth=2)
         outline.isLoop = True
         self.outline = outline
     outline.Flush()
     for i in xrange(6):
         if self.isFlatTop:
             outlineRad = self.displayWidth * 0.5
             angle = 2.0 * math.pi / 6.0 * i
         else:
             outlineRad = self.displayHeight * 0.5
             angle = 2.0 * math.pi / 6.0 * (i + 0.5)
         x_i = ReverseScaleDpi(self.displayWidth * 0.5 +
                               outlineRad * math.cos(angle))
         y_i = ReverseScaleDpi(self.displayHeight * 0.5 +
                               outlineRad * math.sin(angle))
         outline.AddPoint((x_i, y_i), (1, 0, 0, 0.8))
class AchievementTreeConnection(VectorLineTrace, ColorThemeMixin):
    default_lineWidth = 1.0
    default_colorType = uiconst.COLORTYPE_UIHILIGHTGLOW
    default_opacity = 1.0
    glowLine = None
    glowLineColor = (1, 1, 1, 0.5)
    localScale = 1.0
    __notifyevents__ = ['OnUIScalingChange']

    def ApplyAttributes(self, attributes):
        VectorLineTrace.ApplyAttributes(self, attributes)
        ColorThemeMixin.ApplyAttributes(self, attributes)
        self.lineType = LINE_SOLID
        self.fromID = attributes.fromID
        self.toID = attributes.toID
        self.glowLine = VectorLineTrace(
            parent=self.parent,
            lineWidth=20,
            spriteEffect=trinity.TR2_SFX_COPY,
            texturePath='res:/UI/Texture/classes/Achievements/lineGlow.png',
            name='glowLine',
            blendMode=trinity.TR2_SBM_ADDX2,
            opacity=0.3)
        sm.RegisterNotify(self)

    def Close(self, *args):
        if self.glowLine and not self.glowLine.destroyed:
            self.glowLine.Close()
        VectorLineTrace.Close(self, *args)

    def OnUIScalingChange(self, *args):
        self.PlotLineTrace()

    def UpdateFromToPosition(self, fromObject, toObject, localScale):
        self.localScale = localScale
        self.fromPosition = (fromObject.left + fromObject.width / 2,
                             fromObject.top + fromObject.height / 2)
        self.toPosition = (toObject.left + toObject.width / 2,
                           toObject.top + toObject.height / 2)
        self.PlotLineTrace()

    def SetLineType(self, lineType):
        self.lineType = lineType
        self.PlotLineTrace()

    def PlotLineTrace(self):
        self.Flush()
        if self.glowLine:
            self.glowLine.Flush()
        if self.lineType in (LINE_DASHED, LINE_DASHED_ACTIVE):
            self.PlotDashLine()
        elif self.lineType == LINE_SOLID:
            self.PlotSolidLine()
        else:
            return
        if self.lineType == LINE_DASHED_ACTIVE:
            vecDir = geo2.Vec2Subtract(self.toPosition, self.fromPosition)
            vecLength = geo2.Vec2Length(vecDir)
            vecDirNorm = geo2.Vec2Normalize(vecDir)
            r, g, b = self.GetRGB()
            GLOWCOLOR = (r, g, b, 1.0)
            GAPCOLOR = (r, g, b, 0.0)
            self.glowLine.AddPoint(self.fromPosition, GAPCOLOR)
            point = geo2.Vec2Add(self.fromPosition,
                                 geo2.Vec2Scale(vecDirNorm, vecLength * 0.5))
            self.glowLine.AddPoint(point, GLOWCOLOR)
            self.glowLine.AddPoint(self.toPosition, GAPCOLOR)
            self.glowLine.textureWidth = vecLength
            uicore.animations.MorphScalar(self.glowLine,
                                          'textureOffset',
                                          startVal=0.0,
                                          endVal=1.0,
                                          curveType=uiconst.ANIM_LINEAR,
                                          duration=2.0,
                                          loops=uiconst.ANIM_REPEAT)

    def PlotSolidLine(self):
        r, g, b = self.GetRGB()
        DASHCOLOR = (r, g, b, 1.0)
        GAPCOLOR = (r, g, b, 0.0)
        MARGIN = 16.0 * self.localScale
        vecDir = geo2.Vec2Subtract(self.toPosition, self.fromPosition)
        vecLength = geo2.Vec2Length(vecDir)
        vecDirNorm = geo2.Vec2Normalize(vecDir)
        startPoint = geo2.Vec2Add(self.fromPosition,
                                  geo2.Vec2Scale(vecDirNorm, MARGIN))
        self.AddPoint(startPoint, GAPCOLOR)
        startPoint = geo2.Vec2Add(self.fromPosition,
                                  geo2.Vec2Scale(vecDirNorm, MARGIN + 8))
        self.AddPoint(startPoint, DASHCOLOR)
        startPoint = geo2.Vec2Add(
            self.fromPosition,
            geo2.Vec2Scale(vecDirNorm, vecLength - MARGIN - 8))
        self.AddPoint(startPoint, DASHCOLOR)
        startPoint = geo2.Vec2Add(
            self.fromPosition, geo2.Vec2Scale(vecDirNorm, vecLength - MARGIN))
        self.AddPoint(startPoint, GAPCOLOR)

    def PlotDashLine(self):
        dashSize = 2.0
        gapSize = 7.0
        r, g, b = self.GetRGB()
        DASHCOLOR = (r, g, b, 1.0)
        GAPCOLOR = (r, g, b, 0.0)
        MARGIN = 16.0 * self.localScale
        vecDir = geo2.Vec2Subtract(self.toPosition, self.fromPosition)
        vecLength = geo2.Vec2Length(vecDir)
        vecDirNorm = geo2.Vec2Normalize(vecDir)
        p = MARGIN
        while p < vecLength - MARGIN:
            startPoint = geo2.Vec2Add(self.fromPosition,
                                      geo2.Vec2Scale(vecDirNorm, p - 0.5))
            self.AddPoint(startPoint, GAPCOLOR)
            fromPoint = geo2.Vec2Add(self.fromPosition,
                                     geo2.Vec2Scale(vecDirNorm, p))
            self.AddPoint(fromPoint, DASHCOLOR)
            p = min(vecLength - MARGIN, dashSize + p)
            toPoint = geo2.Vec2Add(self.fromPosition,
                                   geo2.Vec2Scale(vecDirNorm, p))
            self.AddPoint(toPoint, DASHCOLOR)
            endPoint = geo2.Vec2Add(self.fromPosition,
                                    geo2.Vec2Scale(vecDirNorm, p + 0.5))
            self.AddPoint(endPoint, GAPCOLOR)
            p += gapSize