Class: Tone

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

Overview

The color tone 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, gray = 0) ⇒ Tone

:call-seq: Tone.new(red, green, blue[, gray]) Tone.new

Creates a Tone object. If gray is omitted, it is assumed to be 0.

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



27
28
29
# File 'lib/openrgss/tone.rb', line 27

def initialize(red = 0, green = 0, blue = 0, gray = 0)
  self.red, self.green, self.blue, self.gray = red, green, blue, gray
end

Instance Attribute Details

#blueObject

The blue balance adjustment value (-255 to 255). Out-of-range values are automatically corrected.



12
13
14
# File 'lib/openrgss/tone.rb', line 12

def blue
  @blue
end

#grayObject

The grayscale filter strength (0 to 255). Out-of-range values are automatically corrected.

When this value is not 0, processing time is significantly longer than when using tone balance adjustment values alone.



17
18
19
# File 'lib/openrgss/tone.rb', line 17

def gray
  @gray
end

#greenObject

The green balance adjustment value (-255 to 255). Out-of-range values are automatically corrected.



9
10
11
# File 'lib/openrgss/tone.rb', line 9

def green
  @green
end

#redObject

The red balance adjustment value (-255 to 255). Out-of-range values are automatically corrected.



6
7
8
# File 'lib/openrgss/tone.rb', line 6

def red
  @red
end

Class Method Details

._load(data) ⇒ Object

:nodoc:



92
93
94
# File 'lib/openrgss/tone.rb', line 92

def self._load(data) # :nodoc:
  new(*data.unpack('E4'))
end

Instance Method Details

#_dump(marshal_depth = -1)) ⇒ Object

:nodoc:



88
89
90
# File 'lib/openrgss/tone.rb', line 88

def _dump(marshal_depth = -1) # :nodoc:
  [@red, @green, @blue, @gray].pack('E4')
end

#blend(tone) ⇒ Object

:nodoc:



76
77
78
# File 'lib/openrgss/tone.rb', line 76

def blend(tone) # :nodoc:
  self.clone.blend!(tone)
end

#blend!(tone) ⇒ Object

:nodoc:



80
81
82
83
84
85
86
# File 'lib/openrgss/tone.rb', line 80

def blend!(tone) # :nodoc:
  self.red   += tone.red
  self.green += tone.green
  self.blue  += tone.blue
  self.gray  += tone.gray
  self
end

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

:call-seq: set(red, green, blue[, gray]) set(tone) (RGSS3)

Sets all components at once.

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/openrgss/tone.rb', line 39

def set(red, green=0, blue=0, gray=0)
  if red.is_a? Tone
    tone   = red
    @red   = tone.red
    @green = tone.green
    @blue  = tone.blue
    @gray  = tone.gray
  else
    @red   = red
    @green = green
    @blue  = blue
    @gray  = gray
  end
end

#to_sObject

:nodoc:



72
73
74
# File 'lib/openrgss/tone.rb', line 72

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