UI: Add a simple tween class.

This commit is contained in:
Unknown W. Brackets committed 2017-12-03 09:39:50 -08:00
1 parent 7ab3e58dec
commit b4b850bce8
8 files changed
+168

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
#include "base/colorutil.h"
#include "ui/ui_tween.h"
#include "ui/view.h"
namespace UI {
uint32_t ColorTween::Current() {
return colorBlend(to_, from_, Position());
}
void TextColorTween::Apply(View *view) {
// TODO: No validation without RTTI?
TextView *tv = (TextView *)view;
tv->SetTextColor(Current());
}
void VisibilityTween::Apply(View *view) {
view->SetVisibility(Current());
}
Visibility VisibilityTween::Current() {
// Prefer V_VISIBLE over V_GONE/V_INVISIBLE.
float p = Position();
if (from_ == V_VISIBLE && p < 1.0f)
return from_;
if (to_ == V_VISIBLE && p > 0.0f)
return to_;
return p >= 1.0f ? to_ : from_;
}
} // namespace