mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-11 15:13:37 +02:00
UI: Make PopupScreens animate in just a bit.
This commit is contained in:
@@ -45,6 +45,27 @@ float ease(int t, int fadeLength)
|
||||
return ease((float)t / (float)fadeLength);
|
||||
}
|
||||
|
||||
float bezierEaseInOut(float val) {
|
||||
static const float x1 = 0.42f, x2 = 0.58f;
|
||||
static const float a = 1.0f - 3.0f * x2 + 3.0f * x1;
|
||||
static const float b = 3.0f * x2 - 6.0f * x1;
|
||||
static const float c = 3.0f * x1;
|
||||
|
||||
float guess = val;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
float slope = 3.0f * a * guess * guess + 2.0f * b * guess + c;
|
||||
if (slope == 0.0f) {
|
||||
break;
|
||||
}
|
||||
|
||||
float x = ((a * guess + b) * guess + c) * guess - val;
|
||||
guess -= x / slope;
|
||||
}
|
||||
|
||||
|
||||
return (-2.0f * guess + 3.0f) * guess * guess;
|
||||
}
|
||||
|
||||
float sawtooth(int t, int period) {
|
||||
return (t % period) * (1.0f / (period - 1));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ float linearOut(int t, int fadeInLength);
|
||||
float ease(float val);
|
||||
float ease(int t, int fadeLength);
|
||||
|
||||
float bezierEaseInOut(float val);
|
||||
|
||||
// need a bouncy ease
|
||||
|
||||
// waveforms [0, 1]
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include "base/display.h"
|
||||
#include "input/input_state.h"
|
||||
#include "input/keycodes.h"
|
||||
#include "math/curves.h"
|
||||
#include "ui/ui_screen.h"
|
||||
#include "ui/ui_context.h"
|
||||
#include "ui/screen.h"
|
||||
@@ -213,6 +215,8 @@ PopupScreen::PopupScreen(std::string title, std::string button1, std::string but
|
||||
button1_ = di->T(button1.c_str());
|
||||
if (!button2.empty())
|
||||
button2_ = di->T(button2.c_str());
|
||||
|
||||
alpha_ = 0.0f;
|
||||
}
|
||||
|
||||
bool PopupScreen::touch(const TouchInput &touch) {
|
||||
@@ -238,6 +242,24 @@ bool PopupScreen::key(const KeyInput &key) {
|
||||
return UIDialogScreen::key(key);
|
||||
}
|
||||
|
||||
void PopupScreen::update() {
|
||||
UIDialogScreen::update();
|
||||
|
||||
static const int FRAMES_LEAD_IN = 6;
|
||||
if (++frames_ < FRAMES_LEAD_IN) {
|
||||
float leadIn = bezierEaseInOut(frames_ * (1.0f / (float)FRAMES_LEAD_IN));
|
||||
alpha_ = leadIn;
|
||||
scale_.x = 0.9f + leadIn * 0.1f;
|
||||
scale_.y = 0.9f + leadIn * 0.1f;
|
||||
translation_.y = -dp_yres * (1.0f - leadIn) * 0.5f;
|
||||
} else {
|
||||
alpha_ = 1.0f;
|
||||
scale_.x = 1.0f;
|
||||
scale_.y = 1.0f;
|
||||
translation_.y = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void PopupScreen::CreateViews() {
|
||||
using namespace UI;
|
||||
|
||||
@@ -255,6 +277,8 @@ void PopupScreen::CreateViews() {
|
||||
root_->Add(box_);
|
||||
box_->SetBG(UI::Drawable(0xFF303030));
|
||||
box_->SetHasDropShadow(true);
|
||||
// Since we scale a bit, make the dropshadow bleed past the edges.
|
||||
box_->SetDropShadowExpand(std::max(dp_xres, dp_yres));
|
||||
|
||||
View *title = new PopupHeader(title_);
|
||||
box_->Add(title);
|
||||
|
||||
@@ -76,6 +76,8 @@ protected:
|
||||
virtual bool ShowButtons() const { return true; }
|
||||
virtual void OnCompleted(DialogResult result) {}
|
||||
|
||||
virtual void update() override;
|
||||
|
||||
private:
|
||||
UI::EventReturn OnOK(UI::EventParams &e);
|
||||
UI::EventReturn OnCancel(UI::EventParams &e);
|
||||
@@ -85,6 +87,8 @@ private:
|
||||
std::string title_;
|
||||
std::string button1_;
|
||||
std::string button2_;
|
||||
|
||||
int frames_ = 0;
|
||||
};
|
||||
|
||||
class ListPopupScreen : public PopupScreen {
|
||||
|
||||
@@ -118,8 +118,8 @@ void ViewGroup::Axis(const AxisInput &input) {
|
||||
void ViewGroup::Draw(UIContext &dc) {
|
||||
if (hasDropShadow_) {
|
||||
// Darken things behind.
|
||||
dc.FillRect(UI::Drawable(0x60000000), dc.GetBounds());
|
||||
float dropsize = 30;
|
||||
dc.FillRect(UI::Drawable(0x60000000), dc.GetBounds().Expand(dropShadowExpand_));
|
||||
float dropsize = 30.0f;
|
||||
dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid,
|
||||
bounds_.x - dropsize, bounds_.y,
|
||||
bounds_.x2() + dropsize, bounds_.y2()+dropsize*1.5, 0xDF000000, 3.0f);
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
View *GetViewByIndex(int index) { return views_[index]; }
|
||||
int GetNumSubviews() const { return (int)views_.size(); }
|
||||
void SetHasDropShadow(bool has) { hasDropShadow_ = has; }
|
||||
void SetDropShadowExpand(float s) { dropShadowExpand_ = s; }
|
||||
|
||||
void Lock() { modifyLock_.lock(); }
|
||||
void Unlock() { modifyLock_.unlock(); }
|
||||
@@ -81,6 +82,7 @@ protected:
|
||||
std::vector<View *> views_;
|
||||
View *defaultFocusView_;
|
||||
Drawable bg_;
|
||||
float dropShadowExpand_ = 0.0f;
|
||||
bool hasDropShadow_;
|
||||
bool clip_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user