class Glimmer::SWT::ColorProxy
Proxy for org.eclipse.swt.graphics.Color
Invoking `#swt_color` returns the SWT
Color object wrapped by this proxy
Follows the Proxy Design Pattern
Constants
- SWT_COLOR_TRANSLATION
Attributes
alpha[R]
args[R]
blue[R]
green[R]
red[R]
Public Class Methods
new(*args)
click to toggle source
Initializes a proxy for an SWT
Color object
Takes a standard color single argument, rgba 3 args, or rgba 4 args
A standard color is a string/symbol representing one of the SWT
.COLOR_*** constants like SWT
.COLOR_RED, but in underscored string format (e.g :color_red). Glimmer
can also accept standard color names without the color_ prefix, and it will automatically figure out the SWT
.COLOR_*** constant (e.g. :red)
rgb is 3 arguments representing Red, Green, Blue numeric values
rgba is 4 arguments representing Red, Green, Blue, and Alpha numeric values
# File lib/glimmer/swt/color_proxy.rb, line 89 def initialize(*args) @args = args case @args.size when 1 @alpha = nil if @args.first.is_a?(String) || @args.first.is_a?(Symbol) standard_color = @args.first.to_s.downcase.sub('COLOR_', '') @red, @green, @blue = SWT_COLOR_TRANSLATION[standard_color] else @red, @green, @blue = [0, 0, 0] end when 3..4 @red, @green, @blue, @alpha = @args end end
Public Instance Methods
alpha_css()
click to toggle source
# File lib/glimmer/swt/color_proxy.rb, line 113 def alpha_css alpha.to_f / 255 end
to_css()
click to toggle source
# File lib/glimmer/swt/color_proxy.rb, line 105 def to_css if alpha.nil? "rgb(#{red}, #{green}, #{blue})" else "rgba(#{red}, #{green}, #{blue}, #{alpha_css})" end end