Class: Skia::Color
- Inherits:
-
Object
- Object
- Skia::Color
- Defined in:
- lib/skia/color.rb
Constant Summary collapse
- TRANSPARENT =
new(0x00000000)
- BLACK =
new(0xFF000000)
- WHITE =
new(0xFFFFFFFF)
- RED =
new(0xFFFF0000)
- GREEN =
new(0xFF00FF00)
- BLUE =
new(0xFF0000FF)
- YELLOW =
new(0xFFFFFF00)
- CYAN =
new(0xFF00FFFF)
- MAGENTA =
new(0xFFFF00FF)
- GRAY =
new(0xFF808080)
- LIGHT_GRAY =
new(0xFFC0C0C0)
- DARK_GRAY =
new(0xFF404040)
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #alpha ⇒ Object
- #blue ⇒ Object
- #green ⇒ Object
-
#initialize(r_or_value = 0, g = nil, b = nil, a = 255) ⇒ Color
constructor
A new instance of Color.
- #red ⇒ Object
- #to_hex ⇒ Object
- #to_i ⇒ Object
- #with_alpha(a) ⇒ Object
Constructor Details
#initialize(r_or_value = 0, g = nil, b = nil, a = 255) ⇒ Color
Returns a new instance of Color.
7 8 9 10 11 12 13 |
# File 'lib/skia/color.rb', line 7 def initialize(r_or_value = 0, g = nil, b = nil, a = 255) @value = if g.nil? && b.nil? r_or_value.is_a?(Integer) ? r_or_value : 0xFF000000 else ((a & 0xFF) << 24) | ((r_or_value & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) end end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/skia/color.rb', line 5 def value @value end |
Class Method Details
.argb(a, r, g, b) ⇒ Object
15 16 17 |
# File 'lib/skia/color.rb', line 15 def self.argb(a, r, g, b) new(r, g, b, a) end |
.from_hex(hex_string) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/skia/color.rb', line 23 def self.from_hex(hex_string) hex = hex_string.delete_prefix('#') case hex.length when 6 new(hex.to_i(16) | 0xFF000000) when 8 new(hex.to_i(16)) else raise ArgumentError, "Invalid hex color format: #{hex_string}" end end |
.rgb(r, g, b) ⇒ Object
19 20 21 |
# File 'lib/skia/color.rb', line 19 def self.rgb(r, g, b) new(r, g, b, 255) end |
Instance Method Details
#==(other) ⇒ Object
63 64 65 66 67 |
# File 'lib/skia/color.rb', line 63 def ==(other) return false unless other.is_a?(Color) @value == other.value end |
#alpha ⇒ Object
35 36 37 |
# File 'lib/skia/color.rb', line 35 def alpha (@value >> 24) & 0xFF end |
#blue ⇒ Object
47 48 49 |
# File 'lib/skia/color.rb', line 47 def blue @value & 0xFF end |
#green ⇒ Object
43 44 45 |
# File 'lib/skia/color.rb', line 43 def green (@value >> 8) & 0xFF end |
#red ⇒ Object
39 40 41 |
# File 'lib/skia/color.rb', line 39 def red (@value >> 16) & 0xFF end |
#to_hex ⇒ Object
55 56 57 |
# File 'lib/skia/color.rb', line 55 def to_hex format('#%08X', @value) end |
#to_i ⇒ Object
51 52 53 |
# File 'lib/skia/color.rb', line 51 def to_i @value end |
#with_alpha(a) ⇒ Object
59 60 61 |
# File 'lib/skia/color.rb', line 59 def with_alpha(a) self.class.new(red, green, blue, a) end |