Skip to content

Commit

Permalink
UI: Apply tweens on Update().
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Dec 3, 2017
1 parent 15152fc commit f23c7cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
15 changes: 15 additions & 0 deletions ext/native/ui/view.cpp
Expand Up @@ -12,6 +12,7 @@
#include "ui/ui.h"
#include "ui/view.h"
#include "ui/ui_context.h"
#include "ui/ui_tween.h"
#include "thin3d/thin3d.h"
#include "base/NativeApp.h"

Expand Down Expand Up @@ -160,6 +161,18 @@ View::~View() {
if (HasFocus())
SetFocusedView(0);
RemoveQueuedEvents(this);

// Could use unique_ptr, but then we have to include tween everywhere.
for (auto &tween : tweens_)
delete tween;
tweens_.clear();
}

void View::Update() {
for (Tween *tween : tweens_) {
if (!tween->Finished())
tween->Apply(this);
}
}

void View::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {
Expand Down Expand Up @@ -1119,6 +1132,7 @@ void Slider::Draw(UIContext &dc) {
}

void Slider::Update() {
View::Update();
if (repeat_ >= 0) {
repeat_++;
}
Expand Down Expand Up @@ -1228,6 +1242,7 @@ void SliderFloat::Draw(UIContext &dc) {
}

void SliderFloat::Update() {
View::Update();
if (repeat_ >= 0) {
repeat_++;
}
Expand Down
16 changes: 11 additions & 5 deletions ext/native/ui/view.h
Expand Up @@ -224,9 +224,6 @@ struct MeasureSpec {
float size;
};

class View;


// Should cover all bases.
struct EventParams {
View *v;
Expand Down Expand Up @@ -349,6 +346,8 @@ class LayoutParams {

View *GetFocusedView();

class Tween;

class View {
public:
View(LayoutParams *layoutParams = 0) : layoutParams_(layoutParams), visibility_(V_VISIBLE), measuredWidth_(0), measuredHeight_(0), enabledPtr_(0), enabled_(true), enabledMeansDisabled_(false) {
Expand All @@ -363,7 +362,7 @@ class View {
virtual bool Key(const KeyInput &input) { return false; }
virtual void Touch(const TouchInput &input) {}
virtual void Axis(const AxisInput &input) {}
virtual void Update() {}
virtual void Update();

// If this view covers these coordinates, it should add itself and its children to the list.
virtual void Query(float x, float y, std::vector<View *> &list);
Expand Down Expand Up @@ -424,6 +423,12 @@ class View {

Point GetFocusPosition(FocusDirection dir);

template <class T>
T *AddTween(T *t) {
tweens_.push_back(t);
return t;
}

protected:
// Inputs to layout
std::unique_ptr<LayoutParams> layoutParams_;
Expand All @@ -438,6 +443,8 @@ class View {
// Outputs of layout. X/Y are absolute screen coordinates, hierarchy is "gone" here.
Bounds bounds_;

std::vector<Tween *> tweens_;

private:
bool *enabledPtr_;
bool enabled_;
Expand All @@ -455,7 +462,6 @@ class InertView : public View {
bool Key(const KeyInput &input) override { return false; }
void Touch(const TouchInput &input) override {}
bool CanBeFocused() const override { return false; }
void Update() override {}
};


Expand Down

0 comments on commit f23c7cf

Please sign in to comment.