diff --git a/Common/System/OSD.cpp b/Common/System/OSD.cpp index 7c3bb7c7c1..7a896f20a6 100644 --- a/Common/System/OSD.cpp +++ b/Common/System/OSD.cpp @@ -39,6 +39,13 @@ float OnScreenDisplay::SidebarAlpha() const { return saturatef(1.0f - ((float)timeSinceNudge - 0.1f) * 4.0f); } +void OnScreenDisplay::DismissEntry(size_t index, double now) { + std::lock_guard guard(mutex_); + if (index < entries_.size() && entries_[index].type != OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR) { + entries_[index].endTime = std::min(now + FadeoutTime(), entries_[index].endTime); + } +} + void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::string &text2, const std::string &icon, float duration_s, const char *id) { // Automatic duration based on type. if (duration_s <= 0.0f) { diff --git a/Common/System/OSD.h b/Common/System/OSD.h index dd288c01a2..4f81e4ad39 100644 --- a/Common/System/OSD.h +++ b/Common/System/OSD.h @@ -87,6 +87,9 @@ public: std::vector Entries(); + // TODO: Use something more stable than the index. + void DismissEntry(size_t index, double now); + static float FadeinTime() { return 0.1f; } static float FadeoutTime() { return 0.25f; } diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 08ce0a31eb..d42eee36af 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -48,6 +48,9 @@ void ScreenManager::update() { switchToNext(); } + if (overlayScreen_) { + overlayScreen_->update(); + } if (stack_.size()) { stack_.back().screen->update(); } @@ -90,6 +93,10 @@ void ScreenManager::touch(const TouchInput &touch) { layer.screen->UnsyncTouch(screen->transformTouch(touch)); } } else if (!stack_.empty()) { + // Let the overlay know about touch-downs, to be able to dismiss popups. + if (overlayScreen_ && (touch.flags & TOUCH_DOWN)) { + overlayScreen_->UnsyncTouch(overlayScreen_->transformTouch(touch)); + } Screen *screen = stack_.back().screen; stack_.back().screen->UnsyncTouch(screen->transformTouch(touch)); } diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index 2258ba6cc4..954392e09c 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -448,9 +448,19 @@ void OnScreenMessagesView::Draw(UIContext &dc) { } } + // Quick hack for dismissing messages by touch. + for (auto &touch : touches_) { + if (b.Contains(touch.x, touch.y)) { + INFO_LOG(G3D, "Dismissing entry %d (%0.1f %0.1f vs %0.1f %0.1f %0.1f %0.f)", j, touch.x, touch.y, bounds_.x, bounds_.y, bounds_.w, bounds_.h); + g_OSD.DismissEntry(j, now); + } + } + y += (measuredEntry.h + 4.0f) * measuredEntry.alpha; } } + + touches_.clear(); } std::string OnScreenMessagesView::DescribeText() const { @@ -465,6 +475,13 @@ std::string OnScreenMessagesView::DescribeText() const { return ss.str(); } +bool OnScreenMessagesView::Touch(const TouchInput &input) { + if (input.flags & TOUCH_DOWN) { + touches_.push_back(input); + } + return true; +} + void OSDOverlayScreen::CreateViews() { root_ = new UI::AnchorLayout(); root_->SetTag("OSDOverlayScreen"); diff --git a/UI/OnScreenDisplay.h b/UI/OnScreenDisplay.h index 5cde5cf585..480c34780d 100644 --- a/UI/OnScreenDisplay.h +++ b/UI/OnScreenDisplay.h @@ -21,7 +21,10 @@ class OnScreenMessagesView : public UI::InertView { public: OnScreenMessagesView(UI::LayoutParams *layoutParams = nullptr) : UI::InertView(layoutParams) {} void Draw(UIContext &dc) override; + bool Touch(const TouchInput &input) override; std::string DescribeText() const override; +private: + std::vector touches_; }; class OSDOverlayScreen : public UIScreen {