Class: Color
- Inherits:
-
Object
- Object
- Color
- Extended by:
- RgssDb::JsonableConstructor
- Includes:
- RgssDb::Jsonable
- Defined in:
- lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb,
lib/rgss_db/model/rpg_maker_data/xp/rgss/color.rb,
lib/rgss_db/model/rpg_maker_data/vx_ace/rgss/color.rb
Overview
The RGBA color class.
Each component is handled with a floating-point value (Float).
Instance Attribute Summary collapse
-
#alpha ⇒ Object
Returns the value of attribute alpha.
-
#blue ⇒ Object
Returns the value of attribute blue.
-
#green ⇒ Object
Returns the value of attribute green.
-
#red ⇒ Object
Returns the value of attribute red.
Class Method Summary collapse
-
._load(serialized_string) ⇒ Color
Creates a new instance using the given binary data.
-
.new_serialized(serialized_string) ⇒ Color
Creates a new instance from a serialized string.
Instance Method Summary collapse
-
#_dump ⇒ String
Dumps this instance into a binary string.
-
#initialize(red = 0, green = 0, blue = 0, alpha = 0) ⇒ Color
constructor
Creates a Color object.
Methods included from RgssDb::JsonableConstructor
Methods included from RgssDb::Jsonable
Constructor Details
#initialize(red = 0, green = 0, blue = 0, alpha = 0) ⇒ Color
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).
22 23 24 25 26 27 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 22 def initialize(red = 0, green = 0, blue = 0, alpha = 0) @red = red @green = green @blue = blue @alpha = [red, green, blue].sum.positive? && alpha.zero? ? 255 : alpha end |
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
71 72 73 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71 def alpha @alpha end |
#blue ⇒ Object
Returns the value of attribute blue.
71 72 73 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71 def blue @blue end |
#green ⇒ Object
Returns the value of attribute green.
71 72 73 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71 def green @green end |
#red ⇒ Object
Returns the value of attribute red.
71 72 73 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 71 def red @red end |
Class Method Details
._load(serialized_string) ⇒ Color
Creates a new instance using the given binary data
Note: needed for Marshal module support
50 51 52 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 50 def self._load(serialized_string) Color.new_serialized(serialized_string) end |
.new_serialized(serialized_string) ⇒ Color
Creates a new instance from a serialized string
Note: needed for Marshal module support
63 64 65 66 67 68 69 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 63 def self.new_serialized(serialized_string) # double, double, double, double (double-precision) red, green, blue, alpha = serialized_string.unpack("dddd") # Creates the instance Color.new(red, green, blue, alpha) end |
Instance Method Details
#_dump ⇒ String
Dumps this instance into a binary string
Note: needed for Marshal module support
36 37 38 39 |
# File 'lib/rgss_db/model/rpg_maker_data/vx/rgss/color.rb', line 36 def _dump(*) # double, double, double, double (double-precision) [@red, @green, @blue, @alpha].pack("dddd") end |