abstract class SF::Shape
- SF::Shape
- SF::Transformable
- Reference
- Object
Overview
Base class for textured shapes with outline
SF::Shape
is a drawable class that allows to define and
display a custom convex shape on a render target.
It's only an abstract base, it needs to be specialized for
concrete types of shapes (circle, rectangle, convex polygon,
star, ...).
In addition to the attributes provided by the specialized shape classes, a shape always has the following attributes:
- a texture
- a texture rectangle
- a fill color
- an outline color
- an outline thickness
Each feature is optional, and can be disabled easily:
- the texture can be null
- the fill/outline colors can be
SF::Color::Transparent
- the outline thickness can be zero
You can write your own derived shape class, there are only two virtual functions to override:
#point_count
must return the number of points of the shape#get_point
must return the points of the shape
See also: SF::RectangleShape
, SF::CircleShape
, SF::ConvexShape
, SF::Transformable
Included Modules
Direct Known Subclasses
Defined in:
graphics/graphics.crgraphics/obj.cr
Instance Method Summary
-
#fill_color : Color
Get the fill color of the shape
-
#fill_color=(color : Color)
Set the fill color of the shape
-
#finalize
Virtual destructor
-
#get_point(index : Int) : Vector2f
Get a point of the shape
-
#global_bounds : FloatRect
Get the global (non-minimal) bounding rectangle of the entity
-
#local_bounds : FloatRect
Get the local bounding rectangle of the entity
-
#outline_color : Color
Get the outline color of the shape
-
#outline_color=(color : Color)
Set the outline color of the shape
-
#outline_thickness : Float32
Get the outline thickness of the shape
-
#outline_thickness=(thickness : Number)
Set the thickness of the shape's outline
-
#point_count : Int32
Get the total number of points of the shape
-
#set_texture(texture : Texture | Nil, reset_rect : Bool = false)
Change the source texture of the shape
-
#texture=(texture : Texture)
Shorthand for
#set_texture
-
#texture_rect : IntRect
Get the sub-rectangle of the texture displayed by the shape
-
#texture_rect=(rect : IntRect)
Set the sub-rectangle of the texture that the shape will display
-
#update
Recompute the internal geometry of the shape
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
Instance Method Detail
Set the fill color of the shape
This color is modulated (multiplied) with the shape's
texture if any. It can be used to colorize the shape,
or change its global opacity.
You can use SF::Color::Transparent
to make the inside of
the shape transparent, and have the outline alone.
By default, the shape's fill color is opaque white.
- color - New color of the shape
See also: #fill_color
, #outline_color=
Get a point of the shape
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 ... point_count
Returns: index-th point of the shape
See also: #point_count
Get the global (non-minimal) bounding rectangle of the entity
The returned rectangle is in global coordinates, which means that it takes into account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the shape in the global 2D world's coordinate system.
This function does not necessarily return the minimal bounding rectangle. It merely ensures that the returned rectangle covers all the vertices (but possibly more). This allows for a fast approximation of the bounds as a first check; you may want to use more precise checks on top of that.
Returns: Global bounding rectangle of the entity
Get the local bounding rectangle of the entity
The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.
Returns: Local bounding rectangle of the entity
Set the outline color of the shape
By default, the shape's outline color is opaque white.
- color - New outline color of the shape
See also: #outline_color
, #fill_color=
Get the outline thickness of the shape
Returns: Outline thickness of the shape
See also: #outline_thickness=
Set the thickness of the shape's outline
Note that negative values are allowed (so that the outline expands towards the center of the shape), and using zero disables the outline. By default, the outline thickness is 0.
- thickness - New outline thickness
See also: #outline_thickness
Get the total number of points of the shape
Returns: Number of points of the shape
See also: point
Change the source texture of the shape
The texture argument refers to a texture that must exist as long as the shape uses it. Indeed, the shape doesn't store its own copy of the texture, but rather keeps a pointer to the one that you passed to this function. If the source texture is destroyed and the shape tries to use it, the behavior is undefined. texture can be NULL to disable texturing. If reset_rect is true, the TextureRect property of the shape is automatically adjusted to the size of the new texture. If it is false, the texture rect is left unchanged.
- texture - New texture
- reset_rect - Should the texture rect be reset to the size of the new texture?
See also: texture
, #texture_rect=
Get the sub-rectangle of the texture displayed by the shape
Returns: Texture rectangle of the shape
See also: #texture_rect=
Set the sub-rectangle of the texture that the shape will display
The texture rect is useful when you don't want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.
- rect - Rectangle defining the region of the texture to display
See also: #texture_rect
, #texture=
Recompute the internal geometry of the shape
This function must be called by the derived class everytime
the shape's points change (i.e. the result of either
#point_count
or #get_point
is different).