Exemplo n.º 1
0
  def draw(self, context):
    '''
    Draw self using context.
    Return bounds in DCS for later use to invalidate.
    
    !!! This is the primitive draw.  See also composite.draw().
    
    !!! Transform and style must already be in the context CTM.
    My parent transforms and styles me.
    '''
 
    self.put_path_to(context) # recursive, except this should be terminal!!!
    
    # Self is glyph.  Parent morph holds style.
    # Alters transform, so save
    context.save()
    style.set_line_width(context, self.parent.style.pen_width)
        
    self.bounds = self.get_stroke_bounds(context) # Cache drawn bounds
    
    # !!! Parent knows whether my style filled
    if self.parent.style.is_filled():
      context.fill()  # Filled, up to path
    else:
      context.stroke()  # Outline, with line width
    context.restore()
    # Assert fill or stroke clears paths from context
    # NOT assert context.restore() follows soon: may be one of siblings.
    return self.bounds.copy()   # Return reference to copy, not self
Exemplo n.º 2
0
    def draw(self, context):
        '''
    Draw self using context.
    Return bounds in DCS for later use to invalidate.
    
    !!! This is the primitive draw.  See also composite.draw().
    
    !!! Transform and style must already be in the context CTM.
    My parent transforms and styles me.
    '''

        self.put_path_to(
            context)  # recursive, except this should be terminal!!!

        # Self is glyph.  Parent morph holds style.
        # Alters transform, so save
        context.save()
        style.set_line_width(context, self.parent.style.pen_width)

        self.bounds = self.get_stroke_bounds(context)  # Cache drawn bounds

        # !!! Parent knows whether my style filled
        if self.parent.style.is_filled():
            context.fill()  # Filled, up to path
        else:
            context.stroke()  # Outline, with line width
        context.restore()
        # Assert fill or stroke clears paths from context
        # NOT assert context.restore() follows soon: may be one of siblings.
        return self.bounds.copy()  # Return reference to copy, not self
Exemplo n.º 3
0
 def in_path(self, context, coords):
     '''
 Does coords hit *ideal* edge of this drawable?
 Contrast to in_stroke.
 '''
     # !!! pen_width approaching zero
     style.set_line_width(context, 1)  # !!! After path
     # Cairo does not have in_path()
     return context.in_stroke(coords.x, coords.y)
Exemplo n.º 4
0
 def in_path(self, context, coords):
   '''
   Does coords hit *ideal* edge of this drawable?
   Contrast to in_stroke.
   '''
   # !!! pen_width approaching zero
   style.set_line_width(context, 1)  # !!! After path
   # Cairo does not have in_path()
   return context.in_stroke(coords.x, coords.y)
Exemplo n.º 5
0
 def pick(self, context, point):
     self.put_path_to(context)
     # Pick width is user preference or constant.
     # Does NOT depend on style of the object.  WAS self.parent.style.pen_width
     style.set_line_width(context, PENSOOL_PICK_PEN_WIDTH)  # !!! After path
     if context.in_stroke(*context.device_to_user(point.x, point.y)):
         return self.parent  # !!! Don't return a glyph, return glyph's parent morph
     else:
         return None
Exemplo n.º 6
0
 def in_stroke(self, coords):
   '''
   Does coords hit edge of this drawable?
   Stroke: hit on inked, visible.
   Edge: not including possible interior features, just the hittable boundary.
   Distinguish from a bounding box, which is a rectangle in DCS.
   '''
   context, point = self._prepare_for_picking(coords)
   # Assert cairo holds the path in DCS, point is in UCS
   # Use actual pen width. This alters the context, BUT NOT the path.
   style.set_line_width(context, self.parent.style.pen_width)  # !!! After path
   #print "Line width", context.get_line_width(), "Stroke extents", context.stroke_extents(), "Coords ", point, "Parent ", self.parent
   # context.get_line_width()
   # April 2011 lkk This cruft is here because there was flakiness:
   # Manifests itself as not picking on scroll in the Move handle item.
   # Not reliably reproducible: depends on what seemingly irrelevant code (like @dump_return)
   # or the above context.get_line_width() is in place.
   # I installed the latest cairo and pixmand (but not the latest pycairo) and now it MIGHT be working.
   value = context.in_stroke(point.x, point.y)
   return value
Exemplo n.º 7
0
 def in_stroke(self, coords):
     '''
 Does coords hit edge of this drawable?
 Stroke: hit on inked, visible.
 Edge: not including possible interior features, just the hittable boundary.
 Distinguish from a bounding box, which is a rectangle in DCS.
 '''
     context, point = self._prepare_for_picking(coords)
     # Assert cairo holds the path in DCS, point is in UCS
     # Use actual pen width. This alters the context, BUT NOT the path.
     style.set_line_width(context,
                          self.parent.style.pen_width)  # !!! After path
     #print "Line width", context.get_line_width(), "Stroke extents", context.stroke_extents(), "Coords ", point, "Parent ", self.parent
     # context.get_line_width()
     # April 2011 lkk This cruft is here because there was flakiness:
     # Manifests itself as not picking on scroll in the Move handle item.
     # Not reliably reproducible: depends on what seemingly irrelevant code (like @dump_return)
     # or the above context.get_line_width() is in place.
     # I installed the latest cairo and pixmand (but not the latest pycairo) and now it MIGHT be working.
     value = context.in_stroke(point.x, point.y)
     return value