donutSegment.py (7050B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\donutSegment.py 2 import math 3 import geo2 4 from carbonui import Color, uiconst 5 from carbonui.primitives.vectorlinetrace import VectorLineTrace 6 from carbonui.uianimations import animations 7 from signals import Signal 8 MIN_NUM_POINTS = 24 9 10 class DonutSegment(VectorLineTrace): 11 default_segmentID = None 12 default_radius = 20 13 default_angle = 2 * math.pi 14 default_startAngle = -math.pi / 2 15 default_isClockwise = True 16 default_colorStart = (1.0, 1.0, 1.0, 1.0) 17 default_colorEnd = (1.0, 1.0, 1.0, 1.0) 18 default_outputMode = uiconst.OUTPUT_COLOR_AND_GLOW 19 default_glowBrightness = 0.0 20 21 def ApplyAttributes(self, attributes): 22 VectorLineTrace.ApplyAttributes(self, attributes) 23 self._radius = attributes.get('radius', self.default_radius) 24 self.startAngle = attributes.get('startAngle', self.default_startAngle) 25 self.angle = attributes.get('angle', self.default_angle) 26 self.isClockwise = attributes.get('isClockwise', self.default_isClockwise) 27 self._colorStart = Color.from_any(attributes.get('colorStart', self.default_colorStart)) 28 self._colorEnd = Color.from_any(attributes.get('colorEnd', self.default_colorEnd)) 29 self.segmentID = attributes.get('segmentID', None) 30 value = attributes.value 31 self.width = self.height = 2 * self._radius 32 self.on_clicked = Signal(signalName='on_clicked') 33 self.on_mouse_enter = Signal(signalName='on_mouse_enter') 34 self.on_mouse_exit = Signal(signalName='on_mouse_exit') 35 self._ReconstructControlPoints() 36 if value is not None: 37 self.SetValue(value) 38 39 @property 40 def radius(self): 41 return self._radius 42 43 @radius.setter 44 def radius(self, value): 45 self.SetRadius(value) 46 47 @property 48 def colorStart(self): 49 return self._colorStart 50 51 @colorStart.setter 52 def colorStart(self, color): 53 self._colorStart = Color.from_any(color) 54 self._ReconstructControlPoints() 55 56 @property 57 def colorEnd(self): 58 return self._colorEnd 59 60 @colorEnd.setter 61 def colorEnd(self, color): 62 self._colorEnd = Color.from_any(color) 63 self._ReconstructControlPoints() 64 65 def SetColor(self, start = None, end = None): 66 if start is not None: 67 self._colorStart = Color.from_any(start) 68 if end is not None: 69 self._colorEnd = Color.from_any(end) 70 self._ReconstructControlPoints() 71 72 def Refresh(self): 73 self._ReconstructControlPoints() 74 75 def _ReconstructControlPoints(self): 76 self.Flush() 77 numPoints = self._GetNumPoints() 78 offset = min(0.01, self.angle / 4.0) 79 rangeSize = self.angle - 2.0 * offset 80 stepSize = rangeSize / float(numPoints) 81 self._AddPoint(self.startAngle - offset, self.colorStart.rgba) 82 for i in xrange(numPoints + 1): 83 t = self.startAngle + offset + float(i) * stepSize 84 color = geo2.Vec4Lerp(self.colorStart.rgba, self.colorEnd.rgba, i / float(numPoints)) 85 self._AddPoint(t, color) 86 87 self._AddPoint(t + 2 * offset, self.colorEnd.rgba) 88 89 def _GetNumPoints(self): 90 numPoints = 0.2 * self._radius * self.angle 91 numPoints = int(max(MIN_NUM_POINTS, numPoints)) 92 return numPoints 93 94 def _AddPoint(self, t, color): 95 point = self._GetLinePoint(t) 96 self.AddPoint(point, color=color) 97 98 def SetClockwise(self): 99 self.isClockwise = True 100 self._ReconstructControlPoints() 101 102 def SetCounterClockwise(self): 103 self.isClockwise = False 104 self._ReconstructControlPoints() 105 106 def _GetLinePoint(self, t): 107 if not self.isClockwise: 108 t = -t - math.pi 109 w = self.lineWidth / 2.0 110 r = self._radius - w 111 xPoint = w + r * (1.0 + math.cos(t)) 112 yPoint = w + r * (1.0 + math.sin(t)) 113 return (xPoint, yPoint) 114 115 @property 116 def value(self): 117 return self.GetValue() 118 119 @value.setter 120 def value(self, val): 121 self.SetValue(val) 122 123 def GetValue(self): 124 return self.end - self.start 125 126 def SetValue(self, value, duration = 0.0, sleep = False): 127 if value == self.end: 128 return 129 if not duration: 130 self.end = value 131 else: 132 animations.MorphScalar(self, 'end', self.end, value, duration=duration, sleep=sleep) 133 134 def SetLineWidth(self, value): 135 self.lineWidth = value 136 self._ReconstructControlPoints() 137 138 def OnClick(self, *args): 139 self.on_clicked(self.segmentID) 140 141 def OnMouseEnter(self, *args): 142 self.on_mouse_enter(self.segmentID) 143 animations.MorphScalar(self, 'glowBrightness', self.glowBrightness, 0.3, duration=uiconst.TIME_ENTRY) 144 145 def OnMouseExit(self, *args): 146 self.on_mouse_exit(self.segmentID) 147 animations.MorphScalar(self, 'glowBrightness', self.glowBrightness, 0.0, duration=uiconst.TIME_EXIT) 148 149 def LoadTooltipPanel(self, tooltipPanel, *args): 150 if not self.hint: 151 return None 152 tooltipPanel.LoadGeneric1ColumnTemplate() 153 tooltipPanel.AddLabelMedium(text=self.hint) 154 155 def GetTooltipPosition(self): 156 xp, yp = self.GetAbsolutePosition() 157 w, _ = self.GetAbsoluteSize() 158 x, y = self.GetOuterCenterPoint() 159 r = w / 2 160 return (xp + r + x, 161 yp + r + y, 162 0, 163 0) 164 165 def GetOuterCenterPoint(self, radiusScale = 1.0): 166 angle = self.GetCenterAngle() 167 return self._GetPoint(angle, radiusScale) 168 169 def GetPoint(self, value, radiusScale): 170 angle = self.startAngle + value * self.angle 171 return self._GetPoint(angle, radiusScale) 172 173 def _GetPoint(self, angle, radiusScale): 174 w, h = self.GetAbsoluteSize() 175 r = radiusScale * w / 2 176 x = r * math.cos(angle) 177 y = r * math.sin(angle) 178 return (x, y) 179 180 def GetOuterCenterPointAbsolute(self, radiusScale): 181 x, y = self.GetOuterCenterPoint(radiusScale) 182 l, t = self.GetAbsolutePosition() 183 w, h = self.GetAbsoluteSize() 184 x += l + w / 2.0 185 y += t + h / 2.0 186 return (x, y) 187 188 def GetCenterAngle(self): 189 startAngle = self.startAngle + self.angle * self.start 190 angle = startAngle + self.angle / 2 * (self.end - self.start) 191 return angle 192 193 def GetTooltipPointer(self): 194 angle = self.GetCenterAngle() 195 if angle < math.pi / 4: 196 return uiconst.POINT_LEFT_2 197 elif angle < 3 * math.pi / 4: 198 return uiconst.POINT_TOP_2 199 elif angle < 5 * math.pi / 4: 200 return uiconst.POINT_RIGHT_2 201 elif angle < 7 * math.pi / 4: 202 return uiconst.POINT_BOTTOM_2 203 else: 204 return uiconst.POINT_LEFT_2 205 206 def SetRadius(self, radius): 207 self._radius = radius 208 self.width = self.height = 2 * radius 209 self._ReconstructControlPoints() 210 self.SetValue(self.end)