diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index f17e205396..bf82b6a3ac 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -1,4 +1,5 @@ #include "ppsspp_config.h" +#include "ui/root.h" #include "ui/ui_context.h" #include "ui/view.h" #include "ui/viewgroup.h" diff --git a/UI/ComboKeyMappingScreen.cpp b/UI/ComboKeyMappingScreen.cpp index 90dc84b1e3..e309ba35b3 100644 --- a/UI/ComboKeyMappingScreen.cpp +++ b/UI/ComboKeyMappingScreen.cpp @@ -31,7 +31,7 @@ #include "ui/view.h" #include "ui/viewgroup.h" -void Combo_keyScreen::CreateViews() { +void ComboKeyScreen::CreateViews() { using namespace UI; auto co = GetI18NCategory("Controls"); root_ = new LinearLayout(ORIENT_VERTICAL); @@ -51,7 +51,7 @@ void Combo_keyScreen::CreateViews() { comboselect->AddChoice(comboKeyImages[i]); } comboselect->SetSelection(*mode); - comboselect->OnChoice.Handle(this, &Combo_keyScreen::onCombo); + comboselect->OnChoice.Handle(this, &ComboKeyScreen::onCombo); leftColumn->Add(comboselect); root__->Add(leftColumn); rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)); @@ -175,7 +175,7 @@ static int arrayToInt(bool ary[16]) { return value >> 1; } -void Combo_keyScreen::onFinish(DialogResult result) { +void ComboKeyScreen::onFinish(DialogResult result) { switch (*mode) { case 0: g_Config.iCombokey0 = arrayToInt(array); @@ -193,17 +193,17 @@ void Combo_keyScreen::onFinish(DialogResult result) { g_Config.iCombokey4 = arrayToInt(array); break; } - g_Config.Save("Combo_keyScreen::onFInish"); + g_Config.Save("ComboKeyScreen::onFInish"); } -UI::EventReturn Combo_keyScreen::ChoiceEventHandler::onChoiceClick(UI::EventParams &e){ +UI::EventReturn ComboKeyScreen::ChoiceEventHandler::onChoiceClick(UI::EventParams &e){ checkbox_->Toggle(); return UI::EVENT_DONE; }; -UI::EventReturn Combo_keyScreen::onCombo(UI::EventParams &e) { +UI::EventReturn ComboKeyScreen::onCombo(UI::EventParams &e) { switch (*mode){ case 0:g_Config.iCombokey0 = arrayToInt(array); break; diff --git a/UI/ComboKeyMappingScreen.h b/UI/ComboKeyMappingScreen.h index 34044869ad..bafc3a974b 100644 --- a/UI/ComboKeyMappingScreen.h +++ b/UI/ComboKeyMappingScreen.h @@ -25,9 +25,9 @@ namespace UI { class CheckBox; } -class Combo_keyScreen : public UIDialogScreenWithBackground { +class ComboKeyScreen : public UIDialogScreenWithBackground { public: - Combo_keyScreen(int *key): mode(key) {} + ComboKeyScreen(int *key): mode(key) {} void CreateViews() override; void onFinish(DialogResult result) override; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 39a9d5104d..efe0479bf1 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -26,6 +26,7 @@ #include "i18n/i18n.h" #include "input/keycodes.h" #include "input/input_state.h" +#include "ui/root.h" #include "ui/ui.h" #include "ui/ui_context.h" #include "ui/view.h" diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 5b14871522..d7e995f288 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -28,6 +28,7 @@ #include "gfx_es2/draw_buffer.h" #include "i18n/i18n.h" #include "util/text/utf8.h" +#include "ui/root.h" #include "ui/view.h" #include "ui/viewgroup.h" #include "ui/ui_context.h" @@ -1403,7 +1404,7 @@ UI::EventReturn GameSettingsScreen::OnChangeMacAddress(UI::EventParams &e) { } UI::EventReturn GameSettingsScreen::OnComboKey(UI::EventParams &e) { - screenManager()->push(new Combo_keyScreen(&g_Config.iComboMode)); + screenManager()->push(new ComboKeyScreen(&g_Config.iComboMode)); return UI::EVENT_DONE; } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 0cbd326b66..57f500faa5 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -27,6 +27,7 @@ #include "gfx_es2/draw_buffer.h" #include "math/curves.h" #include "base/stringutil.h" +#include "ui/root.h" #include "ui/ui_context.h" #include "ui/view.h" #include "ui/viewgroup.h" diff --git a/ext/native/ui/root.cpp b/ext/native/ui/root.cpp index dd2b610a99..fd805c62e3 100644 --- a/ext/native/ui/root.cpp +++ b/ext/native/ui/root.cpp @@ -1,4 +1,5 @@ #include +#include #include "base/timeutil.h" #include "ui/root.h" @@ -10,6 +11,94 @@ static std::mutex focusLock; static std::vector focusMoves; extern bool focusForced; +static View *focusedView; +static bool focusMovementEnabled; +bool focusForced; +static std::mutex eventMutex_; // needs recursivity! + +struct DispatchQueueItem { + Event *e; + EventParams params; +}; + +std::deque g_dispatchQueue; + +void EventTriggered(Event *e, EventParams params) { + DispatchQueueItem item; + item.e = e; + item.params = params; + + std::unique_lock guard(eventMutex_); + g_dispatchQueue.push_front(item); +} + +void DispatchEvents() { + while (true) { + DispatchQueueItem item; + { + std::unique_lock guard(eventMutex_); + if (g_dispatchQueue.empty()) + break; + item = g_dispatchQueue.back(); + g_dispatchQueue.pop_back(); + } + if (item.e) { + item.e->Dispatch(item.params); + } + } +} + +void RemoveQueuedEventsByView(View *view) { + for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) { + if (it->params.v == view) { + it = g_dispatchQueue.erase(it); + } else { + ++it; + } + } +} + +void RemoveQueuedEventsByEvent(Event *event) { + for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) { + if (it->e == event) { + it = g_dispatchQueue.erase(it); + } else { + ++it; + } + } +} + +View *GetFocusedView() { + return focusedView; +} + +void SetFocusedView(View *view, bool force) { + if (focusedView) { + focusedView->FocusChanged(FF_LOSTFOCUS); + } + focusedView = view; + if (focusedView) { + focusedView->FocusChanged(FF_GOTFOCUS); + if (force) { + focusForced = true; + } + } +} + +void EnableFocusMovement(bool enable) { + focusMovementEnabled = enable; + if (!enable) { + if (focusedView) { + focusedView->FocusChanged(FF_LOSTFOCUS); + } + focusedView = 0; + } +} + +bool IsFocusMovementEnabled() { + return focusMovementEnabled; +} + void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root) { if (!root) { ELOG("Tried to layout a view hierarchy from a zero pointer root"); diff --git a/ext/native/ui/root.h b/ext/native/ui/root.h index 69730aa8e4..a51a20d095 100644 --- a/ext/native/ui/root.h +++ b/ext/native/ui/root.h @@ -5,6 +5,18 @@ namespace UI { +// The ONLY global is the currently focused item. +// Can be and often is null. +void EnableFocusMovement(bool enable); +bool IsFocusMovementEnabled(); +View *GetFocusedView(); +void SetFocusedView(View *view, bool force = false); +void RemoveQueuedEventsByEvent(Event *e); +void RemoveQueuedEventsByView(View * v); + +void EventTriggered(Event *e, EventParams params); +void DispatchEvents(); + class ViewGroup; void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root); @@ -14,4 +26,4 @@ bool KeyEvent(const KeyInput &key, ViewGroup *root); bool TouchEvent(const TouchInput &touch, ViewGroup *root); bool AxisEvent(const AxisInput &axis, ViewGroup *root); -} +} // namespace UI diff --git a/ext/native/ui/screen.cpp b/ext/native/ui/screen.cpp index 3bdfb5cb9f..a5e105aa56 100644 --- a/ext/native/ui/screen.cpp +++ b/ext/native/ui/screen.cpp @@ -2,6 +2,7 @@ #include "base/logging.h" #include "base/timeutil.h" #include "input/input_state.h" +#include "ui/root.h" #include "ui/screen.h" #include "ui/ui.h" #include "ui/view.h" diff --git a/ext/native/ui/view.cpp b/ext/native/ui/view.cpp index 01376c4c09..d452b6a8a3 100644 --- a/ext/native/ui/view.cpp +++ b/ext/native/ui/view.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -13,103 +12,16 @@ #include "ui/view.h" #include "ui/ui_context.h" #include "ui/ui_tween.h" +#include "ui/root.h" #include "thin3d/thin3d.h" #include "base/NativeApp.h" namespace UI { -static View *focusedView; -static bool focusMovementEnabled; -bool focusForced; -static std::mutex eventMutex_; // needs recursivity! - const float ITEM_HEIGHT = 64.f; const float MIN_TEXT_SCALE = 0.8f; const float MAX_ITEM_SIZE = 65535.0f; -struct DispatchQueueItem { - Event *e; - EventParams params; -}; - -std::deque g_dispatchQueue; - -void EventTriggered(Event *e, EventParams params) { - DispatchQueueItem item; - item.e = e; - item.params = params; - - std::unique_lock guard(eventMutex_); - g_dispatchQueue.push_front(item); -} - -void DispatchEvents() { - while (true) { - DispatchQueueItem item; - { - std::unique_lock guard(eventMutex_); - if (g_dispatchQueue.empty()) - break; - item = g_dispatchQueue.back(); - g_dispatchQueue.pop_back(); - } - if (item.e) { - item.e->Dispatch(item.params); - } - } -} - -void RemoveQueuedEvents(View *v) { - for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) { - if (it->params.v == v) { - it = g_dispatchQueue.erase(it); - } else { - ++it; - } - } -} - -void RemoveQueuedEvents(Event *e) { - for (auto it = g_dispatchQueue.begin(); it != g_dispatchQueue.end(); ) { - if (it->e == e) { - it = g_dispatchQueue.erase(it); - } else { - ++it; - } - } -} - -View *GetFocusedView() { - return focusedView; -} - -void SetFocusedView(View *view, bool force) { - if (focusedView) { - focusedView->FocusChanged(FF_LOSTFOCUS); - } - focusedView = view; - if (focusedView) { - focusedView->FocusChanged(FF_GOTFOCUS); - if (force) { - focusForced = true; - } - } -} - -void EnableFocusMovement(bool enable) { - focusMovementEnabled = enable; - if (!enable) { - if (focusedView) { - focusedView->FocusChanged(FF_LOSTFOCUS); - } - focusedView = 0; - } -} - -bool IsFocusMovementEnabled() { - return focusMovementEnabled; -} - void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measured) { *measured = sz; if (sz == WRAP_CONTENT) { @@ -172,13 +84,13 @@ EventReturn Event::Dispatch(EventParams &e) { Event::~Event() { handlers_.clear(); - RemoveQueuedEvents(this); + RemoveQueuedEventsByEvent(this); } View::~View() { if (HasFocus()) SetFocusedView(0); - RemoveQueuedEvents(this); + RemoveQueuedEventsByView(this); // Could use unique_ptr, but then we have to include tween everywhere. for (auto &tween : tweens_) diff --git a/ext/native/ui/view.h b/ext/native/ui/view.h index 8bcbbe7a0d..9bd45d8757 100644 --- a/ext/native/ui/view.h +++ b/ext/native/ui/view.h @@ -45,13 +45,6 @@ namespace UI { class View; -// The ONLY global is the currently focused item. -// Can be and often is null. -void EnableFocusMovement(bool enable); -bool IsFocusMovementEnabled(); -View *GetFocusedView(); -void SetFocusedView(View *view, bool force = false); - enum DrawableType { DRAW_NOTHING, DRAW_SOLID_COLOR, @@ -908,8 +901,6 @@ private: void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measured); -void EventTriggered(Event *e, EventParams params); -void DispatchEvents(); bool IsDPadKey(const KeyInput &key); bool IsAcceptKey(const KeyInput &key); bool IsEscapeKey(const KeyInput &key);