| | 1296 | # Add it to the list of drawing objects |
|---|
| | 1297 | obj = self._addToDrawnObjects(obj, persist) |
|---|
| | 1298 | return obj |
|---|
| | 1299 | |
|---|
| | 1300 | |
|---|
| | 1301 | def drawPolyLines(self, points, penColor="black", penWidth=1, |
|---|
| | 1302 | lineStyle=None, mode=None, persist=True): |
|---|
| | 1303 | """Draws a series of connected line segments defined by the specified points. |
|---|
| | 1304 | |
|---|
| | 1305 | The 'points' parameter should be a tuple of (x,y) pairs defining the shape. Lines |
|---|
| | 1306 | are drawn connecting the points sequentially, but a segment from the last |
|---|
| | 1307 | point to the first is not drawn, leaving an 'open' polygon. As a result, there is no |
|---|
| | 1308 | FillColor or HatchStyle defined for this. |
|---|
| | 1309 | |
|---|
| | 1310 | See the 'drawCircle()' method above for more details. |
|---|
| | 1311 | """ |
|---|
| | 1312 | obj = DrawObject(self, PenColor=penColor, PenWidth=penWidth, LineStyle=lineStyle, |
|---|
| | 1313 | Shape="polylines", Points=points, DrawMode=mode) |
|---|
| 2705 | | elif self.Shape == "polygon": |
|---|
| 2706 | | dc.DrawPolygon(self.Points) |
|---|
| | 2725 | elif self.Shape in ("polygon", "polylines"): |
|---|
| | 2726 | if self.Shape == "polygon": |
|---|
| | 2727 | dc.DrawPolygon(self.Points) |
|---|
| | 2728 | else: |
|---|
| | 2729 | dc.DrawLines(self.Points) |
|---|
| | 2730 | xs = [pt[0] for pt in self.Points] |
|---|
| | 2731 | ys = [pt[1] for pt in self.Points] |
|---|
| | 2732 | self._xPos = min(xs) |
|---|
| | 2733 | self._yPos = min(ys) |
|---|
| | 2734 | self._width = max(xs) - self._xPos |
|---|
| | 2735 | self._height = max(ys) - self._yPos |
|---|
| | 2783 | w, h = dabo.ui.fontMetricFromDrawObject(self) |
|---|
| | 2784 | angle = self._angle % 360 |
|---|
| | 2785 | if angle % 90 == 0: |
|---|
| | 2786 | if angle % 180 == 0: |
|---|
| | 2787 | self._width, self._height = w, h |
|---|
| | 2788 | else: |
|---|
| | 2789 | # 90 degree variant; switch the values. |
|---|
| | 2790 | self._width, self._height = h, w |
|---|
| | 2791 | else: |
|---|
| | 2792 | rad = math.radians(angle) |
|---|
| | 2793 | self._width = abs(math.cos(rad) * w) + abs(math.sin(rad) * h) |
|---|
| | 2794 | self._height = abs(math.sin(rad) * w) + abs(math.cos(rad) * h) |
|---|
| 3034 | | |
|---|
| 3035 | | |
|---|
| | 3088 | |
|---|
| | 3089 | |
|---|
| | 3090 | def _getRect(self): |
|---|
| | 3091 | x, y, w, h = self._xPos, self._yPos, self._width, self._height |
|---|
| | 3092 | if self._shape == "circle": |
|---|
| | 3093 | # x and y are the center, so correct for that. |
|---|
| | 3094 | x = x - self._radius |
|---|
| | 3095 | y = y - self._radius |
|---|
| | 3096 | elif (self._shape == "text") and (self._angle % 360 != 0): |
|---|
| | 3097 | tw, th = dabo.ui.fontMetricFromDrawObject(self) |
|---|
| | 3098 | angle = self._angle % 360 |
|---|
| | 3099 | if 0 < angle <= 90: |
|---|
| | 3100 | rad = math.radians(angle) |
|---|
| | 3101 | cos = math.cos(rad) |
|---|
| | 3102 | y -= (h - cos*th) |
|---|
| | 3103 | elif 90 < angle <= 180: |
|---|
| | 3104 | rad = math.radians(90 - angle) |
|---|
| | 3105 | cos = math.cos(rad) |
|---|
| | 3106 | y -= h |
|---|
| | 3107 | x -= (w - cos*th) |
|---|
| | 3108 | elif 180 < angle <= 270: |
|---|
| | 3109 | rad = math.radians(180 - angle) |
|---|
| | 3110 | cos = math.cos(rad) |
|---|
| | 3111 | y -= cos*th |
|---|
| | 3112 | x -= w |
|---|
| | 3113 | else: |
|---|
| | 3114 | rad = math.radians(270 - angle) |
|---|
| | 3115 | cos = math.cos(rad) |
|---|
| | 3116 | x -= cos*th |
|---|
| | 3117 | return wx.Rect(x, y, w, h) |
|---|
| | 3118 | |
|---|
| | 3119 | |
|---|
| | 3120 | def _getSize(self): |
|---|
| | 3121 | return (self._width, self._height) |
|---|
| | 3122 | |
|---|
| | 3123 | def _setSize(self, val): |
|---|
| | 3124 | if (self._width, self._height) != val: |
|---|
| | 3125 | self._width, self._height = val |
|---|
| | 3126 | self.update() |
|---|
| | 3127 | |
|---|
| | 3128 | |
|---|