Class: Ray::Text
- Inherits:
-
Drawable
- Object
- Drawable
- Ray::Text
- Includes:
- TextHelper
- Defined in:
- lib/ray/text.rb,
ext/text.c
Constant Summary collapse
- Normal =
INT2FIX(SAY_TEXT_NORMAL)
- Bold =
INT2FIX(SAY_TEXT_BOLD)
- Italic =
INT2FIX(SAY_TEXT_ITALIC)
- Underlined =
INT2FIX(SAY_TEXT_UNDERLINED)
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#auto_center ⇒ Ray::Vector2?
Auto-centering ratio.
-
#auto_center=(val) ⇒ Object
Sets the auto centering ratio.
-
#collide?(obj) ⇒ true, false
True if the receiver collides with the rect.
-
#color ⇒ Color
Text color.
- #color=(val) ⇒ Object
- #font ⇒ Ray::Font
-
#font=(font) ⇒ Object
Sets the text’s font.
-
#initialize(string, opts = {}) ⇒ Text
constructor
A new instance of Text.
- #initialize_copy(orig) ⇒ Object
-
#inside?(obj) ⇒ true, false
True if the receiver is inside the rect.
- #inspect ⇒ Object
-
#outside?(obj) ⇒ true, false
True if the receiver is outside the rect.
- #pretty_print(q, other_attributes = []) ⇒ Object
-
#rect ⇒ Rect
(also: #to_rect)
Rect occupied by the text.
-
#size ⇒ Integer
Character size in pixels.
- #size=(val) ⇒ Object
-
#string ⇒ String
(also: #to_s)
Sets the string used by the text.
-
#string=(val) ⇒ Object
Sets the string used by the text.
-
#style ⇒ Integer
Text style (see constants Normal, Italic, Bold, and Underlined).
- #style=(style) ⇒ Object
Methods included from TextHelper
Constructor Details
#initialize(string, opts = {}) ⇒ Text
Returns a new instance of Text.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ray/text.rb', line 17 def initialize(string, opts = {}) opts = { :encoding => string.respond_to?(:encoding) ? string.encoding : "utf-8", :size => 12, :style => Normal, :at => [0, 0], :angle => 0, :color => Ray::Color.white }.merge(opts) @encoding = opts[:encoding].to_s self.string = string self.size = opts[:size] self.style = opts[:style] self.pos = opts[:at] self.scale = opts[:scale] || opts[:zoom] || [1, 1] self.angle = opts[:angle] self.color = opts[:color] self.shader = opts[:shader] if font = opts[:font] self.font = font.is_a?(String) ? Ray::FontSet[font] : font end end |
Instance Attribute Details
#encoding ⇒ String
92 93 94 |
# File 'lib/ray/text.rb', line 92 def encoding @encoding end |
Instance Method Details
#auto_center ⇒ Ray::Vector2?
Returns Auto-centering ratio. Nil when disabled.
145 146 147 148 149 150 151 152 153 |
# File 'ext/text.c', line 145
static
VALUE ray_text_auto_center(VALUE self) {
say_text *text = ray_rb2text(self);
if (say_text_auto_center(text))
return ray_vector2_to_rb(say_text_get_auto_center_ratio(text));
else
return Qnil;
}
|
#auto_center=(val) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'ext/text.c', line 164
static
VALUE ray_text_set_auto_center(VALUE self, VALUE center) {
say_text *text = ray_rb2text(self);
if (NIL_P(center))
say_text_disable_auto_center(text);
else
say_text_enable_auto_center(text, ray_convert_to_vector2(center));
return center;
}
|
#collide?(obj) ⇒ true, false
Returns True if the receiver collides with the rect.
75 76 77 |
# File 'lib/ray/text.rb', line 75 def collide?(obj) rect.collide?(obj.to_rect) end |
#color ⇒ Color
Returns Text color.
119 120 121 122 |
# File 'ext/text.c', line 119 static VALUE ray_text_color(VALUE self) { return ray_col2rb(say_text_get_color(ray_rb2text(self))); } |
#color=(val) ⇒ Object
128 129 130 131 132 |
# File 'ext/text.c', line 128
static
VALUE ray_text_set_color(VALUE self, VALUE val) {
say_text_set_color(ray_rb2text(self), ray_rb2col(val));
return val;
}
|
#font ⇒ Ray::Font
39 40 41 42 |
# File 'ext/text.c', line 39 static VALUE ray_text_font(VALUE self) { return rb_iv_get(self, "@font"); } |
#font=(font) ⇒ Object
49 50 51 52 53 54 |
# File 'ext/text.c', line 49
static
VALUE ray_text_set_font(VALUE self, VALUE font) {
say_text_set_font(ray_rb2text(self), ray_rb2font(font));
rb_iv_set(self, "@font", font);
return font;
}
|
#initialize_copy(orig) ⇒ Object
30 31 32 33 34 35 36 |
# File 'ext/text.c', line 30
static
VALUE ray_text_init_copy(VALUE self, VALUE orig) {
say_text_copy(ray_rb2text(self), ray_rb2text(orig));
rb_iv_set(self, "@font", rb_iv_get(orig, "@font"));
ray_drawable_copy_attr(self, orig);
return self;
}
|
#inside?(obj) ⇒ true, false
Returns True if the receiver is inside the rect. (false if they just collide).
80 81 82 |
# File 'lib/ray/text.rb', line 80 def inside?(obj) rect.inside?(obj.to_rect) end |
#inspect ⇒ Object
94 95 96 |
# File 'lib/ray/text.rb', line 94 def inspect "text(#{string.inspect})" end |
#outside?(obj) ⇒ true, false
Returns True if the receiver is outside the rect.
85 86 87 |
# File 'lib/ray/text.rb', line 85 def outside?(obj) rect.outside?(obj.to_rect) end |
#pretty_print(q, other_attributes = []) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/ray/text.rb', line 100 def pretty_print(q, other_attributes = []) attr = [ "string", "font", "color", "size", "style", "rect", "auto_center" ] super q, (attr + other_attributes) end |
#rect ⇒ Rect Also known as: to_rect
Returns Rect occupied by the text.
137 138 139 140 |
# File 'ext/text.c', line 137 static VALUE ray_text_rect(VALUE self) { return ray_rect2rb(say_text_get_rect(ray_rb2text(self))); } |
#size ⇒ Integer
Returns Character size in pixels.
82 83 84 85 |
# File 'ext/text.c', line 82 static VALUE ray_text_size(VALUE self) { return INT2FIX(say_text_get_size(ray_rb2text(self))); } |
#size=(val) ⇒ Object
91 92 93 94 95 |
# File 'ext/text.c', line 91
static
VALUE ray_text_set_size(VALUE self, VALUE val) {
say_text_set_size(ray_rb2text(self), NUM2ULONG(val));
return val;
}
|
#string ⇒ String Also known as: to_s
Sets the string used by the text. In 1.9, @encoding is changed approprietly. In 1.8, it is defaulted to utf-8. Change it to whatever is the right encoding.
54 55 56 57 58 59 60 61 |
# File 'lib/ray/text.rb', line 54 def string str = basic_string if str.respond_to? :force_encoding str.force_encoding InternalEncoding end convert(str, @encoding) end |
#string=(val) ⇒ Object
Sets the string used by the text. In 1.9, @encoding is changed approprietly. In 1.8, it is defaulted to utf-8. Change it to whatever is the right encoding.
66 67 68 69 70 71 72 |
# File 'lib/ray/text.rb', line 66 def string=(val) if val.respond_to? :encoding @encoding = val.encoding.to_s end set_basic_string internal_string(val, @encoding) end |
#style ⇒ Integer
Returns Text style (see constants Normal, Italic, Bold, and Underlined).
101 102 103 104 |
# File 'ext/text.c', line 101 static VALUE ray_text_style(VALUE self) { return INT2FIX(say_text_get_style(ray_rb2text(self))); } |
#style=(style) ⇒ Object
45 46 47 |
# File 'lib/ray/text.rb', line 45 def style=(style) set_basic_style parse_style(style) end |