class SF::RectangleShape

Overview

Specialized shape representing a rectangle

This class inherits all the functions of SF::Transformable (position, rotation, scale, bounds, ...) as well as the functions of SF::Shape (outline, color, texture, ...).

Usage example:

rectangle = SF::RectangleShape.new
rectangle.size = SF.vector2f(100, 50)
rectangle.outline_color = SF::Color::Red
rectangle.outline_thickness = 5
rectangle.position = {10, 20}
# [...]
window.draw rectangle

See also: SF::Shape, SF::CircleShape, SF::ConvexShape

Defined in:

graphics/obj.cr

Constructors

Instance Method Summary

Instance methods inherited from class SF::Shape

fill_color : Color fill_color, fill_color=(color : Color) fill_color=, finalize finalize, get_point(index : Int) : Vector2f get_point, global_bounds : FloatRect global_bounds, local_bounds : FloatRect local_bounds, outline_color : Color outline_color, outline_color=(color : Color) outline_color=, outline_thickness : Float32 outline_thickness, outline_thickness=(thickness : Number) outline_thickness=, point_count : Int32 point_count, set_texture(texture : Texture | Nil, reset_rect : Bool = false) set_texture, texture=(texture : Texture) texture=, texture_rect : IntRect texture_rect, texture_rect=(rect : IntRect) texture_rect=, update update

Instance methods inherited from module SF::Drawable

draw(target : RenderTarget, states : RenderStates) draw

Instance methods inherited from class SF::Transformable

dup : Transformable dup, finalize finalize, inverse_transform : Transform inverse_transform, move(offset_x : Number, offset_y : Number)
move(offset : Vector2 | Tuple)
move
, origin : Vector2f origin, origin=(origin : Vector2 | Tuple) origin=, position : Vector2f position, position=(position : Vector2 | Tuple) position=, rotate(angle : Number) rotate, rotation : Float32 rotation, rotation=(angle : Number) rotation=, scale(factor_x : Number, factor_y : Number)
scale(factor : Vector2 | Tuple)
scale : Vector2f
scale
, scale=(factors : Vector2 | Tuple) scale=, set_origin(x : Number, y : Number) set_origin, set_position(x : Number, y : Number) set_position, set_scale(factor_x : Number, factor_y : Number) set_scale, transform : Transform transform

Constructor methods inherited from class SF::Transformable

new new

Constructor Detail

def self.new(size : Vector2 | Tuple = Vector2.new(0, 0)) #

Default constructor

  • size - Size of the rectangle

[View source]

Instance Method Detail

def dup : RectangleShape #
Description copied from class Reference

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.


[View source]
def finalize #
Description copied from class SF::Shape

Virtual destructor


[View source]
def get_point(index : Int) : Vector2f #

Get a point of the rectangle

The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account. The result is undefined if index is out of the valid range.

  • index - Index of the point to get, in range 0..3

Returns: index-th point of the shape


[View source]
def point_count : Int32 #

Get the number of points defining the shape

Returns: Number of points of the shape. For rectangle shapes, this number is always 4.


[View source]
def size : Vector2f #

Get the size of the rectangle

Returns: Size of the rectangle

See also: #size=


[View source]
def size=(size : Vector2 | Tuple) #

Set the size of the rectangle

  • size - New size of the rectangle

See also: #size


[View source]