Merge pull request #9476 from unknownbrackets/ui-transform

UI: Make popups transition their button
This commit is contained in:
Henrik Rydgård 2017-03-22 14:38:37 +01:00 committed by GitHub
commit 41a3370035
13 changed files with 86 additions and 37 deletions

View File

@ -266,6 +266,8 @@ UI::EventReturn ControlMappingScreen::OnAutoConfigure(UI::EventParams &params) {
} }
I18NCategory *km = GetI18NCategory("KeyMapping"); I18NCategory *km = GetI18NCategory("KeyMapping");
ListPopupScreen *autoConfList = new ListPopupScreen(km->T("Autoconfigure for device"), items, -1); ListPopupScreen *autoConfList = new ListPopupScreen(km->T("Autoconfigure for device"), items, -1);
if (params.v)
autoConfList->SetPopupOrigin(params.v);
screenManager()->push(autoConfList); screenManager()->push(autoConfList);
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }

View File

@ -287,6 +287,8 @@ UI::EventReturn LogConfigScreen::OnLogLevel(UI::EventParams &e) {
auto logLevelScreen = new LogLevelScreen(dev->T("Log Level")); auto logLevelScreen = new LogLevelScreen(dev->T("Log Level"));
logLevelScreen->OnChoice.Handle(this, &LogConfigScreen::OnLogLevelChange); logLevelScreen->OnChoice.Handle(this, &LogConfigScreen::OnLogLevelChange);
if (e.v)
logLevelScreen->SetPopupOrigin(e.v);
screenManager()->push(logLevelScreen); screenManager()->push(logLevelScreen);
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
@ -294,7 +296,7 @@ UI::EventReturn LogConfigScreen::OnLogLevel(UI::EventParams &e) {
LogLevelScreen::LogLevelScreen(const std::string &title) : ListPopupScreen(title) { LogLevelScreen::LogLevelScreen(const std::string &title) : ListPopupScreen(title) {
int NUMLOGLEVEL = 6; int NUMLOGLEVEL = 6;
std::vector<std::string> list; std::vector<std::string> list;
for(int i = 0; i < NUMLOGLEVEL; ++i) { for (int i = 0; i < NUMLOGLEVEL; ++i) {
list.push_back(logLevelList[i]); list.push_back(logLevelList[i]);
} }
adaptor_ = UI::StringVectorListAdaptor(list, -1); adaptor_ = UI::StringVectorListAdaptor(list, -1);
@ -552,7 +554,7 @@ void AddressPromptScreen::CreatePopupContents(UI::ViewGroup *parent) {
void AddressPromptScreen::OnCompleted(DialogResult result) { void AddressPromptScreen::OnCompleted(DialogResult result) {
if (result == DR_OK) { if (result == DR_OK) {
UI::EventParams e; UI::EventParams e{};
e.v = root_; e.v = root_;
e.a = addr_; e.a = addr_;
OnChoice.Trigger(e); OnChoice.Trigger(e);
@ -655,7 +657,7 @@ void JitCompareScreen::CreateViews() {
blockAddr_->OnTextChange.Handle(this, &JitCompareScreen::OnAddressChange); blockAddr_->OnTextChange.Handle(this, &JitCompareScreen::OnAddressChange);
blockStats_ = leftColumn->Add(new TextView("")); blockStats_ = leftColumn->Add(new TextView(""));
EventParams ignore = {0}; EventParams ignore{};
OnCurrentBlock(ignore); OnCurrentBlock(ignore);
} }

View File

@ -792,7 +792,10 @@ void EmuScreen::CreateViews() {
UI::EventReturn EmuScreen::OnDevTools(UI::EventParams &params) { UI::EventReturn EmuScreen::OnDevTools(UI::EventParams &params) {
releaseButtons(); releaseButtons();
screenManager()->push(new DevMenu()); DevMenu *devMenu = new DevMenu();
if (params.v)
devMenu->SetPopupOrigin(params.v);
screenManager()->push(devMenu);
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }

View File

@ -1101,6 +1101,8 @@ UI::EventReturn GameSettingsScreen::OnLanguage(UI::EventParams &e) {
I18NCategory *dev = GetI18NCategory("Developer"); I18NCategory *dev = GetI18NCategory("Developer");
auto langScreen = new NewLanguageScreen(dev->T("Language")); auto langScreen = new NewLanguageScreen(dev->T("Language"));
langScreen->OnChoice.Handle(this, &GameSettingsScreen::OnLanguageChange); langScreen->OnChoice.Handle(this, &GameSettingsScreen::OnLanguageChange);
if (e.v)
langScreen->SetPopupOrigin(e.v);
screenManager()->push(langScreen); screenManager()->push(langScreen);
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
@ -1118,6 +1120,8 @@ UI::EventReturn GameSettingsScreen::OnPostProcShader(UI::EventParams &e) {
I18NCategory *gr = GetI18NCategory("Graphics"); I18NCategory *gr = GetI18NCategory("Graphics");
auto procScreen = new PostProcScreen(gr->T("Postprocessing Shader")); auto procScreen = new PostProcScreen(gr->T("Postprocessing Shader"));
procScreen->OnChoice.Handle(this, &GameSettingsScreen::OnPostProcShaderChange); procScreen->OnChoice.Handle(this, &GameSettingsScreen::OnPostProcShaderChange);
if (e.v)
procScreen->SetPopupOrigin(e.v);
screenManager()->push(procScreen); screenManager()->push(procScreen);
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }

View File

@ -150,14 +150,14 @@ public:
private: private:
void TriggerOnHoldClick() { void TriggerOnHoldClick() {
holdStart_ = 0.0; holdStart_ = 0.0;
UI::EventParams e; UI::EventParams e{};
e.v = this; e.v = this;
e.s = gamePath_; e.s = gamePath_;
down_ = false; down_ = false;
OnHoldClick.Trigger(e); OnHoldClick.Trigger(e);
} }
void TriggerOnHighlight(int focusFlags) { void TriggerOnHighlight(int focusFlags) {
UI::EventParams e; UI::EventParams e{};
e.v = this; e.v = this;
e.s = gamePath_; e.s = gamePath_;
e.a = focusFlags; e.a = focusFlags;

View File

@ -242,7 +242,7 @@ static void AfterSaveStateAction(bool status, const std::string &message, void *
UI::EventReturn SaveSlotView::OnLoadState(UI::EventParams &e) { UI::EventReturn SaveSlotView::OnLoadState(UI::EventParams &e) {
g_Config.iCurrentStateSlot = slot_; g_Config.iCurrentStateSlot = slot_;
SaveState::LoadSlot(gamePath_, slot_, &AfterSaveStateAction); SaveState::LoadSlot(gamePath_, slot_, &AfterSaveStateAction);
UI::EventParams e2; UI::EventParams e2{};
e2.v = this; e2.v = this;
OnStateLoaded.Trigger(e2); OnStateLoaded.Trigger(e2);
return UI::EVENT_DONE; return UI::EVENT_DONE;
@ -251,14 +251,14 @@ UI::EventReturn SaveSlotView::OnLoadState(UI::EventParams &e) {
UI::EventReturn SaveSlotView::OnSaveState(UI::EventParams &e) { UI::EventReturn SaveSlotView::OnSaveState(UI::EventParams &e) {
g_Config.iCurrentStateSlot = slot_; g_Config.iCurrentStateSlot = slot_;
SaveState::SaveSlot(gamePath_, slot_, &AfterSaveStateAction); SaveState::SaveSlot(gamePath_, slot_, &AfterSaveStateAction);
UI::EventParams e2; UI::EventParams e2{};
e2.v = this; e2.v = this;
OnStateSaved.Trigger(e2); OnStateSaved.Trigger(e2);
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
UI::EventReturn SaveSlotView::OnScreenshotClick(UI::EventParams &e) { UI::EventReturn SaveSlotView::OnScreenshotClick(UI::EventParams &e) {
UI::EventParams e2; UI::EventParams e2{};
e2.v = this; e2.v = this;
OnScreenshotClicked.Trigger(e2); OnScreenshotClicked.Trigger(e2);
return UI::EVENT_DONE; return UI::EVENT_DONE;

View File

@ -119,7 +119,7 @@ EventReturn RatingChoice::OnChoiceClick(EventParams &e) {
} }
} }
EventParams e2; EventParams e2{};
e2.v = e.v; e2.v = e.v;
e2.a = *value_; e2.a = *value_;
// Dispatch immediately (we're already on the UI thread as we're in an event handler). // Dispatch immediately (we're already on the UI thread as we're in an event handler).

View File

@ -330,7 +330,8 @@ void SavedataBrowser::Refresh() {
UI::EventReturn SavedataBrowser::SavedataButtonClick(UI::EventParams &e) { UI::EventReturn SavedataBrowser::SavedataButtonClick(UI::EventParams &e) {
SavedataButton *button = static_cast<SavedataButton *>(e.v); SavedataButton *button = static_cast<SavedataButton *>(e.v);
UI::EventParams e2; UI::EventParams e2{};
e2.v = e.v;
e2.s = button->GamePath(); e2.s = button->GamePath();
// Insta-update - here we know we are already on the right thread. // Insta-update - here we know we are already on the right thread.
OnChoice.Trigger(e2); OnChoice.Trigger(e2);
@ -378,7 +379,11 @@ void SavedataScreen::CreateViews() {
UI::EventReturn SavedataScreen::OnSavedataButtonClick(UI::EventParams &e) { UI::EventReturn SavedataScreen::OnSavedataButtonClick(UI::EventParams &e) {
GameInfo *ginfo = g_gameInfoCache->GetInfo(screenManager()->getDrawContext(), e.s, 0); GameInfo *ginfo = g_gameInfoCache->GetInfo(screenManager()->getDrawContext(), e.s, 0);
screenManager()->push(new SavedataPopupScreen(e.s, ginfo->GetTitle())); SavedataPopupScreen *popupScreen = new SavedataPopupScreen(e.s, ginfo->GetTitle());
if (e.v) {
popupScreen->SetPopupOrigin(e.v);
}
screenManager()->push(popupScreen);
// the game path: e.s; // the game path: e.s;
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }

View File

@ -313,7 +313,8 @@ UI::EventReturn ProductView::OnLaunchClick(UI::EventParams &e) {
path = ReplaceAll(path, "\\", "/"); path = ReplaceAll(path, "\\", "/");
#endif #endif
UI::EventParams e2; UI::EventParams e2{};
e2.v = e.v;
e2.s = path; e2.s = path;
// Insta-update - here we know we are already on the right thread. // Insta-update - here we know we are already on the right thread.
OnClickLaunch.Trigger(e2); OnClickLaunch.Trigger(e2);

View File

@ -237,7 +237,7 @@ bool PopupScreen::touch(const TouchInput &touch) {
bool PopupScreen::key(const KeyInput &key) { bool PopupScreen::key(const KeyInput &key) {
if (key.flags & KEY_DOWN) { if (key.flags & KEY_DOWN) {
if (key.keyCode == NKCODE_ENTER && defaultButton_) { if (key.keyCode == NKCODE_ENTER && defaultButton_) {
UI::EventParams e; UI::EventParams e{};
defaultButton_->OnClick.Trigger(e); defaultButton_->OnClick.Trigger(e);
return true; return true;
} }
@ -252,32 +252,51 @@ void PopupScreen::update() {
static const int FRAMES_LEAD_IN = 6; static const int FRAMES_LEAD_IN = 6;
static const int FRAMES_LEAD_OUT = 4; static const int FRAMES_LEAD_OUT = 4;
float animatePos = 1.0f;
++frames_; ++frames_;
if (frames_ < FRAMES_LEAD_IN) { if (frames_ < FRAMES_LEAD_IN) {
float leadIn = bezierEaseInOut(frames_ * (1.0f / (float)FRAMES_LEAD_IN)); float leadIn = bezierEaseInOut(frames_ * (1.0f / (float)FRAMES_LEAD_IN));
alpha_ = leadIn; animatePos = 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 if (finishFrame_ > 0) { } else if (finishFrame_ > 0) {
float leadOut = bezierEaseInOut((frames_ - finishFrame_) * (1.0f / (float)FRAMES_LEAD_OUT)); float leadOut = bezierEaseInOut((frames_ - finishFrame_) * (1.0f / (float)FRAMES_LEAD_OUT));
alpha_ = 1.0f - leadOut; animatePos = 1.0f - leadOut;
scale_.x = 0.9f + (1.0f - leadOut) * 0.1f;
scale_.y = 0.9f + (1.0f - leadOut) * 0.1f;
translation_.y = -dp_yres * leadOut * 0.5f;
if (frames_ >= finishFrame_ + FRAMES_LEAD_OUT) { if (frames_ >= finishFrame_ + FRAMES_LEAD_OUT) {
// Actual finish happens here. // Actual finish happens here.
screenManager()->finishDialog(this, finishResult_); screenManager()->finishDialog(this, finishResult_);
} }
}
if (animatePos < 1.0f) {
alpha_ = animatePos;
scale_.x = 0.9f + animatePos * 0.1f;
scale_.y = 0.9f + animatePos * 0.1f;
if (hasPopupOrigin_) {
float xoff = popupOrigin_.x - dp_xres / 2;
float yoff = popupOrigin_.y - dp_yres / 2;
// Pull toward the origin a bit.
translation_.x = xoff * (1.0f - animatePos) * 0.2f;
translation_.y = yoff * (1.0f - animatePos) * 0.2f;
} else {
translation_.y = -dp_yres * (1.0f - animatePos) * 0.2f;
}
} else { } else {
alpha_ = 1.0f; alpha_ = 1.0f;
scale_.x = 1.0f; scale_.x = 1.0f;
scale_.y = 1.0f; scale_.y = 1.0f;
translation_.x = 0.0f;
translation_.y = 0.0f; translation_.y = 0.0f;
} }
} }
void PopupScreen::SetPopupOrigin(const UI::View *view) {
hasPopupOrigin_ = true;
popupOrigin_ = view->GetBounds().Center();
}
void PopupScreen::TriggerFinish(DialogResult result) { void PopupScreen::TriggerFinish(DialogResult result) {
finishFrame_ = frames_; finishFrame_ = frames_;
finishResult_ = result; finishResult_ = result;
@ -391,6 +410,8 @@ UI::EventReturn PopupMultiChoice::HandleClick(UI::EventParams &e) {
ListPopupScreen *popupScreen = new ListPopupScreen(ChopTitle(text_), choices, *value_ - minVal_, ListPopupScreen *popupScreen = new ListPopupScreen(ChopTitle(text_), choices, *value_ - minVal_,
std::bind(&PopupMultiChoice::ChoiceCallback, this, std::placeholders::_1)); std::bind(&PopupMultiChoice::ChoiceCallback, this, std::placeholders::_1));
popupScreen->SetHiddenChoices(hidden_); popupScreen->SetHiddenChoices(hidden_);
if (e.v)
popupScreen->SetPopupOrigin(e.v);
screenManager_->push(popupScreen); screenManager_->push(popupScreen);
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
@ -414,7 +435,7 @@ void PopupMultiChoice::ChoiceCallback(int num) {
*value_ = num + minVal_; *value_ = num + minVal_;
UpdateText(); UpdateText();
UI::EventParams e; UI::EventParams e{};
e.v = this; e.v = this;
e.a = num; e.a = num;
OnChoice.Trigger(e); OnChoice.Trigger(e);
@ -470,6 +491,8 @@ EventReturn PopupSliderChoice::HandleClick(EventParams &e) {
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, ChopTitle(text_), step_, units_); SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, ChopTitle(text_), step_, units_);
popupScreen->OnChange.Handle(this, &PopupSliderChoice::HandleChange); popupScreen->OnChange.Handle(this, &PopupSliderChoice::HandleChange);
if (e.v)
popupScreen->SetPopupOrigin(e.v);
screenManager_->push(popupScreen); screenManager_->push(popupScreen);
return EVENT_DONE; return EVENT_DONE;
} }
@ -512,6 +535,8 @@ EventReturn PopupSliderChoiceFloat::HandleClick(EventParams &e) {
SliderFloatPopupScreen *popupScreen = new SliderFloatPopupScreen(value_, minValue_, maxValue_, ChopTitle(text_), step_, units_); SliderFloatPopupScreen *popupScreen = new SliderFloatPopupScreen(value_, minValue_, maxValue_, ChopTitle(text_), step_, units_);
popupScreen->OnChange.Handle(this, &PopupSliderChoiceFloat::HandleChange); popupScreen->OnChange.Handle(this, &PopupSliderChoiceFloat::HandleChange);
if (e.v)
popupScreen->SetPopupOrigin(e.v);
screenManager_->push(popupScreen); screenManager_->push(popupScreen);
return EVENT_DONE; return EVENT_DONE;
} }
@ -691,8 +716,8 @@ EventReturn SliderFloatPopupScreen::OnTextChange(EventParams &params) {
void SliderPopupScreen::OnCompleted(DialogResult result) { void SliderPopupScreen::OnCompleted(DialogResult result) {
if (result == DR_OK) { if (result == DR_OK) {
*value_ = sliderValue_; *value_ = sliderValue_;
EventParams e; EventParams e{};
e.v = 0; e.v = nullptr;
e.a = *value_; e.a = *value_;
OnChange.Trigger(e); OnChange.Trigger(e);
} }
@ -701,8 +726,8 @@ void SliderPopupScreen::OnCompleted(DialogResult result) {
void SliderFloatPopupScreen::OnCompleted(DialogResult result) { void SliderFloatPopupScreen::OnCompleted(DialogResult result) {
if (result == DR_OK) { if (result == DR_OK) {
*value_ = sliderValue_; *value_ = sliderValue_;
EventParams e; EventParams e{};
e.v = 0; e.v = nullptr;
e.a = (int)*value_; e.a = (int)*value_;
e.f = *value_; e.f = *value_;
OnChange.Trigger(e); OnChange.Trigger(e);
@ -719,6 +744,8 @@ EventReturn PopupTextInputChoice::HandleClick(EventParams &e) {
TextEditPopupScreen *popupScreen = new TextEditPopupScreen(value_, placeHolder_, ChopTitle(text_), maxLen_); TextEditPopupScreen *popupScreen = new TextEditPopupScreen(value_, placeHolder_, ChopTitle(text_), maxLen_);
popupScreen->OnChange.Handle(this, &PopupTextInputChoice::HandleChange); popupScreen->OnChange.Handle(this, &PopupTextInputChoice::HandleChange);
if (e.v)
popupScreen->SetPopupOrigin(e.v);
screenManager_->push(popupScreen); screenManager_->push(popupScreen);
return EVENT_DONE; return EVENT_DONE;
} }
@ -765,7 +792,7 @@ void TextEditPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
void TextEditPopupScreen::OnCompleted(DialogResult result) { void TextEditPopupScreen::OnCompleted(DialogResult result) {
if (result == DR_OK) { if (result == DR_OK) {
*value_ = edit_->GetText(); *value_ = edit_->GetText();
EventParams e; EventParams e{};
e.v = edit_; e.v = edit_;
OnChange.Trigger(e); OnChange.Trigger(e);
} }

View File

@ -74,6 +74,8 @@ public:
virtual void TriggerFinish(DialogResult result) override; virtual void TriggerFinish(DialogResult result) override;
void SetPopupOrigin(const UI::View *view);
protected: protected:
virtual bool FillVertical() const { return false; } virtual bool FillVertical() const { return false; }
virtual UI::Size PopupWidth() const { return 550; } virtual UI::Size PopupWidth() const { return 550; }
@ -92,6 +94,8 @@ private:
int frames_ = 0; int frames_ = 0;
int finishFrame_ = 0; int finishFrame_ = 0;
DialogResult finishResult_; DialogResult finishResult_;
bool hasPopupOrigin_ = false;
Point popupOrigin_;
}; };
class ListPopupScreen : public PopupScreen { class ListPopupScreen : public PopupScreen {

View File

@ -234,7 +234,7 @@ bool View::SetFocus() {
} }
void Clickable::Click() { void Clickable::Click() {
UI::EventParams e; UI::EventParams e{};
e.v = this; e.v = this;
OnClick.Trigger(e); OnClick.Trigger(e);
}; };
@ -874,7 +874,8 @@ bool TextEdit::Key(const KeyInput &input) {
break; break;
case NKCODE_ENTER: case NKCODE_ENTER:
{ {
EventParams e; EventParams e{};
e.v = this;
e.s = text_; e.s = text_;
OnEnter.Trigger(e); OnEnter.Trigger(e);
break; break;
@ -955,7 +956,7 @@ bool TextEdit::Key(const KeyInput &input) {
} }
if (textChanged) { if (textChanged) {
UI::EventParams e; UI::EventParams e{};
e.v = this; e.v = this;
OnTextChange.Trigger(e); OnTextChange.Trigger(e);
} }
@ -1071,7 +1072,7 @@ void Slider::Touch(const TouchInput &input) {
float relativeX = (input.x - (bounds_.x + paddingLeft_)) / (bounds_.w - paddingLeft_ - paddingRight_); float relativeX = (input.x - (bounds_.x + paddingLeft_)) / (bounds_.w - paddingLeft_ - paddingRight_);
*value_ = floorf(relativeX * (maxValue_ - minValue_) + minValue_ + 0.5f); *value_ = floorf(relativeX * (maxValue_ - minValue_) + minValue_ + 0.5f);
Clamp(); Clamp();
EventParams params; EventParams params{};
params.v = this; params.v = this;
params.a = (uint32_t)(*value_); params.a = (uint32_t)(*value_);
params.f = (float)(*value_); params.f = (float)(*value_);
@ -1183,7 +1184,7 @@ void SliderFloat::Touch(const TouchInput &input) {
float relativeX = (input.x - (bounds_.x + paddingLeft_)) / (bounds_.w - paddingLeft_ - paddingRight_); float relativeX = (input.x - (bounds_.x + paddingLeft_)) / (bounds_.w - paddingLeft_ - paddingRight_);
*value_ = (relativeX * (maxValue_ - minValue_) + minValue_); *value_ = (relativeX * (maxValue_ - minValue_) + minValue_);
Clamp(); Clamp();
EventParams params; EventParams params{};
params.v = this; params.v = this;
params.a = (uint32_t)(*value_); params.a = (uint32_t)(*value_);
params.f = (float)(*value_); params.f = (float)(*value_);

View File

@ -1212,7 +1212,7 @@ EventReturn ChoiceStrip::OnChoiceClick(EventParams &e) {
} }
} }
EventParams e2; EventParams e2{};
e2.v = views_[selected_]; e2.v = views_[selected_];
e2.a = selected_; e2.a = selected_;
// Set to 1 to indicate an explicit click. // Set to 1 to indicate an explicit click.
@ -1232,7 +1232,7 @@ void ChoiceStrip::SetSelection(int sel) {
newChoice->Press(); newChoice->Press();
if (topTabs_ && prevSelected != selected_) { if (topTabs_ && prevSelected != selected_) {
EventParams e; EventParams e{};
e.v = views_[selected_]; e.v = views_[selected_];
e.a = selected_; e.a = selected_;
// Set to 0 to indicate a selection change (not a click.) // Set to 0 to indicate a selection change (not a click.)
@ -1305,8 +1305,8 @@ void ListView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert)
} }
EventReturn ListView::OnItemCallback(int num, EventParams &e) { EventReturn ListView::OnItemCallback(int num, EventParams &e) {
EventParams ev; EventParams ev{};
ev.v = 0; ev.v = nullptr;
ev.a = num; ev.a = num;
adaptor_->SetSelected(num); adaptor_->SetSelected(num);
View *focused = GetFocusedView(); View *focused = GetFocusedView();