Changeset 1002
- Timestamp:
- 09/08/06 03:14:48 (2 years ago)
- Files:
-
- gaphas/trunk/ChangeLog (modified) (1 diff)
- gaphas/trunk/demo.py (modified) (1 diff)
- gaphas/trunk/gaphas/examples.py (modified) (1 diff)
- gaphas/trunk/gaphas/item.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/trunk/ChangeLog
r1001 r1002 1 2006-09-08 Arjan Molenaar <arjan_at_yirdis_dot_nl> 2 3 * item.py: Implemented arrow heads on Line elements. 4 1 5 2006-09-07 Arjan Molenaar <arjan_at_yirdis_dot_nl> 2 6 gaphas/trunk/demo.py
r1001 r1002 25 25 """Line with experimental connection protocol. 26 26 """ 27 pass 27 28 def draw_head(self, context): 29 cr = context.cairo 30 cr.move_to(0, 0) 31 cr.line_to(10, 10) 32 cr.stroke() 33 # Start point for the line to the next handle 34 cr.move_to(0, 0) 35 36 def draw_tail(self, context): 37 cr = context.cairo 38 cr.line_to(0, 0) 39 cr.line_to(10, 10) 40 cr.stroke() 41 28 42 29 43 gaphas/trunk/gaphas/examples.py
r1001 r1002 93 93 # Transform distance to world coordinates 94 94 distance, dumy = matrix_i2w(i).transform_distance(distance, 0) 95 if distance < glue_distance:95 if distance <= glue_distance: 96 96 glue_distance = distance 97 97 glue_point = matrix_i2w(i).transform_point(*point) gaphas/trunk/gaphas/item.py
r999 r1002 5 5 __version__ = "$Revision$" 6 6 # $HeadURL$ 7 8 from math import atan2 7 9 8 10 from geometry import Matrix, distance_line_point, distance_rectangle_point … … 323 325 h = self._handles 324 326 hnw, hse = h[NW], h[SE] 325 #print ((hnw.x, hnw.y, hse.x, hse.y), (x, y)), \326 #distance_rectangle_point((hnw.x, hnw.y, hse.x, hse.y), (x, y))327 327 return distance_rectangle_point(map(float, (hnw.x, hnw.y, hse.x, hse.y)), (x, y)) 328 328 … … 337 337 (only straight angles) 338 338 - line_width: width of the line to be drawn 339 340 This line also supports arrow heads on both the begin and end of the 341 line. These are drawn with the methods draw_head(context) and 342 draw_tail(context). The coordinate system is altered so the methods do 343 not have to know about the angle of the line segment (e.g. drawing a line 344 from (10, 10) via (0, 0) to (10, -10) will draw an arrow point). 339 345 """ 340 346 … … 346 352 self.fuzzyness = 0 347 353 self._orthogonal = [] 354 self._head_angle = self._tail_angle = 0 348 355 349 356 def _set_orthogonal(self, orthogonal): … … 372 379 cons.append(add(eq(a=h0.y, b=h1.y))) 373 380 self.canvas.solver.mark_dirty(h1.x, h1.y) 374 # Mark first handle dirty, forcing recalculayion 375 print 'updated ortho constraints' 376 #self.canvas.solver.mark_dirty(self._handles[0].x, self._handles[0].y) 377 381 self.request_update() 382 378 383 orthogonal = property(lambda s: s._orthogonal != [], _set_orthogonal) 379 384 … … 461 466 raise KeyError('Handle is not an end handle') 462 467 468 def update(self, context): 469 """ 470 """ 471 super(Line, self).update(context) 472 h0, h1 = self._handles[:2] 473 self._head_angle = atan2(h1.y - h0.y, h1.x - h0.x) 474 h1, h0 = self._handles[-2:] 475 self._tail_angle = atan2(h1.y - h0.y, h1.x - h0.x) 476 463 477 def _closest_segment(self, x, y): 464 478 """Obtain a tuple (distance, point_on_line, segment). … … 495 509 return max(0, distance - self.fuzzyness) 496 510 497 def _draw_line(self, context): 511 def draw_head(self, context): 512 """Default head drawer: move cursor to the first handle. 513 """ 514 context.cairo.move_to(0, 0) 515 516 def draw_tail(self, context): 517 """Default tail drawer: draw line to the last handle. 518 """ 519 context.cairo.line_to(0, 0) 520 521 522 def draw(self, context): 498 523 """Draw the line itself. 499 """ 500 c = context.cairo 501 h = self._handles[0] 502 c.set_line_width(self.line_width) 503 c.move_to(float(h.x), float(h.y)) 504 for h in self._handles[1:]: 505 c.line_to(float(h.x), float(h.y)) 506 c.stroke() 507 508 def draw(self, context): 509 """See Item.draw(context). 510 """ 511 self._draw_line(context) 524 See Item.draw(context). 525 """ 526 def draw_line_end(handle, angle, draw): 527 cr = context.cairo 528 cr.save() 529 try: 530 cr.translate(handle.x, handle.y) 531 cr.rotate(angle) 532 draw(context) 533 finally: 534 cr.restore() 535 cr = context.cairo 536 cr.set_line_width(self.line_width) 537 draw_line_end(self._handles[0], self._head_angle, self.draw_head) 538 for h in self._handles[1:-1]: 539 cr.line_to(float(h.x), float(h.y)) 540 h0, h1 = self._handles[-2:] 541 draw_line_end(self._handles[-1], self._tail_angle, self.draw_tail) 542 cr.stroke() 512 543 513 544
