Method: MotionPrime::ImageDrawElement#draw_in_context

Defined in:
motion-prime/elements/draw/image.rb

#draw_in_context(context) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'motion-prime/elements/draw/image.rb', line 26

def draw_in_context(context)
  return if computed_options[:hidden]

  draw_background_in_context(context)
  options = draw_options
  return unless image = options[:image]

  border_width = options[:border_width]
  inset = border_width > 0 ? (border_width - 1 ).abs*0.5 : 0
  rect = CGRectInset(options[:rect], inset, inset)
  radius = options[:corner_radius].to_f if options[:corner_radius] && options[:masks_to_bounds]

  UIGraphicsPushContext(context)
  if radius
    CGContextBeginPath(context)
    CGContextAddArc(context, rect.origin.x + rect.size.width/2, rect.origin.y + rect.size.height/2, radius, 0, 2*Math::PI, 0) # FIXME
    CGContextClosePath(context)
    CGContextSaveGState(context)
    CGContextClip(context)
    image.drawInRect(rect)
    CGContextRestoreGState(context)
  else
    image.drawInRect(rect)
  end
  UIGraphicsPopContext()
end