Also move out the global stuff from view.cpp/h to root.cpp/h

This commit is contained in:
Henrik Rydgård 2020-03-08 15:16:32 +01:00
parent 271f79ea63
commit c176c6c114
11 changed files with 119 additions and 110 deletions

View File

@ -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"

View File

@ -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;

View File

@ -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;

View File

@ -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"

View File

@ -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;
}

View File

@ -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"

View File

@ -1,4 +1,5 @@
#include <mutex>
#include <deque>
#include "base/timeutil.h"
#include "ui/root.h"
@ -10,6 +11,94 @@ static std::mutex focusLock;
static std::vector<int> 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<DispatchQueueItem> g_dispatchQueue;
void EventTriggered(Event *e, EventParams params) {
DispatchQueueItem item;
item.e = e;
item.params = params;
std::unique_lock<std::mutex> guard(eventMutex_);
g_dispatchQueue.push_front(item);
}
void DispatchEvents() {
while (true) {
DispatchQueueItem item;
{
std::unique_lock<std::mutex> 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");

View File

@ -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

View File

@ -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"

View File

@ -1,4 +1,3 @@
#include <queue>
#include <algorithm>
#include <mutex>
@ -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<DispatchQueueItem> g_dispatchQueue;
void EventTriggered(Event *e, EventParams params) {
DispatchQueueItem item;
item.e = e;
item.params = params;
std::unique_lock<std::mutex> guard(eventMutex_);
g_dispatchQueue.push_front(item);
}
void DispatchEvents() {
while (true) {
DispatchQueueItem item;
{
std::unique_lock<std::mutex> 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_)

View File

@ -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);