Sha256: bf9631b5cad93cb9c2de0a3f699e89134fcb63086ee32b9e69046c9e372a874c

Contents?: true

Size: 811 Bytes

Versions: 9

Compression:

Stored size: 811 Bytes

Contents

module UI
  class Color
    def self._native?(color)
      color.is_a?(UIColor)
    end

    def self.rgba(r, g, b, a)
      new UIColor.colorWithRed(r/255.0, green:g/255.0, blue:b/255.0, alpha:a/255.0)
    end

    def to_a
      @ary_values ||= begin
        red_ptr = Pointer.new(:double)
        green_ptr = Pointer.new(:double)
        blue_ptr = Pointer.new(:double)
        alpha_ptr = Pointer.new(:double)

        if proxy.getRed(red_ptr, green:green_ptr, blue:blue_ptr, alpha:alpha_ptr)
          [red_ptr[0], green_ptr[0], blue_ptr[0], alpha_ptr[0]]
        else
          [0, 0, 0, 0]
        end.map { |x| (x * 255.0).round}
      end
    end

    def red
      to_a[0]
    end

    def green
      to_a[1]
    end

    def blue
      to_a[2]
    end

    def alpha
      to_a[3]
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
motion-flow-0.1.8 flow/ui/cocoa/color.rb
motion-flow-0.1.7 flow/ui/cocoa/color.rb
motion-flow-0.1.6 flow/ui/cocoa/color.rb
motion-flow-0.1.5 flow/ui/cocoa/color.rb
motion-flow-0.1.4 flow/ui/cocoa/color.rb
motion-flow-0.1.3 flow/ui/cocoa/color.rb
motion-flow-0.1.2 flow/ui/cocoa/color.rb
motion-flow-0.1.1 flow/ui/cocoa/color.rb
motion-flow-0.1 flow/ui/cocoa/color.rb