Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions engine/includes/components/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class ENGINE_EXPORT Actor : public Object {
return static_cast<T *>(component(T::metaClass()->name()));
}

std::list<Component *> components(const TString &type);

Component *componentInChild(const TString &type);

template<typename T>
Expand Down
2 changes: 0 additions & 2 deletions engine/includes/components/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class ENGINE_EXPORT Component : public Object {

TString tr(const TString &source);

virtual void actorParentChanged();

virtual void composeComponent();

virtual void drawGizmos();
Expand Down
2 changes: 1 addition & 1 deletion engine/includes/components/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ENGINE_EXPORT Transform : public Component {
~Transform();

Vector3 position() const;
void setPosition(const Vector3 &position);
virtual void setPosition(const Vector3 &position);

Vector3 rotation() const;
void setRotation(const Vector3 &angles);
Expand Down
32 changes: 21 additions & 11 deletions engine/src/components/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ Component *Actor::component(const TString &type) {
}
return nullptr;
}
/*!
Returns a list of the components with \a type attached to this Actor.
*/
std::list<Component *> Actor::components(const TString &type) {
PROFILE_FUNCTION();
std::list<Component *> result;
for(auto it : getChildren()) {
const MetaObject *meta = it->metaObject();
if(meta->canCastTo(type.data())) {
result.push_back(static_cast<Component *>(it));
}
}
return result;
}
/*!
Returns the component with \a type in the Actor's children using depth search.
A component is returned only if it's found on a current Actor; otherwise returns nullptr.
Expand Down Expand Up @@ -293,7 +307,9 @@ void Actor::clearCloneRef() {
*/
void Actor::setParent(Object *parent, int32_t position, bool force) {
PROFILE_FUNCTION();
if(parent == this || (Object::parent() == parent && position == -1)) {
Object *oldParent = Object::parent();

if(parent == this || (oldParent == parent && position == -1)) {
return;
}

Expand All @@ -304,19 +320,13 @@ void Actor::setParent(Object *parent, int32_t position, bool force) {
} else {
setScene(dynamic_cast<Scene *>(parent));
}

Object::setParent(parent, position, force);
if(m_transform) {
Object::setParent(parent, position, force);
if(actor) {
m_transform->setParentTransform(actor->transform(), force);
}
} else {
Object::setParent(parent, position);
}

for(auto it : getChildren()) {
Component *component = dynamic_cast<Component *>(it);
if(component) {
component->actorParentChanged();
} else {
m_transform->setParentTransform(nullptr, force);
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions engine/src/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ Actor *Component::instantiate(Prefab *prefab, Vector3 position, Quaternion rotat
*/
TString Component::tr(const TString &source) {
return Engine::translate(source);
}
/*!
This method will be triggered in case of Actor will change its own parent.
\internal
*/
void Component::actorParentChanged() {

}
/*!
\internal
Expand Down
15 changes: 1 addition & 14 deletions modules/uikit/includes/components/abstractslider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "widget.h"

class Frame;

class UIKIT_EXPORT AbstractSlider : public Widget {
A_OBJECT(AbstractSlider, Widget, General)

Expand All @@ -19,18 +17,7 @@ class UIKIT_EXPORT AbstractSlider : public Widget {
A_SIGNAL(AbstractSlider::pressed),
A_SIGNAL(AbstractSlider::valueChanged)
)
A_ENUMS(
A_ENUM(Orientation,
A_VALUE(Horizontal),
A_VALUE(Vertical)
)
)

public:
enum Orientation {
Horizontal,
Vertical
};
A_NOENUMS()

public:
AbstractSlider();
Expand Down
8 changes: 5 additions & 3 deletions modules/uikit/includes/components/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class UIKIT_EXPORT Layout {
int indexOf(const Layout *layout) const;
int indexOf(const RectTransform *transform) const;

RectTransform *transformAt(int index);

RectTransform *rectTransform();
void setRectTransform(RectTransform *transform);

int count() const;

float spacing() const;
void setSpacing(float spacing);
int spacing() const;
void setSpacing(int spacing);

int orientation() const;
void setOrientation(int orientation);
Expand All @@ -48,7 +50,7 @@ class UIKIT_EXPORT Layout {

RectTransform *m_rectTransform;

float m_spacing;
int m_spacing;

int m_orientation;

Expand Down
15 changes: 2 additions & 13 deletions modules/uikit/includes/components/progressbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UIKIT_EXPORT ProgressBar : public Widget {
A_OBJECT(ProgressBar, Widget, Components/UI)

A_PROPERTIES(
A_PROPERTYEX(ProgressOrientation, orientation, ProgressBar::orientation, ProgressBar::setOrientation, "enum=ProgressOrientation"),
A_PROPERTYEX(Orientation, orientation, ProgressBar::orientation, ProgressBar::setOrientation, "enum=Orientation"),
A_PROPERTY(float, from, ProgressBar::from, ProgressBar::setFrom),
A_PROPERTY(float, to, ProgressBar::to, ProgressBar::setTo),
A_PROPERTY(float, value, ProgressBar::value, ProgressBar::setValue),
Expand All @@ -17,18 +17,7 @@ class UIKIT_EXPORT ProgressBar : public Widget {
A_PROPERTYEX(Frame *, chunk, ProgressBar::chunk, ProgressBar::setChunk, "editor=Component")
)
A_NOMETHODS()
A_ENUMS(
A_ENUM(BarOrientation,
A_VALUE(Horizontal),
A_VALUE(Vertical)
)
)

public:
enum ProgressOrientation {
Horizontal,
Vertical
};
A_NOENUMS()

public:
ProgressBar();
Expand Down
8 changes: 8 additions & 0 deletions modules/uikit/includes/components/recttransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class UIKIT_EXPORT RectTransform : public Transform {
RectTransform();
~RectTransform();

void setPosition(const Vector3 &position) override;

Vector2 size() const;
void setSize(const Vector2 &size);

Expand All @@ -59,8 +61,11 @@ class UIKIT_EXPORT RectTransform : public Transform {
bool mouseTracking() const;
void setMouseTracking(bool tracking);

Vector2 mapFromGlobal(float x, float y);
bool isHovered(float x, float y) const;

Widget *widget();

RectTransform *hoveredTransform(float x, float y);

void subscribe(Widget *widget);
Expand All @@ -87,13 +92,16 @@ class UIKIT_EXPORT RectTransform : public Transform {

private:
friend class Layout;
friend class Widget;

void cleanDirty() const override;

void recalcChilds() const;

void recalcParent();

void applyStyle();

private:
std::list<Widget *> m_subscribers;

Expand Down
23 changes: 15 additions & 8 deletions modules/uikit/includes/components/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ class UIKIT_EXPORT Widget : public NativeBehaviour {
A_SLOT(Widget::lower),
A_SLOT(Widget::raise)
)
A_ENUMS(
A_ENUM(Orientation,
A_VALUE(Horizontal),
A_VALUE(Vertical)
)
)

public:
enum Orentation {
enum Orientation {
Horizontal,
Vertical
};
Expand All @@ -35,9 +42,9 @@ class UIKIT_EXPORT Widget : public NativeBehaviour {
Widget *parentWidget() const;
std::list<Widget *> &childWidgets();

RectTransform *rectTransform() const;
RectTransform *rectTransform();

bool isSubWidget(Widget *widget) const;
bool isSubWidget() const;

static Widget *focusWidget();

Expand All @@ -57,12 +64,10 @@ class UIKIT_EXPORT Widget : public NativeBehaviour {

void setRectTransform(RectTransform *transform);

void actorParentChanged() override;
void onHierarchyUpdated();

void composeComponent() override;

void setParent(Object *parent, int32_t position = -1, bool force = false) override;

float styleLength(const TString &key, float value, bool &pixels);
Vector2 styleBlock2Length(const TString &property, const Vector2 &value, bool &pixels);
Vector4 styleBlock4Length(const TString &property, const Vector4 &value, bool &pixels);
Expand All @@ -72,6 +77,8 @@ class UIKIT_EXPORT Widget : public NativeBehaviour {

static void setFocusWidget(Widget *widget);

void updateStyleProperty(const TString &name, const float *v, int32_t size);

private:
void addStyleRules(const std::map<TString, TString> &rules, uint32_t weight);

Expand All @@ -80,8 +87,6 @@ class UIKIT_EXPORT Widget : public NativeBehaviour {
protected:
std::map<TString, std::pair<uint32_t, TString>> m_styleRules;

std::list<Widget *> m_subWidgets;

std::list<Widget *> m_childWidgets;

private:
Expand All @@ -96,6 +101,8 @@ class UIKIT_EXPORT Widget : public NativeBehaviour {

RectTransform *m_transform;

bool m_subWidget;

static Widget *m_focusWidget;

};
Expand Down
2 changes: 1 addition & 1 deletion modules/uikit/includes/editor/uiedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private slots:
void onObjectCreate(TString type) override;
void onObjectsSelected(Object::ObjectList objects, bool force) override;
void onObjectsDeleted(Object::ObjectList objects) override;
void onObjectsChanged(const Object::ObjectList &objects, const TString &property, const Variant &value) override;
void onObjectsChanged(const Object::ObjectList &objects, const TString &propertyName, const Variant &value) override;

void onCutAction() override;
void onCopyAction() override;
Expand Down
2 changes: 2 additions & 0 deletions modules/uikit/includes/resources/stylesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class UIKIT_EXPORT StyleSheet : public Resource {
static void setStyleProperty(Widget *widget, const TString &key, const TString &value);

static Vector4 toColor(const TString &value);
static TString toColor(const Vector4 &value);

static float toLength(const TString &value, bool &pixels);

private:
Expand Down
12 changes: 11 additions & 1 deletion modules/uikit/src/components/abstractbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace {
const char *gIcon("icon");

const float gCorner = 4.0f;

const char *gCssBackgroundColor("background-color");
}
/*!
\class AbstractButton
Expand Down Expand Up @@ -144,6 +146,12 @@ void AbstractButton::setColor(const Vector4 &color) {
if(back) {
back->setColor(m_normalColor);
}

#ifdef SHARED_DEFINE
if(!isSignalsBlocked()) {
StyleSheet::setStyleProperty(this, gCssBackgroundColor, StyleSheet::toColor(m_normalColor));
}
#endif
}
/*!
Returns the color used when the button is highlighted.
Expand Down Expand Up @@ -277,7 +285,9 @@ void AbstractButton::update() {
m_currentFade += 1.0f / m_fadeDuration * Timer::deltaTime();
m_currentFade = CLAMP(m_currentFade, 0.0f, 1.0f);

back->blockSignals(true);
back->setColor(MIX(back->color(), color, m_currentFade));
back->blockSignals(false);
}
}

Expand All @@ -291,7 +301,7 @@ void AbstractButton::applyStyle() {
Widget::applyStyle();

// Background color
auto it = m_styleRules.find("background-color");
auto it = m_styleRules.find(gCssBackgroundColor);
if(it != m_styleRules.end()) {
setColor(StyleSheet::toColor(it->second.second));
}
Expand Down
Loading
Loading