Sha256: 97c2e0559c5f01dc98f42b3f9cc69c4e3a52ce87eac839ebcc4caa7f9552eff8

Contents?: true

Size: 1.35 KB

Versions: 42

Compression:

Stored size: 1.35 KB

Contents

module MotionPrime
  module DrawBackgroundMixin
    def draw_background_in_context(context = nil)
      context ||= UIGraphicsGetCurrentContext()
      options = draw_options
      rect, background_color, border_width, border_color, corner_radius = options.slice(:rect, :background_color, :border_width, :border_color, :corner_radius).values

      return unless background_color || border_width > 0

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

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
motion-prime-1.0.2 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-1.0.1 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-1.0.0 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.9.2 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.9.1 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.9 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.8 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.7 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.6 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.5 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.4 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.3 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.2 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.1 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.9.0 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.8.12 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.8.11 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.8.10 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.8.9 motion-prime/elements/draw/_draw_background_mixin.rb
motion-prime-0.8.8 motion-prime/elements/draw/_draw_background_mixin.rb