Example #1
0
    def ConstructLine(self, colorStart, colorEnd):
        numPoints = self.radius
        line = VectorLineTrace(name='bg', parent=self, lineWidth=self.lineWidth, width=1, height=1, end=0.0)
        w = self.lineWidth / 2.0
        stepSize = 2 * pi / numPoints
        for i in xrange(numPoints + 1):
            if i == 0:
                t = self.startAngle - 0.1 * stepSize
                point = (w + self.radius * (1.0 + cos(t)), w + self.radius * (1.0 + sin(t)))
                line.AddPoint(point, color=(1, 1, 1, 0))
            t = self.startAngle + float(i) * stepSize
            point = (w + self.radius * (1.0 + cos(t)), w + self.radius * (1.0 + sin(t)))
            color = geo2.Vec4Lerp(colorStart, colorEnd, i / float(numPoints))
            line.AddPoint(point, color)

        return line
Example #2
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 #3
0
 def _DebugDrawLine(self, p1, p2, color=(1, 0, 0, 0.8), margin=10):
     if margin:
         p1, p2 = self.ApplyLineMargin(p1, p2, margin, margin)
     line = VectorLineTrace(parent=self, lineWidth=1, idx=0)
     x1, y1 = p1
     x2, y2 = p2
     line.AddPoint((x1, y1), color)
     line.AddPoint((x2, y2), color)
     return line
    def ConstructSegments(self):
        ret = []
        stepSize = 2 * pi / self.numSegments
        numPoints = max(3, int(30 / self.numSegments))
        w = self.lineWidth / 2.0
        radius = self.radius - self.lineWidth / 2.0
        for i in xrange(self.numSegments):
            line = VectorLineTrace(name='line', parent=self.segmentTransform, lineWidth=self.lineWidth, width=100, height=100)
            for j in xrange(numPoints + 1):
                t = float(i) / self.numSegments * 2 * pi + float(j) / numPoints * stepSize
                t += pi / 2
                point = (w + radius * (1.0 + cos(t)), w + radius * (1.0 + sin(t)))
                if self.numSegments > 1 and (j == 0 or j == numPoints):
                    line.AddPoint(point, color=(1, 1, 1, 0))
                else:
                    line.AddPoint(point)

            ret.append(line)

        return ret
Example #5
0
    def ConstructLine(self, colorStart, colorEnd):
        numPoints = max(30, self.radius)
        line = VectorLineTrace(parent=self,
                               lineWidth=self.lineWidth,
                               width=1,
                               height=1,
                               end=0.0)
        w = self.lineWidth / 2.0
        stepSize = 2 * pi / numPoints
        for i in xrange(numPoints + 1):
            if i == 0:
                t = self.startAngle - 0.1 * stepSize
                point = self.GetLinePoint(t, w)
                line.AddPoint(point, color=(1, 1, 1, 0))
            t = self.startAngle + float(i) * stepSize
            point = self.GetLinePoint(t, w)
            color = geo2.Vec4Lerp(colorStart, colorEnd, i / float(numPoints))
            line.AddPoint(point, color)

        return line
Example #6
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))
Example #7
0
class PointerContainer(Container):
    """
    This is a frame with a pointer on one edge
    """
    default_name = 'PointerContainer'
    default_state = uiconst.UI_NORMAL
    default_align = uiconst.TOPLEFT
    default_width = 200
    default_height = 100
    default_dockPlacement = DockPlacement.LeftCenter
    default_dockPointerLength = 16
    default_dockMargin = 8
    default_hintBgColor = (0.1, 0.1, 0.1, 0.85)
    default_hintFrameColor = (1.0, 1.0, 1.0, 0.25)

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.dockPointerLength = attributes.get('dockPointerLength', self.default_dockPointerLength)
        self.dockMargin = attributes.get('dockMargin', self.default_dockMargin)
        self.hintBgColor = attributes.get('hintBgColor', self.default_hintBgColor)
        self.hintFrameColor = attributes.get('hintFrameColor', self.default_hintFrameColor)
        self.anchor = attributes.anchor
        self.dockPlacement = attributes.get('dockPlacement', self.default_dockPlacement)
        self.lineTrace = None
        self._BindToAnchor(self.anchor)
        self.SetDockPlacement(self.dockPlacement)

    def _BindToAnchor(self, anchor):
        """
        When eve our anchor changes we want to update the hint location
        """
        cs = uicore.uilib.bracketCurveSet
        self.bindings = []
        self.bindings.append(trinity.CreateBinding(cs, anchor.renderObject, 'displayX', None, ''))
        self.bindings.append(trinity.CreateBinding(cs, anchor.renderObject, 'displayY', None, ''))
        for binding in self.bindings:
            binding.copyValueCallable = self._UpdateBoundValues

    def _UpdateBoundValues(self, *args):
        self.UpdatePosition()

    def UpdatePosition(self):
        anchorRect = self.anchor.GetAbsolute()
        dockPlacement = self.GetBestDockPlacement()
        left, top = self.CalcPosition(dockPlacement, anchorRect)
        self.top = top
        self.left = left

    def CalcPosition(self, dockPlacement, anchorRect):
        left, top, width, height = anchorRect
        newLeft, newTop = (0, 0)
        if dockPlacement == DockPlacement.TopCenter:
            newTop = top + (height + self.dockPointerLength + self.dockMargin)
            newLeft = left + (width - self.width) / 2
        elif dockPlacement == DockPlacement.BottomCenter:
            newTop = top - (self.height + self.dockPointerLength + self.dockMargin)
            newLeft = left + (width - self.width) / 2
        elif dockPlacement == DockPlacement.LeftCenter:
            newTop = top + (height - self.height) / 2
            newLeft = left + (width + self.dockPointerLength + self.dockMargin)
        elif dockPlacement == DockPlacement.RightCenter:
            newTop = top + (height - self.height) / 2
            newLeft = left - (self.width + self.dockPointerLength + self.dockMargin)
        return (newLeft, newTop)

    def GetBestDockPlacement(self):
        return self.dockPlacement

    def SetDockPlacement(self, dockPlacement):
        """
        places the selector window on around the anchor as appropriate
        """
        self.dockPlacement = dockPlacement
        self.DoUpdateLayout(dockPlacement)
        self.UpdatePosition()

    def DoUpdateLayout(self, dockPlacement):
        pointerWidth = self.dockPointerLength * 2
        if dockPlacement == DockPlacement.TopCenter:
            pointList = ((0, 0),
             ((self.width - pointerWidth) * 0.5, 0),
             (self.width * 0.5, -self.dockPointerLength),
             ((self.width + pointerWidth) * 0.5, 0),
             (self.width, 0),
             (self.width, self.height),
             (0, self.height))
        elif dockPlacement == DockPlacement.BottomCenter:
            pointList = ((0, 0),
             (self.width, 0),
             (self.width, self.height),
             ((self.width + pointerWidth) * 0.5, self.height),
             (self.width * 0.5, self.height + pointerWidth),
             ((self.width - pointerWidth) * 0.5, self.height),
             (0, self.height))
        elif dockPlacement == DockPlacement.LeftCenter:
            pointList = ((0, 0),
             (self.width, 0),
             (self.width, self.height),
             (0, self.height),
             (0, (self.height + pointerWidth) * 0.5),
             (-self.dockPointerLength, self.height * 0.5),
             (0, (self.height - pointerWidth) * 0.5))
        elif dockPlacement == DockPlacement.RightCenter:
            pointList = ((0, 0),
             (self.width, 0),
             (self.width, (self.height - pointerWidth) * 0.5),
             (self.width + self.dockPointerLength, self.height * 0.5),
             (self.width, (self.height + pointerWidth) * 0.5),
             (self.width, self.height),
             (0, self.height))
        else:
            raise NotImplementedError('This case of dock placement has not been implemented yet')
        if self.lineTrace is not None:
            self.lineTrace.Close()
        self.lineTrace = VectorLineTrace(parent=self, lineWidth=1.0, spriteEffect=trinity.TR2_SFX_FILL)
        self.lineTrace.isLoop = True
        for point in pointList:
            x, y = point
            x, y = uicore.ScaleDpi(x), uicore.ScaleDpi(y)
            self.lineTrace.AddPoint((x, y), self.hintFrameColor)

        pointerSideWidth = int(self.dockPointerLength * 2 / sqrt(2))
        pointerSideWidthHalf = pointerSideWidth / 2
        if dockPlacement == DockPlacement.TopCenter:
            clipperAlign = uiconst.CENTERTOP
            transformAlign = uiconst.CENTERBOTTOM
            horizontal = False
        elif dockPlacement == DockPlacement.BottomCenter:
            clipperAlign = uiconst.CENTERBOTTOM
            transformAlign = uiconst.CENTERTOP
            horizontal = False
        elif dockPlacement == DockPlacement.LeftCenter:
            clipperAlign = uiconst.CENTERLEFT
            transformAlign = uiconst.CENTERRIGHT
            horizontal = True
        elif dockPlacement == DockPlacement.RightCenter:
            clipperAlign = uiconst.CENTERRIGHT
            transformAlign = uiconst.CENTERLEFT
            horizontal = True
        else:
            raise NotImplementedError('This case of dock placement has not been implemented yet')
        clipperCont = Container(name='clipper', parent=self, width=self.dockPointerLength if horizontal else pointerWidth, height=pointerWidth if horizontal else self.dockPointerLength, clipChildren=True, align=clipperAlign, top=0 if horizontal else -self.dockPointerLength, left=-self.dockPointerLength if horizontal else 0)
        transform = Transform(name='transform', parent=clipperCont, align=transformAlign, rotation=pi / 4, width=pointerSideWidth, height=pointerSideWidth, top=0 if horizontal else -pointerSideWidthHalf, left=-pointerSideWidthHalf if horizontal else 0)
        Fill(bgParent=transform, color=self.hintBgColor)

    def _OnClose(self):
        self._UnbindAnchor()
        Container._OnClose(self)

    def _UnbindAnchor(self):
        cs = uicore.uilib.bracketCurveSet
        if cs:
            for binding in self.bindings:
                if binding in cs.bindings:
                    cs.bindings.remove(binding)

    def FixPosition(self):
        self._UnbindAnchor()
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