MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / Draw

Method Draw

graphs/gui/vector.py:113–154  ·  view source on GitHub ↗
(self, dc)

Source from the content-addressed store, hash-verified

111 return tuple([dim / self.GetContentScaleFactor() for dim in self.GetClientSize()])
112
113 def Draw(self, dc):
114 width, height = self.GetScaledClientSize()
115 if not width or not height:
116 return
117 dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.BRUSHSTYLE_SOLID))
118 dc.Clear()
119 dc.SetTextForeground(wx.Colour(0))
120 dc.SetFont(self._font)
121
122 radius = min(width, height) / 2 - 2
123 dc.SetBrush(wx.WHITE_BRUSH)
124 dc.DrawCircle(round(radius + 2), round(radius + 2), round(radius))
125 a = math.radians(self._angle + self._offset)
126 x = math.cos(a) * radius
127 y = math.sin(a) * radius
128 # See PR #2260 on why this is needed
129 pointRadius = 2 / self.GetContentScaleFactor() if 'wxGTK' in wx.PlatformInfo else 2
130 dc.DrawLine(
131 round(radius + 2), round(radius + 2),
132 round(radius + 2 + x * self._length), round(radius + 2 - y * self._length))
133 dc.SetBrush(wx.BLACK_BRUSH)
134 dc.DrawCircle(round(radius + 2 + x * self._length), round(radius + 2 - y * self._length), round(pointRadius))
135
136 if self._label:
137 labelText = self._label
138 labelTextW, labelTextH = dc.GetTextExtent(labelText)
139 labelTextX = (radius * 2 + 4 - labelTextW) if (self._labelpos & 1) else 0
140 labelTextY = (radius * 2 + 4 - labelTextH) if (self._labelpos & 2) else 0
141 dc.DrawText(labelText, round(labelTextX), round(labelTextY))
142
143 if not self._directionOnly:
144 lengthText = '%d%%' % (100 * self._length,)
145 lengthTextW, lengthTextH = dc.GetTextExtent(lengthText)
146 lengthTextX = radius + 2 + x / 2 - y / 3 - lengthTextW / 2
147 lengthTextY = radius + 2 - y / 2 - x / 3 - lengthTextH / 2
148 dc.DrawText(lengthText, round(lengthTextX), round(lengthTextY))
149
150 angleText = '%d\u00B0' % (self._angle,)
151 angleTextW, angleTextH = dc.GetTextExtent(angleText)
152 angleTextX = radius + 2 - x / 2 - angleTextW / 2
153 angleTextY = radius + 2 + y / 2 - angleTextH / 2
154 dc.DrawText(angleText, round(angleTextX), round(angleTextY))
155
156 def OnEraseBackground(self, event):
157 pass

Callers 2

OnPaintMethod · 0.95
MakeSnapshotMethod · 0.80

Calls 3

GetScaledClientSizeMethod · 0.95
DrawTextMethod · 0.80
ClearMethod · 0.45

Tested by

no test coverage detected