sfml3.rb

Class: SFML::ConvexShape

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Returns:

Returns:



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.

Returns:

Returns:



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.

Returns:

Returns:



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.

Returns:

  • (Float)

Returns:

  • (Float)


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.

Returns:

  • (Integer)

Returns:

  • (Integer)


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.

Returns:

Returns:



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.

Returns:

  • (Float)

Returns:

  • (Float)


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.

Returns:

Returns:



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.

Returns:

Returns:



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.

Returns:

Returns:

  • (Rect) —

    the sub-rectangle of the texture displayed on the shape



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.

Returns:

Returns:

  • (ConvexShape) —

    an independent copy, including its texture reference



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.

Returns:

  • (nil)

Returns:

  • (nil)


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.

Returns:

Returns:

  • (Vector2) —

    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.

Returns:

Returns:

  • (Rect) —

    the bounding box after 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.

Returns:

  • (Array)

Returns:

  • (Array) —

    the 3x3 row-major inverse 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.

Returns:

Returns:

  • (Rect) —

    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.

Returns:

  • (Array)

Returns:

  • (Array) —

    the 3x3 row-major transform 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.

Returns:

  • (self)

Returns:

  • (self)


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.

Returns:

Returns:

  • (Vector2) —

    the local position of the point at index

Raises:

  • (IndexError) —

    if index is out of range



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.

Returns:

  • (self)

Returns:

  • (self)


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.

Returns:

  • (self)

Returns:

  • (self)


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.

Returns:

Returns:

Raises:

  • (IndexError) —

    if index is out of range



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.

Returns:

  • (Array)

Returns:

  • (Array) —

    the 3x3 row-major transform 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);
}