Class: RGame::Util::Color
- Inherits:
-
Object
- Object
- RGame::Util::Color
- Defined in:
- ext/rgame_util/color_ext.c
Constant Summary collapse
- WHITE =
color_wrap(cColor, RGAME_COLOR_WHITE)
- BLACK =
color_wrap(cColor, RGAME_COLOR_BLACK)
- TRANSPARENT =
color_wrap(cColor, RGAME_COLOR_TRANSPARENT)
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #a ⇒ Object
- #b ⇒ Object
- #eql?(other) ⇒ Object
- #g ⇒ Object
- #hash ⇒ Object
- #inspect ⇒ Object (also: #to_s)
- #packed ⇒ Object
- #r ⇒ Object
Class Method Details
.coerce(value) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'ext/rgame_util/color_ext.c', line 82
static VALUE color_s_coerce(VALUE klass, VALUE value) {
if (NIL_P(value)) {
return rb_const_get(klass, rb_intern("WHITE"));
}
if (rb_obj_is_kind_of(value, klass)) {
return value;
}
if (RB_TYPE_P(value, T_ARRAY)) {
long length = RARRAY_LEN(value);
if (length != 3 && length != 4) {
rb_raise(rb_eArgError, "colour array must be [r, g, b] or [r, g, b, a], got %ld elements",
length);
}
VALUE alpha = length == 4 ? rb_ary_entry(value, 3) : INT2FIX(255);
VALUE args[4] = { rb_ary_entry(value, 0), rb_ary_entry(value, 1),
rb_ary_entry(value, 2), alpha };
return color_s_new(4, args, klass);
}
rb_raise(rb_eTypeError, "cannot coerce %" PRIsVALUE " into a colour", rb_obj_class(value));
}
|
.from_packed(packed) ⇒ Object
67 68 69 70 71 72 73 |
# File 'ext/rgame_util/color_ext.c', line 67
static VALUE color_s_from_packed(VALUE klass, VALUE packed) {
unsigned long value = NUM2ULONG(packed);
if (value > 0xFFFFFFFFul) {
rb_raise(rb_eArgError, "packed colour must fit in 32 bits");
}
return color_wrap(klass, (rgame_color)value);
}
|
.new(*args) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'ext/rgame_util/color_ext.c', line 56
static VALUE color_s_new(int argc, VALUE *argv, VALUE klass) {
VALUE r, g, b, a;
rb_scan_args(argc, argv, "31", &r, &g, &b, &a);
return color_wrap(klass,
rgame_color_rgba(component(r, "red"), component(g, "green"),
component(b, "blue"),
NIL_P(a) ? 255 : component(a, "alpha")));
}
|
.rgba(*args) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'ext/rgame_util/color_ext.c', line 56
static VALUE color_s_new(int argc, VALUE *argv, VALUE klass) {
VALUE r, g, b, a;
rb_scan_args(argc, argv, "31", &r, &g, &b, &a);
return color_wrap(klass,
rgame_color_rgba(component(r, "red"), component(g, "green"),
component(b, "blue"),
NIL_P(a) ? 255 : component(a, "alpha")));
}
|
Instance Method Details
#==(other) ⇒ Object
114 115 116 117 118 119 |
# File 'ext/rgame_util/color_ext.c', line 114
static VALUE color_equal(VALUE self, VALUE other) {
if (!rb_obj_is_kind_of(other, rb_obj_class(self))) {
return Qfalse;
}
return color_unwrap(self) == color_unwrap(other) ? Qtrue : Qfalse;
}
|
#a ⇒ Object
106 |
# File 'ext/rgame_util/color_ext.c', line 106 static VALUE color_a(VALUE self) { return INT2FIX(rgame_color_a(color_unwrap(self))); } |
#b ⇒ Object
105 |
# File 'ext/rgame_util/color_ext.c', line 105 static VALUE color_b(VALUE self) { return INT2FIX(rgame_color_b(color_unwrap(self))); } |
#eql?(other) ⇒ Object
114 115 116 117 118 119 |
# File 'ext/rgame_util/color_ext.c', line 114
static VALUE color_equal(VALUE self, VALUE other) {
if (!rb_obj_is_kind_of(other, rb_obj_class(self))) {
return Qfalse;
}
return color_unwrap(self) == color_unwrap(other) ? Qtrue : Qfalse;
}
|
#g ⇒ Object
104 |
# File 'ext/rgame_util/color_ext.c', line 104 static VALUE color_g(VALUE self) { return INT2FIX(rgame_color_g(color_unwrap(self))); } |
#hash ⇒ Object
121 122 123 |
# File 'ext/rgame_util/color_ext.c', line 121 static VALUE color_hash(VALUE self) { return rb_hash(UINT2NUM(color_unwrap(self))); } |
#inspect ⇒ Object Also known as: to_s
125 126 127 128 129 |
# File 'ext/rgame_util/color_ext.c', line 125 static VALUE color_inspect(VALUE self) { rgame_color color = color_unwrap(self); return rb_sprintf("#<RGame::Util::Color r=%d g=%d b=%d a=%d>", rgame_color_r(color), rgame_color_g(color), rgame_color_b(color), rgame_color_a(color)); } |
#packed ⇒ Object
110 |
# File 'ext/rgame_util/color_ext.c', line 110 static VALUE color_packed(VALUE self) { return UINT2NUM(color_unwrap(self)); } |
#r ⇒ Object
103 |
# File 'ext/rgame_util/color_ext.c', line 103 static VALUE color_r(VALUE self) { return INT2FIX(rgame_color_r(color_unwrap(self))); } |