sfml3.rb

Class: SFML::RectangleShape

Inherits:
Object
  • Object
show all
Defined in:
ext/graphics/rectangle.c,
ext/graphics/rectangle.c

Overview

A rectangle shape, drawable, transformable and stylable like the other SFML shapes. Includes Drawable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#new(size = Vector2.new(0, 0)) ⇒ RectangleShape

Creates a rectangle shape with the given size.



91
92
93
94
95
96
97
98
99
100
101
# File 'ext/graphics/rectangle.c', line 91

static VALUE RectangleShape_initialize(int argc, VALUE* argv, VALUE self) {
    VALUE rb_size;

    rb_scan_args(argc, argv, "01", &rb_size);

    if (!NIL_P(rb_size)) {
        sfRectangleShape_setSize(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_size));
    }

    return self;
}

Instance Attribute Details

#fill_color ⇒ Color

Returns the shape's fill color.

Returns:

Returns:



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_fill_color(VALUE self) {
    return color_to_rb(sfRectangleShape_getFillColor(Get_RectangleShape_Struct(self)));
}

#origin ⇒ Vector2

Returns the object's origin.

Returns:

Returns:



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_origin(VALUE self) {
    return vec2f_to_rb(sfRectangleShape_getOrigin(Get_RectangleShape_Struct(self)));
}

#outline_color ⇒ Color

Returns the shape's outline color.

Returns:

Returns:



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_outline_color(VALUE self) {
    return color_to_rb(sfRectangleShape_getOutlineColor(Get_RectangleShape_Struct(self)));
}

#outline_thickness ⇒ Float

Returns the shape's outline thickness.

Returns:

  • (Float)

Returns:

  • (Float)


486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_outline_thickness(VALUE self) {
    return DBL2NUM(sfRectangleShape_getOutlineThickness(Get_RectangleShape_Struct(self)));
}

#position ⇒ Vector2

Returns the object's position.

Returns:

Returns:



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_position(VALUE self) {
    return vec2f_to_rb(sfRectangleShape_getPosition(Get_RectangleShape_Struct(self)));
}

#rotation ⇒ Float

Returns the object's rotation, in degrees.

Returns:

  • (Float)

Returns:

  • (Float)


486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_rotation(VALUE self) {
    return DBL2NUM(sfRectangleShape_getRotation(Get_RectangleShape_Struct(self)));
}

#scale ⇒ Vector2

Returns the object's scale factors.

Returns:

Returns:



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_scale(VALUE self) {
    return vec2f_to_rb(sfRectangleShape_getScale(Get_RectangleShape_Struct(self)));
}

#size ⇒ Vector2

Returns the object's size.

Returns:

Returns:



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_size(VALUE self) {
    return vec2f_to_rb(sfRectangleShape_getSize(Get_RectangleShape_Struct(self)));
}

#texture ⇒ Texture?

Returns the object's texture, or nil if it has none.

Returns:

Returns:



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_texture(VALUE self) {
    return Get_RectangleShape(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 rectangle



486
487
488
# File 'ext/graphics/rectangle.c', line 486

static VALUE RectangleShape_get_texture_rect(VALUE self) {
    return int_rect_to_rb(sfRectangleShape_getTextureRect(Get_RectangleShape_Struct(self)));
}

Instance Method Details

#copy ⇒ RectangleShape

Returns a deep copy of the object.

Returns:

Returns:

  • (RectangleShape) —

    an independent copy, including its texture reference



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'ext/graphics/rectangle.c', line 110

static VALUE RectangleShape_copy(VALUE self) {
    RectangleShape* ptr = Get_RectangleShape(self);
    VALUE copy = RectangleShape_wrap(Get_Klass_RectangleShape(), sfRectangleShape_copy(ptr->shape));

    if (!NIL_P(ptr->rb_texture)) {
        RectangleShape* copy_ptr = Get_RectangleShape(copy);

        copy_ptr->rb_texture = ptr->rb_texture;
        sfRectangleShape_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)


473
474
475
476
477
478
479
480
481
482
483
484
# File 'ext/graphics/rectangle.c', line 473

static VALUE RectangleShape_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_drawRectangleShape, sfRenderTexture_drawRectangleShape,
                Get_RectangleShape_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



442
443
444
# File 'ext/graphics/rectangle.c', line 442

static VALUE RectangleShape_get_geometric_center(VALUE self) {
    return vec2f_to_rb(sfRectangleShape_getGeometricCenter(Get_RectangleShape_Struct(self)));
}

#global_bounds ⇒ Rect

Returns the bounding box after the transform is applied.

Returns:

Returns:

  • (Rect) —

    the bounding box after transform is applied



462
463
464
# File 'ext/graphics/rectangle.c', line 462

static VALUE RectangleShape_get_global_bounds(VALUE self) {
    return rect_to_rb(sfRectangleShape_getGlobalBounds(Get_RectangleShape_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



285
286
287
288
# File 'ext/graphics/rectangle.c', line 285

static VALUE RectangleShape_get_inverse_transform(VALUE self) {
    return Transform_MatrixToArray(
        sfRectangleShape_getInverseTransform(Get_RectangleShape_Struct(self)).matrix);
}

#local_bounds ⇒ Rect

Returns the bounding box in local (untransformed) coordinates.

Returns:

Returns:

  • (Rect) —

    the bounding box in local (untransformed) coordinates



452
453
454
# File 'ext/graphics/rectangle.c', line 452

static VALUE RectangleShape_get_local_bounds(VALUE self) {
    return rect_to_rb(sfRectangleShape_getLocalBounds(Get_RectangleShape_Struct(self)));
}

#transform ⇒ Array

Also available as #matrix.

Returns:

  • (Array)

Returns:

  • (Array) —

    the 3x3 row-major transform matrix



274
275
276
277
# File 'ext/graphics/rectangle.c', line 274

static VALUE RectangleShape_get_transform(VALUE self) {
    return Transform_MatrixToArray(
        sfRectangleShape_getTransform(Get_RectangleShape_Struct(self)).matrix);
}

#move(offset) ⇒ self

Moves the object by offset.

Returns:

  • (self)

Returns:

  • (self)


240
241
242
243
# File 'ext/graphics/rectangle.c', line 240

static VALUE RectangleShape_move(VALUE self, VALUE rb_offset) {
    sfRectangleShape_move(Get_RectangleShape_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 corner at index



431
432
433
434
# File 'ext/graphics/rectangle.c', line 431

static VALUE RectangleShape_get_point(VALUE self, VALUE rb_index) {
    return vec2f_to_rb(
        sfRectangleShape_getPoint(Get_RectangleShape_Struct(self), (size_t)NUM2SIZET(rb_index)));
}

#point_count ⇒ Integer

Returns the number of points composing the shape.

Returns:

  • (Integer)

Returns:

  • (Integer) —

    always 4



421
422
423
# File 'ext/graphics/rectangle.c', line 421

static VALUE RectangleShape_get_point_count(VALUE self) {
    return SIZET2NUM(sfRectangleShape_getPointCount(Get_RectangleShape_Struct(self)));
}

#rotate(angle) ⇒ self

Rotates the object by angle degrees.

Returns:

  • (self)

Returns:

  • (self)


251
252
253
254
# File 'ext/graphics/rectangle.c', line 251

static VALUE RectangleShape_rotate(VALUE self, VALUE rb_angle) {
    sfRectangleShape_rotate(Get_RectangleShape_Struct(self), NUM2DBL(rb_angle));
    return self;
}

#scale!(factors) ⇒ self

Scales the object by factors relative to its current scale.

Returns:

  • (self)

Returns:

  • (self)


263
264
265
266
# File 'ext/graphics/rectangle.c', line 263

static VALUE RectangleShape_scale(VALUE self, VALUE rb_factors) {
    sfRectangleShape_scale(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_factors));
    return self;
}

#transform ⇒ Array

Also available as #matrix.

Returns:

  • (Array)

Returns:

  • (Array) —

    the 3x3 row-major transform matrix



274
275
276
277
# File 'ext/graphics/rectangle.c', line 274

static VALUE RectangleShape_get_transform(VALUE self) {
    return Transform_MatrixToArray(
        sfRectangleShape_getTransform(Get_RectangleShape_Struct(self)).matrix);
}