Class: Rabbit::Renderer::Color

Inherits:
Struct
  • Object
show all
Defined in:
lib/rabbit/renderer/color.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Color

Returns a new instance of Color.


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rabbit/renderer/color.rb', line 14

def initialize(*args)
  case args.collect(&:class)
  when [Gdk::RGBA]
    rgba = args[0]
    super(*rgba.to_a)
  when [String]
    rgba = parse(args[0])
    super(*rgba)
  else
    super(*args)
  end
end

Instance Attribute Details

#alphaObject

Returns the value of attribute alpha

Returns:

  • (Object)

    the current value of alpha


7
8
9
# File 'lib/rabbit/renderer/color.rb', line 7

def alpha
  @alpha
end

#blueObject

Returns the value of attribute blue

Returns:

  • (Object)

    the current value of blue


7
8
9
# File 'lib/rabbit/renderer/color.rb', line 7

def blue
  @blue
end

#greenObject

Returns the value of attribute green

Returns:

  • (Object)

    the current value of green


7
8
9
# File 'lib/rabbit/renderer/color.rb', line 7

def green
  @green
end

#redObject

Returns the value of attribute red

Returns:

  • (Object)

    the current value of red


7
8
9
# File 'lib/rabbit/renderer/color.rb', line 7

def red
  @red
end

Class Method Details

.parse(*args) ⇒ Object


9
10
11
# File 'lib/rabbit/renderer/color.rb', line 9

def parse(*args)
  new(*args)
end

Instance Method Details

#to_aObject


32
33
34
# File 'lib/rabbit/renderer/color.rb', line 32

def to_a
  [red, green, blue, alpha]
end

#to_css_rgbaObject


44
45
46
47
48
49
50
# File 'lib/rabbit/renderer/color.rb', line 44

def to_css_rgba
  red_percent = (red * 100).ceil
  green_percent = (green * 100).ceil
  blue_percent = (blue * 100).ceil
  a = alpha || 1.0
  "rgba(#{red_percent}%, #{green_percent}%, #{blue_percent}%, #{a})"
end

#to_gdk_formatObject


40
41
42
# File 'lib/rabbit/renderer/color.rb', line 40

def to_gdk_format
  to_s
end

#to_gdk_rgbaObject


36
37
38
# File 'lib/rabbit/renderer/color.rb', line 36

def to_gdk_rgba
  Gdk::RGBA.new(*to_a)
end

#to_sObject


27
28
29
30
# File 'lib/rabbit/renderer/color.rb', line 27

def to_s
  values = to_a.collect {|x| (x * 65535).ceil}
  "#%04X%04X%04X%04X" % values
end