Class: SFML::Text
- Inherits:
-
Object
- Object
- SFML::Text
- Defined in:
- ext/graphics/text.c,
ext/graphics/text.c
Overview
A drawable string of characters, rendered using a Font, positioned, rotated, scaled and tinted like any other Transformable object.
Includes Drawable.
Instance Attribute Summary collapse
-
#character_size ⇒ Integer
Returns the character size in pixels.
-
#fill_color ⇒ Color
Returns the shape's fill color.
-
#font ⇒ Font?
Returns the text's font.
-
#letter_spacing ⇒ Float
Returns the spacing between letters.
-
#line_spacing ⇒ Float
Returns the line spacing multiplier.
-
#origin ⇒ Vector2
Returns the object's origin.
-
#outline_color ⇒ Color
Returns the shape's outline color.
-
#outline_thickness ⇒ Float
Returns the shape's outline thickness.
-
#position ⇒ Vector2
Returns the object's position.
-
#rotation ⇒ Float
Returns the object's rotation, in degrees.
-
#scale ⇒ Vector2
Returns the object's scale factors.
-
#string ⇒ String
Returns the displayed string.
-
#style ⇒ Integer
Returns the text style flags.
Instance Method Summary collapse
-
#copy ⇒ Text
Returns a deep copy of the object.
-
#draw(target, state) ⇒ nil
Part of the Drawable interface; call Target#draw instead of this directly.
-
#find_character_pos(index) ⇒ Vector2
Returns the index of the character at the given position.
-
#global_bounds ⇒ Rect
Returns the bounding box after the transform is applied.
-
#initialize(*args) ⇒ Text
constructor
CSFML requires a font at creation time -- its C API unconditionally dereferences a NULL font argument rather than tolerating one, so unlike most other constructors here, the font is not optional.
-
#inverse_transform ⇒ Array<Float>
Returns the 3x3 row-major inverse of the object's transform matrix.
-
#local_bounds ⇒ Rect
Returns the bounding box in local (untransformed) coordinates.
-
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
-
#move(offset) ⇒ self
Moves the object by
offset. -
#rotate(angle) ⇒ self
Rotates the object by
angledegrees. -
#scale!(factors) ⇒ self
Scales the object by
factorsrelative to its current scale. -
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
Constructor Details
#new(font) ⇒ Text #new(font, string) ⇒ Text #new(font, string, character_size) ⇒ Text
CSFML requires a font at creation time -- its C API unconditionally dereferences a NULL font argument rather than tolerating one, so unlike most other constructors here, the font is not optional.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/graphics/text.c', line 97
static VALUE Text_initialize(int argc, VALUE* argv, VALUE self) {
VALUE rb_font, rb_string, rb_size;
Text* ptr;
rb_scan_args(argc, argv, "12", &rb_font, &rb_string, &rb_size);
if (!rb_obj_is_kind_of(rb_font, Get_Klass_Font())) {
raise_invalid_argument_class(Get_Klass_Font());
}
TypedData_Get_Struct(self, Text, &Text_data_type, ptr);
ptr->text = sfText_create(Get_Font_Struct(rb_font));
ptr->rb_font = rb_font;
if (ptr->text == NULL) {
rb_raise(rb_eRuntimeError, "failed to create text");
}
if (!NIL_P(rb_string)) {
sfText_setString(ptr->text, StringValueCStr(rb_string));
}
if (!NIL_P(rb_size)) {
sfText_setCharacterSize(ptr->text, (unsigned int)NUM2UINT(rb_size));
}
return self;
}
|
Instance Attribute Details
#character_size ⇒ Integer
Returns the character size in pixels.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_character_size(VALUE self) { return UINT2NUM(sfText_getCharacterSize(Get_Text_Struct(self))); } |
#fill_color ⇒ Color
Returns the shape's fill color.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_fill_color(VALUE self) { return color_to_rb(sfText_getFillColor(Get_Text_Struct(self))); } |
#font ⇒ Font?
Returns the text's font.
565 566 567 |
# File 'ext/graphics/text.c', line 565
static VALUE Text_get_font(VALUE self) {
return Get_Text(self)->rb_font;
}
|
#letter_spacing ⇒ Float
Returns the spacing between letters.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_letter_spacing(VALUE self) { return DBL2NUM(sfText_getLetterSpacing(Get_Text_Struct(self))); } |
#line_spacing ⇒ Float
Returns the line spacing multiplier.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_line_spacing(VALUE self) { return DBL2NUM(sfText_getLineSpacing(Get_Text_Struct(self))); } |
#origin ⇒ Vector2
Returns the object's origin.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_origin(VALUE self) { return vec2f_to_rb(sfText_getOrigin(Get_Text_Struct(self))); } |
#outline_color ⇒ Color
Returns the shape's outline color.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_outline_color(VALUE self) { return color_to_rb(sfText_getOutlineColor(Get_Text_Struct(self))); } |
#outline_thickness ⇒ Float
Returns the shape's outline thickness.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_outline_thickness(VALUE self) { return DBL2NUM(sfText_getOutlineThickness(Get_Text_Struct(self))); } |
#position ⇒ Vector2
Returns the object's position.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_position(VALUE self) { return vec2f_to_rb(sfText_getPosition(Get_Text_Struct(self))); } |
#rotation ⇒ Float
Returns the object's rotation, in degrees.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_rotation(VALUE self) { return DBL2NUM(sfText_getRotation(Get_Text_Struct(self))); } |
#scale ⇒ Vector2
Returns the object's scale factors.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_scale(VALUE self) { return vec2f_to_rb(sfText_getScale(Get_Text_Struct(self))); } |
#string ⇒ String
Returns the displayed string.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_string(VALUE self) { return utf32_to_rb(sfText_getUnicodeString(Get_Text_Struct(self))); } |
#style ⇒ Integer
Returns the text style flags.
565 566 567 |
# File 'ext/graphics/text.c', line 565 static VALUE Text_get_style(VALUE self) { return text_style_to_rb(sfText_getStyle(Get_Text_Struct(self))); } |
Instance Method Details
#copy ⇒ Text
Returns a deep copy of the object.
133 134 135 136 137 138 139 140 141 |
# File 'ext/graphics/text.c', line 133
static VALUE Text_copy(VALUE self) {
Text* ptr = Get_Text(self);
VALUE copy = Text_wrap(Get_Klass_Text(), sfText_copy(ptr->text));
Text* copy_ptr = Get_Text(copy);
copy_ptr->rb_font = ptr->rb_font;
return copy;
}
|
#draw(target, state) ⇒ nil
Part of the Drawable interface; call Target#draw instead of this directly.
552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'ext/graphics/text.c', line 552
static VALUE Text_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
TargetView view = Get_RenderTarget_View(rb_target);
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
raise_invalid_argument_class(Get_Klass_RenderState());
}
TARGET_DRAW(view, sfRenderWindow_drawText, sfRenderTexture_drawText, Get_Text_Struct(self),
Get_RenderState_Struct(rb_state));
return Qnil;
}
|
#find_character_pos(index) ⇒ Vector2
Returns the index of the character at the given position.
516 517 518 |
# File 'ext/graphics/text.c', line 516
static VALUE Text_find_character_pos(VALUE self, VALUE rb_index) {
return vec2f_to_rb(sfText_findCharacterPos(Get_Text_Struct(self), (size_t)NUM2SIZET(rb_index)));
}
|
#global_bounds ⇒ Rect
Returns the bounding box after the transform is applied.
538 539 540 |
# File 'ext/graphics/text.c', line 538 static VALUE Text_get_global_bounds(VALUE self) { return rect_to_rb(sfText_getGlobalBounds(Get_Text_Struct(self))); } |
#inverse_transform ⇒ Array<Float>
Returns the 3x3 row-major inverse of the object's transform matrix.
504 505 506 |
# File 'ext/graphics/text.c', line 504 static VALUE Text_get_inverse_transform(VALUE self) { return Transform_MatrixToArray(sfText_getInverseTransform(Get_Text_Struct(self)).matrix); } |
#local_bounds ⇒ Rect
Returns the bounding box in local (untransformed) coordinates.
527 528 529 |
# File 'ext/graphics/text.c', line 527 static VALUE Text_get_local_bounds(VALUE self) { return rect_to_rb(sfText_getLocalBounds(Get_Text_Struct(self))); } |
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
494 495 496 |
# File 'ext/graphics/text.c', line 494 static VALUE Text_get_transform(VALUE self) { return Transform_MatrixToArray(sfText_getTransform(Get_Text_Struct(self)).matrix); } |
#move(offset) ⇒ self
Moves the object by offset.
459 460 461 462 |
# File 'ext/graphics/text.c', line 459
static VALUE Text_move(VALUE self, VALUE rb_offset) {
sfText_move(Get_Text_Struct(self), vec2f_from_rb(rb_offset));
return self;
}
|
#rotate(angle) ⇒ self
Rotates the object by angle degrees.
471 472 473 474 |
# File 'ext/graphics/text.c', line 471
static VALUE Text_rotate(VALUE self, VALUE rb_angle) {
sfText_rotate(Get_Text_Struct(self), NUM2DBL(rb_angle));
return self;
}
|
#scale!(factors) ⇒ self
Scales the object by factors relative to its current scale.
483 484 485 486 |
# File 'ext/graphics/text.c', line 483
static VALUE Text_scale(VALUE self, VALUE rb_factors) {
sfText_scale(Get_Text_Struct(self), vec2f_from_rb(rb_factors));
return self;
}
|
#transform ⇒ Array<Float>
Returns the object's 3x3 row-major transform matrix.
494 495 496 |
# File 'ext/graphics/text.c', line 494 static VALUE Text_get_transform(VALUE self) { return Transform_MatrixToArray(sfText_getTransform(Get_Text_Struct(self)).matrix); } |