Public Member Functions | List of all members
ime::Transform Class Reference

Transform defined by a position, a rotation and a scale. More...

#include <Transform.h>

Public Member Functions

 Transform ()
 Default constructor. More...
 
void setPosition (float x, float y)
 Set the position of the object. More...
 
void setPosition (const Vector2f &position)
 Set the position of the object. More...
 
const Vector2fgetPosition () const
 Get the position of the object. More...
 
void setRotation (float angle)
 Set the orientation of the object. More...
 
void rotate (float angle)
 Rotate the object. More...
 
float getRotation () const
 Get the orientation of the object. More...
 
void setScale (float factorX, float factorY)
 Set the scale factors of the object. More...
 
void setScale (const Vector2f &scale)
 Set the scale factor of the object. More...
 
void scale (float factorX, float factorY)
 Scale the object by an offset. More...
 
void scale (const Vector2f &offset)
 Scale the object by an offset. More...
 
const Vector2fgetScale () const
 Get the current scale of the object. More...
 
void setOrigin (float x, float y)
 Set the local origin of the object. More...
 
void setOrigin (const Vector2f &origin)
 Set the local origin of the object. More...
 
const Vector2fgetOrigin () const
 Get the local origin of the object. More...
 
void move (float offsetX, float offsetY)
 Move the object by a given offset. More...
 
void move (const Vector2f &offset)
 Move the object by a given offset. More...
 
int onPropertyChange (const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to a property change event. More...
 
bool unsubscribe (int id)
 Remove a property change event listener. More...
 

Detailed Description

Transform defined by a position, a rotation and a scale.

Definition at line 38 of file Transform.h.

Constructor & Destructor Documentation

◆ Transform()

ime::Transform::Transform ( )

Default constructor.

Member Function Documentation

◆ getOrigin()

const Vector2f & ime::Transform::getOrigin ( ) const

Get the local origin of the object.

Returns
Local origin of the object

◆ getPosition()

const Vector2f & ime::Transform::getPosition ( ) const

Get the position of the object.

Returns
Current position of the object

◆ getRotation()

float ime::Transform::getRotation ( ) const

Get the orientation of the object.

Returns
Current rotation, in degrees

The rotation is always in the range [0, 360]

◆ getScale()

const Vector2f & ime::Transform::getScale ( ) const

Get the current scale of the object.

Returns
Current scale of the object

◆ move() [1/2]

void ime::Transform::move ( const Vector2f offset)

Move the object by a given offset.

Parameters
offsetOffset to apply

This function adds to the current position of the object, unlike setPosition which overwrites it

See also
setPosition

◆ move() [2/2]

void ime::Transform::move ( float  offsetX,
float  offsetY 
)

Move the object by a given offset.

Parameters
offsetXHorizontal offset
offsetYVertical offset

This function adds to the current position of the object, unlike setPosition which overwrites it

See also
setPosition

◆ onPropertyChange()

int ime::Transform::onPropertyChange ( const Callback< Property > &  callback,
bool  oneTime = false 
)

Add an event listener to a property change event.

Parameters
callbackThe function to be executed when a property changes
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The event listeners identification number

A property change event is triggered by any function that has a 'set' prefix, that is a setter function. The name of the property is the text that appears after the 'set' prefix in lowercase. For example, the setPosition() function will trigger a 'position' change event.

The callback is passed a property object that has the name and new value of the property that was changed. For example, the following code prints the position (whenever it changes) to the standard output stream:

// Register the event listener
int id = transform.onPropertyChange([](const ime::Property& property) {
if (property.getName() == "position") {
ime::Vector2f pos = property.getValue<ime::Vector2f>();
std::cout << "New Position = " << pos.x << ", " << pos.y << std::endl;
}
});
// Trigger the event - This will set the new position and invoke position change listeners
transform.setPosition(100.0f, 50.0f);
// Remove the event listener
transform.unsubscribe(id);
Class that can store a value of any type.
Definition: Property.h:38
const std::string & getName() const
Get the name of the property.
See also
unsubscribe

◆ rotate()

void ime::Transform::rotate ( float  angle)

Rotate the object.

Parameters
angleAngle of rotation, in degrees

This function adds to the current rotation of the object, unlike setRotation which overwrites it

See also
setRotation

◆ scale() [1/2]

void ime::Transform::scale ( const Vector2f offset)

Scale the object by an offset.

Parameters
offsetOffset to apply

This function multiplies the current scale of the object, unlike setScale which overwrites it

See also
setScale

◆ scale() [2/2]

void ime::Transform::scale ( float  factorX,
float  factorY 
)

Scale the object by an offset.

Parameters
factorXHorizontal scale factor
factorYVertical scale factor

This function multiplies the current scale of the object, unlike setScale which overwrites it

See also
setScale

◆ setOrigin() [1/2]

void ime::Transform::setOrigin ( const Vector2f origin)

Set the local origin of the object.

Parameters
originNew origin

The origin of an object 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 object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0)

◆ setOrigin() [2/2]

void ime::Transform::setOrigin ( float  x,
float  y 
)

Set the local origin of the object.

Parameters
xX coordinate of the new origin
yY coordinate of the new origin

The origin of an object 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 object, and ignore all transformations (position, scale, rotation).

The default origin of a transformable object is (0, 0)

◆ setPosition() [1/2]

void ime::Transform::setPosition ( const Vector2f position)

Set the position of the object.

Parameters
positionNew position

This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).

◆ setPosition() [2/2]

void ime::Transform::setPosition ( float  x,
float  y 
)

Set the position of the object.

Parameters
xX coordinate of the new position
yY coordinate of the new position

This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).

◆ setRotation()

void ime::Transform::setRotation ( float  angle)

Set the orientation of the object.

Parameters
angleNew 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 a transformable object is 0

See also
rotate

◆ setScale() [1/2]

void ime::Transform::setScale ( const Vector2f scale)

Set the scale factor of the object.

Parameters
scaleNew scale

This function completely overwrites the previous scale

See also
scale

◆ setScale() [2/2]

void ime::Transform::setScale ( float  factorX,
float  factorY 
)

Set the scale factors of the object.

Parameters
factorXNew horizontal scale factor
factorYNew vertical scale factor

This function completely overwrites the previous scale

See also
scale

◆ unsubscribe()

bool ime::Transform::unsubscribe ( int  id)

Remove a property change event listener.

Parameters
idThe identification number of the event listener
Returns
True if the event listener was removed or false if no such event listener exists
See also
onPropertyChange

The documentation for this class was generated from the following file: