From: Marius Gedminas <marius@gedmin.as>
... | ... |
@@ -85,6 +85,14 @@ class Shape: |
85 | 85 |
"""Draw this shape with the given cairo context""" |
86 | 86 |
raise NotImplementedError |
87 | 87 |
|
88 |
+ def select_pen(self, highlight): |
|
89 |
+ if highlight: |
|
90 |
+ if not hasattr(self, 'highlight_pen'): |
|
91 |
+ self.highlight_pen = self.pen.highlighted() |
|
92 |
+ return self.highlight_pen |
|
93 |
+ else: |
|
94 |
+ return self.pen |
|
95 |
+ |
|
88 | 96 |
|
89 | 97 |
class TextShape(Shape): |
90 | 98 |
|
... | ... |
@@ -164,7 +172,7 @@ class TextShape(Shape): |
164 | 172 |
|
165 | 173 |
cr.save() |
166 | 174 |
cr.scale(f, f) |
167 |
- cr.set_source_rgba(*self.pen.color) |
|
175 |
+ cr.set_source_rgba(*self.select_pen(highlight).color) |
|
168 | 176 |
cr.show_layout(layout) |
169 | 177 |
cr.restore() |
170 | 178 |
|
... | ... |
@@ -187,7 +195,6 @@ class EllipseShape(Shape): |
187 | 195 |
def __init__(self, pen, x0, y0, w, h, filled=False): |
188 | 196 |
Shape.__init__(self) |
189 | 197 |
self.pen = pen.copy() |
190 |
- self.highlight_pen = pen.highlighted() |
|
191 | 198 |
self.x0 = x0 |
192 | 199 |
self.y0 = y0 |
193 | 200 |
self.w = w |
... | ... |
@@ -201,10 +208,7 @@ class EllipseShape(Shape): |
201 | 208 |
cr.move_to(1.0, 0.0) |
202 | 209 |
cr.arc(0.0, 0.0, 1.0, 0, 2.0*math.pi) |
203 | 210 |
cr.restore() |
204 |
- if highlight: |
|
205 |
- pen = self.highlight_pen |
|
206 |
- else: |
|
207 |
- pen = self.pen |
|
211 |
+ pen = self.select_pen(highlight) |
|
208 | 212 |
if self.filled: |
209 | 213 |
cr.set_source_rgba(*pen.fillcolor) |
210 | 214 |
cr.fill() |
... | ... |
@@ -229,14 +233,15 @@ class PolygonShape(Shape): |
229 | 233 |
for x, y in self.points: |
230 | 234 |
cr.line_to(x, y) |
231 | 235 |
cr.close_path() |
236 |
+ pen = self.select_pen(highlight) |
|
232 | 237 |
if self.filled: |
233 |
- cr.set_source_rgba(*self.pen.fillcolor) |
|
238 |
+ cr.set_source_rgba(*pen.fillcolor) |
|
234 | 239 |
cr.fill_preserve() |
235 | 240 |
cr.fill() |
236 | 241 |
else: |
237 |
- cr.set_dash(self.pen.dash) |
|
238 |
- cr.set_line_width(self.pen.linewidth) |
|
239 |
- cr.set_source_rgba(*self.pen.color) |
|
242 |
+ cr.set_dash(pen.dash) |
|
243 |
+ cr.set_line_width(pen.linewidth) |
|
244 |
+ cr.set_source_rgba(*pen.color) |
|
240 | 245 |
cr.stroke() |
241 | 246 |
|
242 | 247 |
|
... | ... |
@@ -255,9 +260,10 @@ class BezierShape(Shape): |
255 | 260 |
x2, y2 = self.points[i + 1] |
256 | 261 |
x3, y3 = self.points[i + 2] |
257 | 262 |
cr.curve_to(x1, y1, x2, y2, x3, y3) |
258 |
- cr.set_dash(self.pen.dash) |
|
259 |
- cr.set_line_width(self.pen.linewidth) |
|
260 |
- cr.set_source_rgba(*self.pen.color) |
|
263 |
+ pen = self.select_pen(highlight) |
|
264 |
+ cr.set_dash(pen.dash) |
|
265 |
+ cr.set_line_width(pen.linewidth) |
|
266 |
+ cr.set_source_rgba(*pen.color) |
|
261 | 267 |
cr.stroke() |
262 | 268 |
|
263 | 269 |
|