Tweening animation test 1.
This commit is contained in:
@@ -30,7 +30,7 @@ namespace JUI
|
||||
{
|
||||
public:
|
||||
|
||||
std::function<void()> getter;
|
||||
std::function<void(float)> tick;
|
||||
float lifetime = 5;
|
||||
float progress = 0;
|
||||
};
|
||||
@@ -81,26 +81,6 @@ namespace JUI
|
||||
Event<Widget *> Destroying;
|
||||
public:
|
||||
|
||||
|
||||
template <typename T>
|
||||
void TweenTo(std::function<T()> getter, std::function<void(T)> setter, T goal) { }
|
||||
|
||||
/*template <>
|
||||
void TweenTo(std::function<float()> getter, std::function<void(float)> setter, float goal) { }
|
||||
|
||||
template <>
|
||||
void TweenTo(std::function<UDim()> getter, std::function<void(UDim)> setter, UDim goal) { }
|
||||
|
||||
template <>
|
||||
void TweenTo(std::function<UDim2()> getter, std::function<void(UDim2)> setter, UDim2 goal) { }*/
|
||||
|
||||
|
||||
void TweenFromTo(std::function<UDim2(void)> getter, std::function<void(UDim2)> setter, UDim2 start, UDim2 goal) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TweenPositionTo(const UDim2& goal)
|
||||
{
|
||||
std::function<void(float)> updateTillGoalReached = [this, goal] (float elapsed)
|
||||
@@ -117,22 +97,27 @@ namespace JUI
|
||||
return;
|
||||
}
|
||||
|
||||
float lerp_factor = 1.f/10.f;
|
||||
float lerp_factor = 1.f/1000.f;
|
||||
pos.X.Pixels = Math::Lerp(pos.X.Pixels, goal.X.Pixels, lerp_factor);
|
||||
pos.Y.Pixels = Math::Lerp(pos.Y.Pixels, goal.Y.Pixels, lerp_factor);
|
||||
pos.X.Scale = Math::Lerp(pos.X.Scale, goal.X.Scale, lerp_factor);
|
||||
pos.Y.Scale = Math::Lerp(pos.Y.Scale, goal.Y.Scale, lerp_factor);
|
||||
|
||||
|
||||
Position(pos);
|
||||
};
|
||||
|
||||
Tween t;
|
||||
t.tick = updateTillGoalReached;
|
||||
|
||||
tweens.push_back(t);
|
||||
|
||||
}
|
||||
void TweenPositionFromTo();
|
||||
void TweenSizeTo();
|
||||
void TweenSizeFromTo();
|
||||
|
||||
|
||||
void TweenTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds a given widget to this widget's list of children.
|
||||
/// @return The widget in question.
|
||||
@@ -402,6 +387,8 @@ namespace JUI
|
||||
Vector2 GetAbsoluteMarginTopLeft();
|
||||
|
||||
Vector2 GetAbsoluteMarginBottomRight();
|
||||
|
||||
void UpdateTweens(float elapsed);
|
||||
};
|
||||
|
||||
|
||||
|
4
main.cpp
4
main.cpp
@@ -125,13 +125,13 @@ JUI::Scene* CreateScene() {
|
||||
input_form->SetContent("");
|
||||
input_form->SetTextSize(14);
|
||||
|
||||
|
||||
|
||||
auto* other_window = new JUI::Window(root);
|
||||
other_window->Position({10_percent, 10_percent});
|
||||
other_window->Size({30_percent, 25_percent});
|
||||
other_window->SetTitle("Another Window");
|
||||
|
||||
other_window->TweenPositionTo({50_percent, 50_percent});
|
||||
|
||||
|
||||
scroller = new JUI::ScrollingRect(other_window->ViewportInstance());
|
||||
scroller->Size({100_percent, 100_percent});
|
||||
|
@@ -12,12 +12,6 @@ namespace JUI {
|
||||
Widget::Widget(Widget* parent) : Widget()
|
||||
{
|
||||
this->Parent(parent);
|
||||
|
||||
this->TweenTo<UDim2>([this] { return Size();},
|
||||
[this](UDim2 s) { Size(s);},
|
||||
{0,0,0,0});
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Widget::Parent(Widget* newParent) {
|
||||
@@ -183,45 +177,14 @@ namespace JUI {
|
||||
return ancestors;
|
||||
}
|
||||
|
||||
/*float Widget::GetAbsoluteMarginLeft()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsoluteMarginRight()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsoluteMarginTop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsoluteMarginBottom()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingLeft()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingRight()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingTop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float Widget::GetAbsolutePaddingBottom()
|
||||
{
|
||||
|
||||
}*/
|
||||
/*float Widget::GetAbsoluteMarginLeft() {}
|
||||
float Widget::GetAbsoluteMarginRight() {}
|
||||
float Widget::GetAbsoluteMarginTop() {}
|
||||
float Widget::GetAbsoluteMarginBottom() {}
|
||||
float Widget::GetAbsolutePaddingLeft() {}
|
||||
float Widget::GetAbsolutePaddingRight() {}
|
||||
float Widget::GetAbsolutePaddingTop() {}
|
||||
float Widget::GetAbsolutePaddingBottom() {}*/
|
||||
|
||||
|
||||
|
||||
@@ -322,9 +285,18 @@ namespace JUI {
|
||||
DrawChildWidgets();
|
||||
}
|
||||
|
||||
void Widget::UpdateTweens(float elapsed)
|
||||
{
|
||||
for (Tween& t: tweens)
|
||||
{
|
||||
t.tick(elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::Update(float delta) {
|
||||
|
||||
UpdateChildWidgets(delta);
|
||||
UpdateTweens(delta);
|
||||
}
|
||||
|
||||
struct {
|
||||
|
Reference in New Issue
Block a user