A 2D shape having four sides and four corners (90 degree angles) More...
#include <RectangleShape.h>
Public Types | |
using | Ptr = std::unique_ptr< RectangleShape > |
Shared shape pointer. More... | |
enum class | Type { Rectangle , Circle , Convex } |
The types of shapes. More... | |
Public Member Functions | |
RectangleShape (const Vector2f &size=Vector2f(0, 0)) | |
Default constructor. More... | |
RectangleShape (const RectangleShape &) | |
Copy constructor. More... | |
RectangleShape & | operator= (const RectangleShape &) |
Copy assignment operator. More... | |
RectangleShape (RectangleShape &&) noexcept | |
Move constructor. More... | |
RectangleShape & | operator= (RectangleShape &&) noexcept |
Move assignment operator. More... | |
RectangleShape::Ptr | copy () const |
Create a copy of this shape. More... | |
Shape::Ptr | clone () const override |
Make a copy of this shape. More... | |
std::string | getClassName () const override |
Get the name of this class. More... | |
void | setSize (const Vector2f &size) |
Set the size of the rectangle. More... | |
Vector2f | getSize () const |
Get the size of th rectangle. More... | |
~RectangleShape () override | |
Destructor. More... | |
std::string | getClassType () const override |
Get the name of this class. More... | |
Type | getShapeType () const |
Get the type of this shape. More... | |
void | attachRigidBody (RigidBody::Ptr body) |
Attach a rigid body to a shape. More... | |
void | removeRigidBody () |
Remove a rigid body from the shape. More... | |
RigidBody * | getRigidBody () |
Get the rigid body attached to the shape. More... | |
const RigidBody * | getRigidBody () const |
bool | hasRigidBody () const |
Check if the the shape has a rigid body attached to it or not. More... | |
void | setTexture (const std::string &filename) |
Set the texture of the shape. More... | |
void | setTexture (const Texture &texture) |
Set the texture of the shape from a source texture. More... | |
Texture * | getTexture () |
Get the shapes texture. More... | |
const Texture * | getTexture () const |
void | setFillColour (const Colour &colour) |
Set the fill colour of the shape. More... | |
Colour | getFillColour () const |
Get the fill colour of the shape. More... | |
void | setOutlineColour (const Colour &colour) |
Set the outline colour of the shape. More... | |
Colour | getOutlineColour () const |
Get the outline colour of the shape. More... | |
void | setOutlineThickness (float thickness) |
Set the thickness of the shape's outline. More... | |
float | getOutlineThickness () const |
Get the outline thickness of the shape. More... | |
FloatRect | getLocalBounds () const |
Get the local bounding rectangle of the shape. More... | |
FloatRect | getGlobalBounds () const |
Get the global bounding rectangle of the shape. More... | |
void | setPosition (float x, float y) override |
Set the position of the shape. More... | |
void | setPosition (const Vector2f &position) override |
Set the position of the shape. More... | |
Vector2f | getPosition () const override |
Get the position of the shape. More... | |
void | setRotation (float angle) override |
Set the orientation of the shape. More... | |
void | rotate (float angle) override |
Rotate the shape. More... | |
float | getRotation () const override |
Get the orientation of the shape. More... | |
void | setScale (float factorX, float factorY) override |
Set the scale factors of the shape. More... | |
void | setScale (const Vector2f &scale) override |
Set the scale factor of the shape. More... | |
void | scale (float factorX, float factorY) override |
Scale the shape by an offset. More... | |
void | scale (const Vector2f &factor) override |
Scale the shape by an offset. More... | |
Vector2f | getScale () const override |
Get the current scale of the shape. More... | |
void | setOrigin (float x, float y) override |
Set the local origin of the shape. More... | |
void | setOrigin (const Vector2f &origin) override |
Set the local origin of the shape. More... | |
Vector2f | getOrigin () const override |
Get the local origin of the shape. More... | |
void | move (float offsetX, float offsetY) override |
Move the shape by a given offset. More... | |
void | move (const Vector2f &offset) override |
Move the shape by a given offset. More... | |
void | draw (priv::RenderTarget &renderTarget) const override |
Draw object on a render target. More... | |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the tag assigned to the object. More... | |
unsigned int | getObjectId () const |
Get the unique id of the object. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to a specific property change event. More... | |
int | onPropertyChange (const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to any property change event. More... | |
void | suspendedEventListener (int id, bool suspend) |
Pause or resume execution of an event listener. More... | |
bool | isEventListenerSuspended (int id) const |
Check if an event listener is suspended or not. More... | |
bool | removeEventListener (const std::string &event, int id) |
Remove an event listener from an event. More... | |
bool | removeEventListener (int id) |
Remove an event listener. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | isSameObjectAs (const Object &other) const |
Check if another object is the same instance as this object. More... | |
Static Public Member Functions | |
static RectangleShape::Ptr | create (const Vector2f &size=Vector2f(0, 0)) |
Create a new rectangle shape. More... | |
Protected Member Functions | |
std::shared_ptr< void > | getInternalPtr () const |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emitDestruction () |
Emit a destruction event. More... | |
Protected Attributes | |
EventEmitter | eventEmitter_ |
Event dispatcher. More... | |
A 2D shape having four sides and four corners (90 degree angles)
Definition at line 36 of file RectangleShape.h.
using ime::RectangleShape::Ptr = std::unique_ptr<RectangleShape> |
Shared shape pointer.
Definition at line 38 of file RectangleShape.h.
|
stronginherited |
Default constructor.
size | The size of the rectangle |
ime::RectangleShape::RectangleShape | ( | const RectangleShape & | ) |
Copy constructor.
|
noexcept |
Move constructor.
|
override |
Destructor.
|
inherited |
Attach a rigid body to a shape.
body | The body to be attached |
Attaching a rigid Body to a shape enables physics for that shape. This means that you should refrain from calling functions that MODIFY the shapes transform (position, rotation and origin). Note that the physics simulation does not account for scaling, that should be handles by you
|
overridevirtual |
Make a copy of this shape.
You should use this function if you don't care about the type of the shape, otherwise use the shapes copy function
Implements ime::Shape.
RectangleShape::Ptr ime::RectangleShape::copy | ( | ) | const |
|
static |
Create a new rectangle shape.
size | The size of the rectangle |
|
overridevirtualinherited |
Draw object on a render target.
renderTarget | Target to draw object on |
Implements ime::Drawable.
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
protectedinherited |
Emit a destruction event.
|
overridevirtual |
|
overridevirtualinherited |
Get the name of this class.
Note that this function is only implemented by child classes of Object which also serve as a base class for other classes
Reimplemented from ime::Drawable.
|
inherited |
Get the fill colour of the shape.
|
inherited |
Get the global bounding rectangle of the shape.
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.
|
inherited |
Get the local bounding rectangle of the shape.
The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity
|
inherited |
Get the unique id of the object.
Note that each instance of ime::Object has a unique id
|
overridevirtualinherited |
|
inherited |
Get the outline colour of the shape.
|
inherited |
Get the outline thickness of the shape.
|
overridevirtualinherited |
|
inherited |
Get the rigid body attached to the shape.
|
overridevirtualinherited |
Get the orientation of the shape.
The rotation is always in the range [0, 360]
Implements ime::ITransformable.
|
overridevirtualinherited |
Get the current scale of the shape.
Implements ime::ITransformable.
|
inherited |
Get the type of this shape.
Vector2f ime::RectangleShape::getSize | ( | ) | const |
Get the size of th rectangle.
|
inherited |
|
inherited |
Get the shapes texture.
|
inherited |
Check if the the shape has a rigid body attached to it or not.
|
inherited |
Check if an event listener is suspended or not.
id | The identification number of the listener to be checked |
This function also returns false if the specified event listener does not exist
|
inherited |
Check if another object is the same instance as this object.
other | The object to compare against this object |
|
overridevirtualinherited |
Move the shape by a given offset.
offset | Offset to apply |
This function adds to the current position of the shape, unlike setPosition which overwrites it
Implements ime::ITransformable.
|
overridevirtualinherited |
Move the shape by a given offset.
offsetX | Horizontal offset |
offsetY | Vertical offset |
This function adds to the current position of the shape, unlike setPosition which overwrites it
Implements ime::ITransformable.
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it
|
inherited |
Add an event listener to any property change event.
callback | The function to be executed when any property changes |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to add an event listener to |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
callback | The function to be executed when the property changes |
A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called
Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.
RectangleShape & ime::RectangleShape::operator= | ( | const RectangleShape & | ) |
Copy assignment operator.
|
noexcept |
Move assignment operator.
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove an event listener from |
id | The unique id of the event listener to be removed |
|
inherited |
Remove an event listener.
id | The id of the event listener to be removed |
|
inherited |
Remove a rigid body from the shape.
Removing a rigid Body from a shape disables all physics applied to the shape. This means that the shape will not respond to forces ans must be moved and rotated manually if need be
|
overridevirtualinherited |
Rotate the shape.
angle | Angle of rotation, in degrees |
This function adds to the current rotation of the shape, unlike setRotation which overwrites it
Implements ime::ITransformable.
|
overridevirtualinherited |
Scale the shape by an offset.
factor | Offset to apply |
This function multiplies the current scale of the shape, unlike setScale which overwrites it
Implements ime::ITransformable.
|
overridevirtualinherited |
Scale the shape by an offset.
factorX | Horizontal scale factor |
factorY | Vertical scale factor |
This function multiplies the current scale of the shape, unlike setScale which overwrites it
Implements ime::ITransformable.
|
inherited |
Set the fill colour of the shape.
colour | The new colour of the shape |
By default, the shape's fill colour is opaque white.
|
overridevirtualinherited |
Set the local origin of the shape.
origin | New origin |
The origin of the shape defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the shape, and ignore all transformations (position, scale, rotation).
The default origin of the shape is (0, 0)
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the local origin of the shape.
x | X coordinate of the new origin |
y | Y coordinate of the new origin |
The origin of the shape defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the shape, and ignore all transformations (position, scale, rotation).
The default origin of the shape is (0, 0)
Implements ime::ITransformable.
|
inherited |
Set the outline colour of the shape.
colour | The new outline colour |
By default, the shape's outline colour is opaque white.
|
inherited |
Set the thickness of the shape's outline.
thickness | The new outline thickness |
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.
|
overridevirtualinherited |
Set the position of the shape.
position | New position |
This function completely overwrites the previous position. Use the move function to apply an offset based on the previous position instead.
The default position of the shape is (0, 0)
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the position of the shape.
x | X coordinate of the new position |
y | Y coordinate of the new position |
This function completely overwrites the previous position. use move function to apply an offset based on the previous position instead
The default position of a the shape is (0, 0)
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the orientation of the shape.
angle | New rotation, in degrees |
This function completely overwrites the previous rotation. See the rotate function to add an angle based on the previous rotation instead.
The default rotation of the shape is 0
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the scale factor of the shape.
scale | New scale |
This function completely overwrites the previous scale
Implements ime::ITransformable.
|
overridevirtualinherited |
Set the scale factors of the shape.
factorX | New horizontal scale factor |
factorY | New vertical scale factor |
This function completely overwrites the previous scale
Implements ime::ITransformable.
void ime::RectangleShape::setSize | ( | const Vector2f & | size | ) |
Set the size of the rectangle.
size | The new size of the rectangle |
|
inherited |
Assign the object an alias.
tag | The alias of the object |
This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag
By default, the tag is an empty string
|
inherited |
Set the texture of the shape.
filename | The file name of the texture to be set |
FileNotFoundException | if the filename cannot be found on the disk |
|
inherited |
Set the texture of the shape from a source texture.
texture | The source texture |
Note that the source texture is copied
|
inherited |
Pause or resume execution of an event listener.
id | The event listeners unique identification number |
suspend | True to suspend/pause or false to unsuspend/resume |
|
protectedinherited |