Class: Color

Inherits:
Object
  • Object
show all
Defined in:
lib/openrgss/color.rb

Overview

The RGBA color class. Each component is handled with a floating-point value (Float).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(red = 0, green = 0, blue = 0, alpha = 255) ⇒ Color

:call-seq: Color.new(red, green, blue[, alpha]) Color.new

Creates a Color object. If alpha is omitted, it is assumed to be 255.

The default values when no arguments are specified are (0, 0, 0, 0).



12
13
14
15
16
17
# File 'lib/openrgss/color.rb', line 12

def initialize(red=0, green=0, blue=0, alpha = 255)
  @red   = red
  @blue  = blue
  @green = green
  @alpha = alpha
end

Instance Attribute Details

#alphaObject

The alpha value (0-255). Out-of-range values are automatically corrected.



53
54
55
# File 'lib/openrgss/color.rb', line 53

def alpha
  @alpha
end

#blueObject

The green value (0-255). Out-of-range values are automatically corrected.



47
48
49
# File 'lib/openrgss/color.rb', line 47

def blue
  @blue
end

#greenObject

The blue value (0-255). Out-of-range values are automatically corrected.



50
51
52
# File 'lib/openrgss/color.rb', line 50

def green
  @green
end

#redObject

The red value (0-255). Out-of-range values are automatically corrected.



44
45
46
# File 'lib/openrgss/color.rb', line 44

def red
  @red
end

Class Method Details

._load(string) ⇒ Object

:nodoc:



63
64
65
# File 'lib/openrgss/color.rb', line 63

def self._load(string) # :nodoc:
  self.new(*string.unpack('D*')) #fix by zh99998
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:

Raises:

  • (TypeError)


83
84
85
86
87
88
89
# File 'lib/openrgss/color.rb', line 83

def ==(other) # :nodoc:
  raise TypeError.new("can't convert #{other.class} into Color") unless self.class == other.class
  return @red == other.red &&
      @green == other.green &&
      @blue == other.blue &&
      @alpha == other.alpha
end

#===(other) ⇒ Object

:nodoc:

Raises:

  • (TypeError)


91
92
93
94
95
96
97
# File 'lib/openrgss/color.rb', line 91

def ===(other) # :nodoc:
  raise TypeError.new("can't convert #{other.class} into Color") unless self.class == other.class
  return @red == other.red &&
      @green == other.green &&
      @blue == other.blue &&
      @alpha == other.alpha
end

#_dump(depth = 0) ⇒ Object

:nodoc:



59
60
61
# File 'lib/openrgss/color.rb', line 59

def _dump(depth = 0) # :nodoc:
  [@red, @green, @blue, @alpha].pack('D*')
end

#egl?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)

Raises:

  • (TypeError)


99
100
101
102
103
104
105
# File 'lib/openrgss/color.rb', line 99

def egl?(other) # :nodoc:
  raise TypeError.new("can't convert #{other.class} into Color") unless self.class == other.class
  return @red == other.red &&
      @green == other.green &&
      @blue == other.blue &&
      @alpha == other.alpha
end

#set(red, blue = 0, green = 0, alpha = 255) ⇒ Object

:call-seq: set(red, green, blue[, alpha]) set(color)

Sets all components at once.

The second format copies all the components from a separate Color object.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/openrgss/color.rb', line 27

def set(red, blue=0, green=0, alpha = 255)
  if red.is_a? Color
    color  = red
    @red   = color.red
    @blue  = color.blue
    @green = color.green
    @alpha = color.alpha
  else
    @red   = red
    @blue  = blue
    @green = green
    @alpha = alpha
  end
  return self
end

#to_sObject

:nodoc:



55
56
57
# File 'lib/openrgss/color.rb', line 55

def to_s() # :nodoc:
  "(#{@red}, #{@blue}, #{@green}, #{@alpha})"
end