Abstract base class for geometric figures. More...
#include <Shape.h>
Public Types | |
enum | Type { Type::Rectangle, Type::Circle, Type::Convex } |
The types of shapes. More... | |
using | Ptr = std::shared_ptr< Shape > |
Shared shape pointer. More... | |
Public Member Functions | |
Shape (std::unique_ptr< priv::IShapeImpl > impl, Type type) | |
Shape (const Shape &) | |
Copy constructor. More... | |
Shape & | operator= (const Shape &) |
Copy assignment operator. More... | |
Shape (Shape &&) noexcept | |
Move constructor. More... | |
Shape & | operator= (Shape &&) noexcept |
Move assignment operator. 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 (Body::Ptr body) |
Attach a rigid body to a shape. More... | |
void | removeRigidBody () |
Remove a rigid body from the shape. More... | |
Body::Ptr | getRigidBody () |
Get the rigid body attached to the shape. More... | |
Body::Ptr | getRigidBody () const |
bool | hasRigidBody () const |
Check if the the shape has a rigid body attached to it or not. More... | |
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 (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 (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 (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 (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 (Vector2f offset) override |
Move the shape by a given offset. More... | |
virtual Shape::Ptr | clone () const =0 |
Make a copy of the shape. More... | |
void | draw (Window &renderTarget) const override |
Draw the shape on a render target. More... | |
~Shape () override | |
Destructor. More... | |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the alias of the object. More... | |
unsigned int | getObjectId () const |
Get the id of the object. More... | |
virtual std::string | getClassName () const =0 |
Get the name of the concrete class. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback) |
Add an event listener to a specific property change event. More... | |
void | onPropertyChange (const Callback< Property > &callback) |
Add an event listener to a property change event. More... | |
int | onEvent (const std::string &event, const Callback<> &callback) |
Add an event listener to an event. More... | |
bool | unsubscribe (const std::string &event, int id) |
Remove an event listener from an event. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | removeDestructionListener (int id) |
Remove a destruction listener form the object. More... | |
bool | operator== (const Object &rhs) const |
Check if two objects are the same object or not. More... | |
bool | operator!= (const Object &rhs) const |
Check if two objects are not the same object. More... | |
Protected Member Functions | |
std::shared_ptr< void > | getInternalPtr () const |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emit (const std::string &event) |
Dispatch an action event. More... | |
Abstract base class for geometric figures.
Some common geometric figures are squares, rectangles and triangles
using ime::Shape::Ptr = std::shared_ptr<Shape> |
|
strong |
ime::Shape::Shape | ( | const Shape & | ) |
Copy constructor.
|
noexcept |
Move constructor.
|
override |
Destructor.
void ime::Shape::attachRigidBody | ( | Body::Ptr | body | ) |
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
|
pure virtual |
Make a copy of the shape.
You should use this function if you don't care about the type of the shape, otherwise use the shapes copy function for copying purposes
Implemented in ime::RectangleShape, ime::ConvexShape, and ime::CircleShape.
|
overridevirtual |
Draw the shape on a render target.
renderTarget | Target to draw object on |
Implements ime::Drawable.
|
protectedinherited |
Dispatch an action event.
event | The name of the event to be dispatched |
This function will invoke all event listeners of the specified event. The function should be used for events that represent an action, rather than those that represent a property change (Use emitChange for that)
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
pure virtualinherited |
Get the name of the concrete class.
This function is implemented by all internal classes that inherit from this class.
Implemented in ime::Tile, ime::SpriteSheet, ime::Sprite, ime::RectangleShape, ime::ConvexShape, ime::CircleShape, ime::Camera, ime::Scene, ime::RenderLayerContainer, ime::RenderLayer, ime::TargetGridMover, ime::RandomGridMover, ime::KeyboardGridMover, ime::DistanceJoint, ime::PolygonCollider, ime::EdgeCollider, ime::CircleCollider, ime::BoxCollider, ime::Body, ime::AABB, and ime::GameObject.
|
overridevirtual |
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.
Colour ime::Shape::getFillColour | ( | ) | const |
Get the fill colour of the shape.
FloatRect ime::Shape::getGlobalBounds | ( | ) | const |
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.
FloatRect ime::Shape::getLocalBounds | ( | ) | const |
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 id of the object.
Each object has a unique id
|
overridevirtual |
Colour ime::Shape::getOutlineColour | ( | ) | const |
Get the outline colour of the shape.
float ime::Shape::getOutlineThickness | ( | ) | const |
Get the outline thickness of the shape.
|
overridevirtual |
Body::Ptr ime::Shape::getRigidBody | ( | ) |
Get the rigid body attached to the shape.
|
overridevirtual |
Get the orientation of the shape.
The rotation is always in the range [0, 360]
Implements ime::ITransformable.
|
overridevirtual |
Get the current scale of the shape.
Implements ime::ITransformable.
Type ime::Shape::getShapeType | ( | ) | const |
Get the type of this shape.
|
inherited |
bool ime::Shape::hasRigidBody | ( | ) | const |
Check if the the shape has a rigid body attached to it or not.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
Note that an object may have more than one destruction listeners, however, you have to keep the returned id if you may want to remove the callback at a later time
|
inherited |
Add an event listener to an event.
event | The name of the event to add an an event listener to |
callback | The function to be executed when the event takes place |
Unlike onPropertyChange, this function registers event listeners to events that occur when something happens to the object, or when the object does something (action events). Usually the name of the event/action is the name of the function:
Add an event listener to a property change event.
callback | The function to be executed when the property changes |
Note that only one callback function may be registered with this function. This means that adding a new event listener overwrites the previous event listener. To remove the callback, pass a nullptr as an argument. The function may be useful if you want to write the logic for property changes in one function.
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to listen for |
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, for the setTag function, the property that the function modifies is Tag.
Note that when adding a property change event listener, the name of the property must be in lowercase:
Unlike onPropertyChange(const Callback&) you can add multiple event listeners to the same property using this function. However you must store the unique id of the event listener if you wish to remove it at a later time
|
inherited |
Check if two objects are not the same object.
rhs | Object to compare against this object |
Two objects are different from each other if they have different object id's
|
inherited |
Check if two objects are the same object or not.
rhs | Object to compare against this object |
Two objects are the same object if they have the same object id. Recall that each object instance has a unique id
|
inherited |
Remove a destruction listener form the object.
The | id of the destruction listener to be removed |
void ime::Shape::removeRigidBody | ( | ) |
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
|
overridevirtual |
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.
|
overridevirtual |
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.
|
overridevirtual |
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.
void ime::Shape::setFillColour | ( | const Colour & | colour | ) |
Set the fill colour of the shape.
colour | The new colour of the shape |
By default, the shape's fill colour is opaque white.
|
overridevirtual |
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.
|
overridevirtual |
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.
void ime::Shape::setOutlineColour | ( | const Colour & | colour | ) |
Set the outline colour of the shape.
colour | The new outline colour |
By default, the shape's outline colour is opaque white.
void ime::Shape::setOutlineThickness | ( | float | thickness | ) |
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.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
overridevirtual |
Set the scale factor of the shape.
scale | New scale |
This function completely overwrites the previous scale
Implements ime::ITransformable.
|
inherited |
Assign the object an alias.
name | The alias of the object |
This function is useful if you want to refer to the object by tag instead of its id. Unlike an object id, multiple objects may have the same tag.
By default, the tag is an empty string
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove event listener from |
id | The unique id of the event listener to be removed |