bargraph.py (8193B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\graphs\bargraph.py 2 import carbonui.const as uiconst 3 from carbonui.primitives.base import ReverseScaleDpi 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.fill import Fill 6 from carbonui.primitives.sprite import Sprite 7 from eve.client.script.ui.graphs import PrimeGraphData 8 from carbonui.uicore import uicore 9 10 class BarGraphBarBase(Container): 11 default_name = 'BarGraphBarBase' 12 default_align = uiconst.TOPLEFT 13 default_width = 128 14 default_height = 6 15 default_state = uiconst.UI_PICKCHILDREN 16 default_bgColor = (0.0, 0.0, 0.0, 0.25) 17 overlayMarkers = None 18 19 def ApplyAttributes(self, attributes): 20 Container.ApplyAttributes(self, attributes) 21 self.segments = [] 22 self.graphData = None 23 24 def LoadGraphData(self, graphData, animateIn = True): 25 self.graphData = PrimeGraphData(graphData) 26 self.ReloadGraph(animateIn=animateIn) 27 28 def UpdateGraphData(self, graphData, animate = True): 29 self.graphData = PrimeGraphData(graphData) 30 for i, segmentParams in enumerate(self.graphData): 31 graphSegment = self.segments[i] 32 graphSegment.color = segmentParams.color 33 graphSegment.hint = segmentParams.tooltip 34 graphSegment.pickState = bool(segmentParams.tooltip) 35 graphSegment.sizeFactor = segmentParams.sizeFactor 36 if segmentParams.showMarker: 37 graphSegment.ShowPointer() 38 else: 39 graphSegment.HidePointer() 40 proportion = segmentParams.proportion 41 proportion = min(1.0, max(0.0, proportion)) 42 if animate: 43 uicore.animations.MorphScalar(graphSegment, 'segmentSize', startVal=graphSegment.segmentSize, endVal=proportion, curveType=uiconst.ANIM_SMOOTH, duration=0.5) 44 else: 45 graphSegment.segmentSize = proportion 46 47 def ReloadGraph(self, animateIn = False): 48 for each in self.segments: 49 each.Close() 50 51 self.segments = [] 52 if not self.graphData: 53 return 54 for i, segmentParams in enumerate(self.graphData): 55 graphSegment = self.CreateGraphSegment(segmentParams.color) 56 self.segments.append(graphSegment) 57 58 self.UpdateGraphData(self.graphData, animateIn) 59 60 def CreateGraphSegment(self, color): 61 segment = BarSegmentFill(name='barSegment', parent=self, align=uiconst.NOALIGN, color=color, state=uiconst.UI_NORMAL, segmentAlignment=self.segmentAlignment) 62 return segment 63 64 def UpdateUIScaling(self, value, oldValue): 65 super(BarGraphBarBase, self).UpdateUIScaling(value, oldValue) 66 self.ReloadGraph() 67 68 def UpdateAlignment(self, budgetLeft = 0, budgetTop = 0, budgetWidth = 0, budgetHeight = 0, updateChildrenOnly = False): 69 ret = Container.UpdateAlignment(self, budgetLeft, budgetTop, budgetWidth, budgetHeight, updateChildrenOnly) 70 self.UpdateSegments() 71 return ret 72 73 def UpdateSegments(self): 74 displayWidth = self.displayWidth 75 displayHeight = self.displayHeight 76 p = 0.0 77 for each in self.segments: 78 if self.segmentAlignment == uiconst.TOLEFT_PROP: 79 w = displayWidth * each.width 80 each.displayRect = (p, 81 0, 82 w, 83 displayHeight * each.sizeFactor) 84 p += w 85 else: 86 h = displayHeight * each.height 87 each.displayRect = (0, 88 p, 89 displayWidth * each.sizeFactor, 90 h) 91 p += h 92 93 94 class BarSegmentFill(Fill): 95 sizeFactor = 1.0 96 pointer = None 97 _segmentSize = 0.0 98 99 def ApplyAttributes(self, attributes): 100 Fill.ApplyAttributes(self, attributes) 101 self.segmentAlignment = attributes.segmentAlignment 102 103 @apply 104 def segmentSize(): 105 106 def fget(self): 107 return self._segmentSize 108 109 def fset(self, value): 110 self._segmentSize = value 111 if self.segmentAlignment == uiconst.TOLEFT_PROP: 112 self.width = value 113 elif self.segmentAlignment == uiconst.TOBOTTOM_PROP: 114 self.height = value 115 116 return property(**locals()) 117 118 def ShowPointer(self): 119 if self.pointer is None: 120 self.pointer = Sprite(parent=self.parent, texturePath='res:/UI/Texture/classes/Graph/barPointer.png', state=uiconst.UI_DISABLED, pos=(0, 0, 15, 15), idx=0) 121 self.pointer.display = False 122 123 def HidePointer(self): 124 if self.pointer and not self.pointer.destroyed: 125 self.pointer.Close() 126 self.pointer = None 127 128 def UpdatePointer(self): 129 if not self.pointer: 130 return 131 displayX, displayY, displayWidth, displayHeight = self.displayRect 132 if self.segmentAlignment == uiconst.TOLEFT_PROP: 133 self.pointer.left = ReverseScaleDpi(displayX + displayWidth / 2) - self.pointer.width / 2 134 self.pointer.top = -self.pointer.height / 2 135 else: 136 self.pointer.left = ReverseScaleDpi(self.parent.displayWidth) - self.pointer.width / 2 137 self.pointer.top = ReverseScaleDpi(displayY + displayHeight / 2) - self.pointer.height / 2 138 self.pointer.display = True 139 140 def Close(self, *args): 141 Fill.Close(self, *args) 142 if self.pointer and not self.pointer.destroyed: 143 self.pointer.Close() 144 self.pointer = None 145 146 @apply 147 def displayRect(): 148 149 def fget(self): 150 return (self._displayX, 151 self._displayY, 152 self._displayWidth, 153 self._displayHeight) 154 155 def fset(self, value): 156 displayX, displayY, displayWidth, displayHeight = value 157 self._displayX = displayX 158 self._displayY = displayY 159 self._displayWidth = displayWidth 160 self._displayHeight = displayHeight 161 ro = self.renderObject 162 if ro: 163 ro.displayX = self._displayX 164 ro.displayY = self._displayY 165 ro.displayWidth = self._displayWidth 166 ro.displayHeight = self._displayHeight 167 self.UpdatePointer() 168 169 return property(**locals()) 170 171 def GetAbsoluteSize(self): 172 return (ReverseScaleDpi(self.displayWidth), ReverseScaleDpi(self.displayHeight)) 173 174 175 class BarGraphBarHorizontal(BarGraphBarBase): 176 segmentAlignment = uiconst.TOLEFT_PROP 177 default_width = 128 178 default_height = 6 179 180 181 class BarGraphBarVertical(BarGraphBarBase): 182 segmentAlignment = uiconst.TOBOTTOM_PROP 183 default_width = 6 184 default_height = 128 185 186 187 class BarGraphHorizontal(Container): 188 189 def ApplyAttributes(self, attributes): 190 Container.ApplyAttributes(self, attributes) 191 self.barClass = attributes.Get('barClass', BarGraphBarHorizontal) 192 self.barPadding = attributes.Get('barPadding', (0, 2, 0, 2)) 193 self.barSize = attributes.Get('barPadding', 6) 194 self.bars = [] 195 196 def LoadGraphData(self, graphData, animateIn = True): 197 self.graphData = graphData 198 self.ReloadGraph(animateIn=animateIn) 199 200 def UpdateGraphData(self, graphData, animate = True): 201 self.graphData = graphData 202 for i, graphData in enumerate(self.graphData): 203 graphBar = self.bars[i] 204 graphBar.UpdateGraphData(graphData, animate) 205 206 def ReloadGraph(self, animateIn = False): 207 for each in self.bars: 208 each.Close() 209 210 self.bars = [] 211 if not self.graphData: 212 return 213 if self.barClass is BarGraphBarHorizontal: 214 barAlign = uiconst.TOTOP 215 width = 0 216 height = self.barSize 217 else: 218 barAlign = uiconst.TOLEFT 219 width = self.barSize 220 height = 0 221 for i, graphData in enumerate(self.graphData): 222 graphBar = self.barClass(parent=self, align=barAlign, width=width, height=height, padding=self.barPadding) 223 self.bars.append(graphBar) 224 graphBar.LoadGraphData(graphData, animateIn)