Class: SFML::Shape
- Inherits:
-
Object
- Object
- SFML::Shape
- Defined in:
- ext/graphics/shape.c,
ext/graphics/shape.c
Overview
A base class for user-defined shapes. Subclass it and implement #point_count and #point(index) in Ruby to describe the shape's geometry, then call #update! after construction and whenever the points change. Drawable, transformable and stylable like the other SFML shapes. Includes Drawable.
Instance Attribute Summary collapse
-
#fill_color ⇒ Color
Returns the shape's fill color.
-
#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.
-
#texture ⇒ Texture?
Returns the object's texture, or
nilif it has none. -
#texture_rect ⇒ Rect
Returns the sub-rectangle of the texture displayed on the object.
Instance Method Summary collapse
-
#draw(target, state) ⇒ nil
Draws the object onto
targetusing the given renderstate. -
#geometric_center ⇒ Vector2
Returns the local position of the shape's geometric center.
-
#global_bounds ⇒ Rect
Returns the bounding box after the transform is applied.
-
#new ⇒ Shape
constructor
A base class meant to be subclassed: override #point_count and #point(i) in Ruby to define the shape's geometry, then call #update! whenever it changes.
-
#inverse_transform ⇒ Array
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
Also available as #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
Also available as #matrix.
-
#update! ⇒ self
Recomputes the shape's geometry by calling back into the subclass's #point_count and #point(i).
Constructor Details
#new ⇒ Shape
A base class meant to be subclassed: override #point_count and #point(i) in Ruby to define the shape's geometry, then call #update! whenever it changes.
131 132 133 |
# File 'ext/graphics/shape.c', line 131 static VALUE CustomShape_initialize(VALUE self) { return self; } |
Instance Attribute Details
#fill_color ⇒ Color
Returns the shape's fill color.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_fill_color(VALUE self) { return color_to_rb(sfShape_getFillColor(Get_CustomShape_Struct(self))); } |
#origin ⇒ Vector2
Returns the object's origin.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_origin(VALUE self) { return vec2f_to_rb(sfShape_getOrigin(Get_CustomShape_Struct(self))); } |
#outline_color ⇒ Color
Returns the shape's outline color.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_outline_color(VALUE self) { return color_to_rb(sfShape_getOutlineColor(Get_CustomShape_Struct(self))); } |
#outline_thickness ⇒ Float
Returns the shape's outline thickness.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_outline_thickness(VALUE self) { return DBL2NUM(sfShape_getOutlineThickness(Get_CustomShape_Struct(self))); } |
#position ⇒ Vector2
Returns the object's position.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_position(VALUE self) { return vec2f_to_rb(sfShape_getPosition(Get_CustomShape_Struct(self))); } |
#rotation ⇒ Float
Returns the object's rotation, in degrees.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_rotation(VALUE self) { return DBL2NUM(sfShape_getRotation(Get_CustomShape_Struct(self))); } |
#scale ⇒ Vector2
Returns the object's scale factors.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_scale(VALUE self) { return vec2f_to_rb(sfShape_getScale(Get_CustomShape_Struct(self))); } |
#texture ⇒ Texture?
Returns the object's texture, or nil if it has none.
465 466 467 |
# File 'ext/graphics/shape.c', line 465
static VALUE CustomShape_get_texture(VALUE self) {
return Get_CustomShape(self)->rb_texture;
}
|
#texture_rect ⇒ Rect
Returns the sub-rectangle of the texture displayed on the object.
465 466 467 |
# File 'ext/graphics/shape.c', line 465 static VALUE CustomShape_get_texture_rect(VALUE self) { return int_rect_to_rb(sfShape_getTextureRect(Get_CustomShape_Struct(self))); } |
Instance Method Details
#draw(target, state) ⇒ nil
Draws the object onto target using the given render state.
452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'ext/graphics/shape.c', line 452
static VALUE CustomShape_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_drawShape, sfRenderTexture_drawShape,
Get_CustomShape_Struct(self), Get_RenderState_Struct(rb_state));
return Qnil;
}
|
#geometric_center ⇒ Vector2
Returns the local position of the shape's geometric center.
421 422 423 |
# File 'ext/graphics/shape.c', line 421 static VALUE CustomShape_get_geometric_center(VALUE self) { return vec2f_to_rb(sfShape_getGeometricCenter(Get_CustomShape_Struct(self))); } |
#global_bounds ⇒ Rect
Returns the bounding box after the transform is applied.
441 442 443 |
# File 'ext/graphics/shape.c', line 441 static VALUE CustomShape_get_global_bounds(VALUE self) { return rect_to_rb(sfShape_getGlobalBounds(Get_CustomShape_Struct(self))); } |
#inverse_transform ⇒ Array
Returns the 3x3 row-major inverse of the object's transform matrix.
286 287 288 289 |
# File 'ext/graphics/shape.c', line 286 static VALUE CustomShape_get_inverse_transform(VALUE self) { return Transform_MatrixToArray( sfShape_getInverseTransform(Get_CustomShape_Struct(self)).matrix); } |
#local_bounds ⇒ Rect
Returns the bounding box in local (untransformed) coordinates.
431 432 433 |
# File 'ext/graphics/shape.c', line 431 static VALUE CustomShape_get_local_bounds(VALUE self) { return rect_to_rb(sfShape_getLocalBounds(Get_CustomShape_Struct(self))); } |
#transform ⇒ Array
Also available as #matrix.
276 277 278 |
# File 'ext/graphics/shape.c', line 276 static VALUE CustomShape_get_transform(VALUE self) { return Transform_MatrixToArray(sfShape_getTransform(Get_CustomShape_Struct(self)).matrix); } |
#move(offset) ⇒ self
Moves the object by offset.
242 243 244 245 |
# File 'ext/graphics/shape.c', line 242
static VALUE CustomShape_move(VALUE self, VALUE rb_offset) {
sfShape_move(Get_CustomShape_Struct(self), vec2f_from_rb(rb_offset));
return self;
}
|
#rotate(angle) ⇒ self
Rotates the object by angle degrees.
253 254 255 256 |
# File 'ext/graphics/shape.c', line 253
static VALUE CustomShape_rotate(VALUE self, VALUE rb_angle) {
sfShape_rotate(Get_CustomShape_Struct(self), NUM2DBL(rb_angle));
return self;
}
|
#scale!(factors) ⇒ self
Scales the object by factors relative to its current scale.
265 266 267 268 |
# File 'ext/graphics/shape.c', line 265
static VALUE CustomShape_scale(VALUE self, VALUE rb_factors) {
sfShape_scale(Get_CustomShape_Struct(self), vec2f_from_rb(rb_factors));
return self;
}
|
#transform ⇒ Array
Also available as #matrix.
276 277 278 |
# File 'ext/graphics/shape.c', line 276 static VALUE CustomShape_get_transform(VALUE self) { return Transform_MatrixToArray(sfShape_getTransform(Get_CustomShape_Struct(self)).matrix); } |
#update! ⇒ self
Recomputes the shape's geometry by calling back into the subclass's #point_count and #point(i). Call this whenever the shape's points change.
143 144 145 146 |
# File 'ext/graphics/shape.c', line 143 static VALUE CustomShape_update(VALUE self) { sfShape_update(Get_CustomShape_Struct(self)); return self; } |