property - first attempt
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "Geometry.h"
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Property.h"
|
||||
#include "Math/Dense.h"
|
||||
#include "Math/Transform.h"
|
||||
#include <utility>
|
||||
@@ -48,6 +49,11 @@ class ContainerBox : public AffineTransform, public Object {
|
||||
typedef AffineTransform BaseClass;
|
||||
|
||||
public:
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// PROPERTIES //
|
||||
Property<float> Width;
|
||||
Property<float> Height;
|
||||
Property<float> Depth;
|
||||
|
||||
virtual const char * GetClassName() const { return "ContainerBox"; }
|
||||
|
||||
@@ -56,14 +62,28 @@ public:
|
||||
* Initializes the local transformation with this instance as its parent.
|
||||
*/
|
||||
ContainerBox()
|
||||
: m_LocalT(this) // BaseClass is Parent of m_LocalTransform
|
||||
{}
|
||||
: m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||
Width(this, "Width", 1.0f),
|
||||
Height(this, "Height", 1.0f),
|
||||
Depth(this, "Depth", 1.0f) {
|
||||
Object::connect(&Width, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Height, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Depth, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Constructor with size.
|
||||
* @param size The size vector.
|
||||
*/
|
||||
ContainerBox(const Vector3f &size) : m_LocalT(this) { this->SetSize(size); }
|
||||
ContainerBox(const Vector3f &size)
|
||||
: m_LocalT(this),
|
||||
Width(this, "Width", size(0)),
|
||||
Height(this, "Height", size(1)),
|
||||
Depth(this, "Depth", size(2)) {
|
||||
Object::connect(&Width, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Height, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Depth, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy constructor.
|
||||
@@ -71,9 +91,14 @@ public:
|
||||
*/
|
||||
ContainerBox(const ContainerBox ©)
|
||||
: m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||
AffineTransform(copy) {
|
||||
AffineTransform(copy),
|
||||
Width(this, "Width", copy.Width),
|
||||
Height(this, "Height", copy.Height),
|
||||
Depth(this, "Depth", copy.Depth) {
|
||||
Object::connect(&Width, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Height, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&Depth, &Property<float>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
this->SetOrigin(copy.GetOrigin());
|
||||
this->SetSize(copy.GetSize());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,6 +119,9 @@ public:
|
||||
* @param v The size vector (width, height, depth).
|
||||
*/
|
||||
void SetSize(const Vector3f &v) {
|
||||
Width = v(0);
|
||||
Height = v(1);
|
||||
Depth = v(2);
|
||||
Vector3f pos = this->GetOrigin();
|
||||
m_LocalT = AffineTransform(this); // regenerate local transform
|
||||
m_LocalT.Scale(v);
|
||||
@@ -186,6 +214,10 @@ signals:
|
||||
virtual void Updated() override { ULIB_SIGNAL_EMIT(ContainerBox::Updated); }
|
||||
|
||||
private:
|
||||
void SyncSize() {
|
||||
this->SetSize(Vector3f(Width, Height, Depth));
|
||||
}
|
||||
|
||||
AffineTransform m_LocalT;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user