NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

circulargraph.py (7686B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\graphs\circulargraph.py
      2 import carbonui.const as uiconst
      3 from carbonui.primitives.container import Container
      4 from carbonui.primitives.sprite import Sprite, VisibleBase
      5 from carbonui.primitives.vectorlinetrace import VectorLineTrace
      6 import math
      7 import geo2
      8 import blue
      9 from eve.client.script.ui.graphs import PrimeGraphData
     10 from carbonui.uicore import uicore
     11 
     12 class CircularGraph(Container):
     13     default_name = 'CircularGraph'
     14     default_radius = 32
     15     default_lineWidth = 4.0
     16     default_bgLineWidth = default_lineWidth + 1.0
     17     default_align = uiconst.TOPLEFT
     18     default_state = uiconst.UI_PICKCHILDREN
     19     default_colorBg = (1.0, 1.0, 1.0, 0.1)
     20     default_startAngle = -math.pi / 2
     21     default_glow = False
     22     default_glowBrightness = 0.0
     23     backgroundLine = None
     24 
     25     def ApplyAttributes(self, attributes):
     26         Container.ApplyAttributes(self, attributes)
     27         self.radius = attributes.Get('radius', self.default_radius)
     28         self.lineWidth = attributes.Get('lineWidth', self.default_lineWidth)
     29         self.bgLineWidth = attributes.Get('bgLineWidth', self.default_bgLineWidth)
     30         self.startAngle = attributes.Get('startAngle', self.default_startAngle)
     31         self.colorBg = attributes.Get('colorBg', self.default_colorBg)
     32         self.glow = attributes.Get('glow', self.default_glow)
     33         self.glowBrightness = attributes.Get('glowBrightness', self.default_glowBrightness)
     34         self.width = self.height = self.radius * 2
     35         self.pickRadius = self.radius
     36         self.segments = []
     37         self.pointers = set()
     38         self.graphData = None
     39 
     40     def LoadGraphData(self, graphData, animateIn = True):
     41         self.graphData = PrimeGraphData(graphData)
     42         self.ReloadGraph(animateIn=animateIn)
     43 
     44     def UpdateGraphData(self, graphData, animate = True):
     45         self.graphData = PrimeGraphData(graphData)
     46         position = 0.0
     47         for i, segmentParams in enumerate(self.graphData):
     48             segmentLine = self.segments[i]
     49             segmentLine.color = segmentParams.color
     50             segmentLine.hint = segmentParams.tooltip
     51             if segmentParams.showMarker:
     52                 segmentLine.ShowPointer()
     53                 self.pointers.add(segmentLine.pointer)
     54             else:
     55                 pointer = getattr(segmentLine, 'pointer', None)
     56                 if pointer and pointer in self.pointers:
     57                     self.pointers.remove(pointer)
     58                 segmentLine.HidePointer()
     59             proportion = segmentParams.proportion
     60             proportion = max(0.0, proportion)
     61             endPosition = min(1.0, position + proportion)
     62             if animate:
     63                 uicore.animations.MorphScalar(segmentLine, 'start', startVal=segmentLine.start, endVal=position, curveType=uiconst.ANIM_SMOOTH, duration=0.5)
     64                 uicore.animations.MorphScalar(segmentLine, 'end', startVal=segmentLine.end, endVal=endPosition, curveType=uiconst.ANIM_SMOOTH, duration=0.5)
     65             else:
     66                 segmentLine.start = position
     67                 segmentLine.end = endPosition
     68             position = endPosition
     69 
     70     def ReloadGraph(self, animateIn = False):
     71         for each in self.segments:
     72             each.Close()
     73 
     74         for each in self.pointers:
     75             each.Close()
     76 
     77         if self.backgroundLine:
     78             self.backgroundLine.Close()
     79         self.backgroundLine = None
     80         self.segments = []
     81         self.pointers = set()
     82         if not self.graphData:
     83             return
     84         for i, segmentParams in enumerate(self.graphData):
     85             segmentLine = self.CreateLineTrace(segmentParams.color, self.lineWidth * segmentParams.sizeFactor)
     86             self.segments.append(segmentLine)
     87 
     88         self.UpdateGraphData(self.graphData, animateIn)
     89         self.width = self.radius * 2
     90         self.height = self.radius * 2
     91         if self.colorBg:
     92             bgLine = self.CreateLineTrace(self.colorBg, self.bgLineWidth)
     93             bgLine.end = 1.0
     94             bgLine.state = uiconst.UI_DISABLED
     95             self.backgroundLine = bgLine
     96 
     97     def CreateLineTrace(self, color, lineWidth):
     98         graphSize = self.radius * 2
     99         outputMode = VisibleBase.default_outputMode
    100         if self.glow:
    101             outputMode = uiconst.OUTPUT_COLOR_AND_GLOW
    102         line = CircularGraphSegment(name='segmentline', parent=self, lineWidth=lineWidth, width=graphSize, height=graphSize, color=color, state=uiconst.UI_NORMAL, outputMode=outputMode, glowBrightness=self.glowBrightness)
    103         line.end = 0.0
    104         halfLine = lineWidth / 2.0
    105         plotRadius = self.radius - halfLine
    106         numPoints = min(256, max(32, int(math.pi * plotRadius)))
    107         stepSize = 2 * math.pi / numPoints
    108         angle = self.startAngle
    109         for i in xrange(numPoints + 1):
    110             x = plotRadius * math.cos(angle) + self.radius
    111             y = plotRadius * math.sin(angle) + self.radius
    112             line.AddPoint((x, y), (1.0, 1.0, 1.0, 1.0))
    113             angle += stepSize
    114 
    115         return line
    116 
    117 
    118 class CircularGraphSegment(VectorLineTrace):
    119     sizeFactor = 1.0
    120     pointer = None
    121 
    122     def ShowPointer(self):
    123         if self.pointer is None:
    124             self.pointer = Sprite(parent=self.parent, texturePath='res:/UI/Texture/classes/Graph/barPointer.png', pos=(0, 0, 15, 15), state=uiconst.UI_DISABLED, idx=0)
    125             self.UpdatePointer()
    126 
    127     def HidePointer(self):
    128         if self.pointer and not self.pointer.destroyed:
    129             self.pointer.Close()
    130             self.pointer = None
    131 
    132     def UpdatePointer(self):
    133         if not self.pointer:
    134             return
    135         x, y, angle = self.GetOuterCenterPointAndAngle()
    136         self.pointer.left = x - self.pointer.width / 2
    137         self.pointer.top = y - self.pointer.height / 2
    138         self.pointer.rotation = math.pi * 2 - angle
    139 
    140     def GetOuterCenterPointAndAngle(self):
    141         centerProportion = self.start + (self.end - self.start) / 2
    142         angle = centerProportion * math.pi * 2
    143         radius = self.width / 2
    144         x = radius * (1.0 + math.cos(angle + math.pi / 2))
    145         y = radius * (1.0 + math.sin(angle + math.pi / 2))
    146         return (self.width - x, self.height - y, angle)
    147 
    148     @apply
    149     def start():
    150         doc = '\n        Where to start drawing the line, as a proportion of the length of\n        the line path. Defaults to 0 to start at the start of the path.\n        '
    151         fget = VectorLineTrace.start.fget
    152 
    153         def fset(self, value):
    154             VectorLineTrace.start.fset(self, value)
    155             self.UpdatePointer()
    156 
    157         return property(**locals())
    158 
    159     @apply
    160     def end():
    161         doc = '\n        Where to stop drawing the line, as a proportion of the length of\n        the line path. Defaults to 1 to stop at the end of the path.\n        '
    162         fget = VectorLineTrace.end.fget
    163 
    164         def fset(self, value):
    165             VectorLineTrace.end.fset(self, value)
    166             self.UpdatePointer()
    167 
    168         return property(**locals())
    169 
    170     def GetTooltipPosition(self):
    171         xp, yp = self.GetAbsolutePosition()
    172         x, y, angle = self.GetOuterCenterPointAndAngle()
    173         return (x + xp,
    174          y + yp,
    175          0,
    176          0)
    177 
    178     def GetTooltipPointer(self):
    179         x, y, angle = self.GetOuterCenterPointAndAngle()
    180         x = x - self.width / 2
    181         y = y - self.height / 2
    182         if y > 0:
    183             if x > 0:
    184                 return uiconst.POINT_TOPLEFT
    185             else:
    186                 return uiconst.POINT_TOPRIGHT
    187         else:
    188             if x > 0:
    189                 return uiconst.POINT_BOTTOMLEFT
    190             return uiconst.POINT_BOTTOMRIGHT
    191         return uiconst.POINT_TOP_2