Sha256: 1d5d8d6587b14ca41b03ea07b3970909e4b60c606ac54f59f435c8fbc0153390

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module MotionPrime
  module DrawBackgroundMixin
    def draw_background_in(draw_rect, options)
      bg_color = options[:background_color]
      border_radius = options[:layer].try(:[], :corner_radius)
      border_width = options[:layer].try(:[], :border_width).to_f
      border_color = options[:layer].try(:[], :border_color) || bg_color || :black

      if bg_color || border_width > 0
        inset = border_width > 0 ? (border_width - 1 )*0.5 : 0
        rect = CGRectInset(draw_rect, -inset, -inset)
        if border_radius
          bezierPath = UIBezierPath.bezierPathWithRoundedRect rect, cornerRadius: border_radius
          if border_width > 0
            bezierPath.lineWidth = border_width
            border_color.uicolor.setStroke
            bezierPath.stroke
          end
          if bg_color
            bg_color.uicolor.setFill
            bezierPath.fill
          end
        else
          context = UIGraphicsGetCurrentContext()
          if border_width > 0 && border_color
            CGContextSetLineWidth(context, border_width)
            CGContextSetStrokeColorWithColor(context, border_color.uicolor.cgcolor)
            CGContextStrokeRect(context, rect)
          end
          CGContextSetFillColorWithColor(context, bg_color.uicolor.cgcolor) if bg_color
          CGContextFillRect(context, rect) if bg_color
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-prime-0.4.3 motion-prime/elements/draw/_draw_background_mixin.rb