Class: SFML::ConvexShape
- Inherits:
-
Object
- Object
- SFML::ConvexShape
- Defined in:
- ext/graphics/polygon.c,
ext/graphics/polygon.c
Overview
A convex polygon shape defined by an arbitrary set of points, drawable, transformable and stylable like the other SFML shapes. Includes Drawable.
The polygon must remain convex; passing points that describe a concave shape produces undefined rendering.
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.
-
#point_count ⇒ Integer
Returns the number of points composing the shape.
-
#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
-
#copy ⇒ ConvexShape
Returns a deep copy of the object.
-
#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(point_count = 0) ⇒ ConvexShape
constructor
Creates a convex shape with room for at least
point_countpoints. -
#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. -
#point(index) ⇒ Vector2
Returns the local position of the point at
index. -
#rotate(angle) ⇒ self
Rotates the object by
angledegrees. -
#scale!(factors) ⇒ self
Scales the object by
factorsrelative to its current scale. -
#set_point(index, point) ⇒ Vector2
Sets the position of the point at
index. -
#transform ⇒ Array
Also available as #matrix.
Constructor Details
#new(point_count = 0) ⇒ ConvexShape
Creates a convex shape with room for at least point_count points.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'ext/graphics/polygon.c', line 90
static VALUE ConvexShape_initialize(int argc, VALUE* argv, VALUE self) {
VALUE rb_point_count;
rb_scan_args(argc, argv, "01", &rb_point_count);
if (!NIL_P(rb_point_count)) {
sfConvexShape_setPointCount(Get_ConvexShape_Struct(self),
(size_t)NUM2SIZET(rb_point_count));
}
return self;
}
|
Instance Attribute Details
#fill_color ⇒ Color
Returns the shape's fill color.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_fill_color(VALUE self) { return color_to_rb(sfConvexShape_getFillColor(Get_ConvexShape_Struct(self))); } |
#origin ⇒ Vector2
Returns the object's origin.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_origin(VALUE self) { return vec2f_to_rb(sfConvexShape_getOrigin(Get_ConvexShape_Struct(self))); } |
#outline_color ⇒ Color
Returns the shape's outline color.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_outline_color(VALUE self) { return color_to_rb(sfConvexShape_getOutlineColor(Get_ConvexShape_Struct(self))); } |
#outline_thickness ⇒ Float
Returns the shape's outline thickness.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_outline_thickness(VALUE self) { return DBL2NUM(sfConvexShape_getOutlineThickness(Get_ConvexShape_Struct(self))); } |
#point_count ⇒ Integer
Returns the number of points composing the shape.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_point_count(VALUE self) { return SIZET2NUM(sfConvexShape_getPointCount(Get_ConvexShape_Struct(self))); } |
#position ⇒ Vector2
Returns the object's position.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_position(VALUE self) { return vec2f_to_rb(sfConvexShape_getPosition(Get_ConvexShape_Struct(self))); } |
#rotation ⇒ Float
Returns the object's rotation, in degrees.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_rotation(VALUE self) { return DBL2NUM(sfConvexShape_getRotation(Get_ConvexShape_Struct(self))); } |
#scale ⇒ Vector2
Returns the object's scale factors.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_scale(VALUE self) { return vec2f_to_rb(sfConvexShape_getScale(Get_ConvexShape_Struct(self))); } |
#texture ⇒ Texture?
Returns the object's texture, or nil if it has none.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499
static VALUE ConvexShape_get_texture(VALUE self) {
return Get_ConvexShape(self)->rb_texture;
}
|
#texture_rect ⇒ Rect
Returns the sub-rectangle of the texture displayed on the object.
499 500 501 |
# File 'ext/graphics/polygon.c', line 499 static VALUE ConvexShape_get_texture_rect(VALUE self) { return int_rect_to_rb(sfConvexShape_getTextureRect(Get_ConvexShape_Struct(self))); } |
Instance Method Details
#copy ⇒ ConvexShape
Returns a deep copy of the object.
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'ext/graphics/polygon.c', line 109
static VALUE ConvexShape_copy(VALUE self) {
ConvexShape* ptr = Get_ConvexShape(self);
VALUE copy = ConvexShape_wrap(Get_Klass_ConvexShape(), sfConvexShape_copy(ptr->shape));
if (!NIL_P(ptr->rb_texture)) {
ConvexShape* copy_ptr = Get_ConvexShape(copy);
copy_ptr->rb_texture = ptr->rb_texture;
sfConvexShape_setTexture(copy_ptr->shape, Get_Texture_Struct(ptr->rb_texture), false);
}
return copy;
}
|
#draw(target, state) ⇒ nil
Draws the object onto target using the given render state.
486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'ext/graphics/polygon.c', line 486
static VALUE ConvexShape_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_drawConvexShape, sfRenderTexture_drawConvexShape,
Get_ConvexShape_Struct(self), Get_RenderState_Struct(rb_state));
return Qnil;
}
|
#geometric_center ⇒ Vector2
Returns the local position of the shape's geometric center.
455 456 457 |
# File 'ext/graphics/polygon.c', line 455 static VALUE ConvexShape_get_geometric_center(VALUE self) { return vec2f_to_rb(sfConvexShape_getGeometricCenter(Get_ConvexShape_Struct(self))); } |
#global_bounds ⇒ Rect
Returns the bounding box after the transform is applied.
475 476 477 |
# File 'ext/graphics/polygon.c', line 475 static VALUE ConvexShape_get_global_bounds(VALUE self) { return rect_to_rb(sfConvexShape_getGlobalBounds(Get_ConvexShape_Struct(self))); } |
#inverse_transform ⇒ Array
Returns the 3x3 row-major inverse of the object's transform matrix.
320 321 322 323 |
# File 'ext/graphics/polygon.c', line 320 static VALUE ConvexShape_get_inverse_transform(VALUE self) { return Transform_MatrixToArray( sfConvexShape_getInverseTransform(Get_ConvexShape_Struct(self)).matrix); } |
#local_bounds ⇒ Rect
Returns the bounding box in local (untransformed) coordinates.
465 466 467 |
# File 'ext/graphics/polygon.c', line 465 static VALUE ConvexShape_get_local_bounds(VALUE self) { return rect_to_rb(sfConvexShape_getLocalBounds(Get_ConvexShape_Struct(self))); } |
#transform ⇒ Array
Also available as #matrix.
310 311 312 |
# File 'ext/graphics/polygon.c', line 310 static VALUE ConvexShape_get_transform(VALUE self) { return Transform_MatrixToArray(sfConvexShape_getTransform(Get_ConvexShape_Struct(self)).matrix); } |
#move(offset) ⇒ self
Moves the object by offset.
276 277 278 279 |
# File 'ext/graphics/polygon.c', line 276
static VALUE ConvexShape_move(VALUE self, VALUE rb_offset) {
sfConvexShape_move(Get_ConvexShape_Struct(self), vec2f_from_rb(rb_offset));
return self;
}
|
#point(index) ⇒ Vector2
Returns the local position of the point at index.
164 165 166 167 |
# File 'ext/graphics/polygon.c', line 164
static VALUE ConvexShape_get_point(VALUE self, VALUE rb_index) {
return vec2f_to_rb(sfConvexShape_getPoint(Get_ConvexShape_Struct(self),
ConvexShape_check_index(self, rb_index)));
}
|
#rotate(angle) ⇒ self
Rotates the object by angle degrees.
287 288 289 290 |
# File 'ext/graphics/polygon.c', line 287
static VALUE ConvexShape_rotate(VALUE self, VALUE rb_angle) {
sfConvexShape_rotate(Get_ConvexShape_Struct(self), NUM2DBL(rb_angle));
return self;
}
|
#scale!(factors) ⇒ self
Scales the object by factors relative to its current scale.
299 300 301 302 |
# File 'ext/graphics/polygon.c', line 299
static VALUE ConvexShape_scale(VALUE self, VALUE rb_factors) {
sfConvexShape_scale(Get_ConvexShape_Struct(self), vec2f_from_rb(rb_factors));
return self;
}
|
#set_point(index, point) ⇒ Vector2
Sets the position of the point at index.
176 177 178 179 180 |
# File 'ext/graphics/polygon.c', line 176
static VALUE ConvexShape_set_point(VALUE self, VALUE rb_index, VALUE rb_point) {
sfConvexShape_setPoint(Get_ConvexShape_Struct(self), ConvexShape_check_index(self, rb_index),
vec2f_from_rb(rb_point));
return rb_point;
}
|
#transform ⇒ Array
Also available as #matrix.
310 311 312 |
# File 'ext/graphics/polygon.c', line 310 static VALUE ConvexShape_get_transform(VALUE self) { return Transform_MatrixToArray(sfConvexShape_getTransform(Get_ConvexShape_Struct(self)).matrix); } |