mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 19:13:40 +01:00
Improve event processing semantics a little. Add a safety check I'm not sure is needed.
This commit is contained in:
1 parent
788d512515
commit
eed7159a06
2 files changed
+26
-10
No files matched your search
+21
-7
@@ -26,7 +26,7 @@ struct DispatchQueueItem {
|
||||
EventParams params;
|
||||
};
|
||||
|
||||
std::queue<DispatchQueueItem> g_dispatchQueue;
|
||||
std::deque<DispatchQueueItem> g_dispatchQueue;
|
||||
|
||||
|
||||
void EventTriggered(Event *e, EventParams params) {
|
||||
@@ -35,7 +35,7 @@ void EventTriggered(Event *e, EventParams params) {
|
||||
DispatchQueueItem item;
|
||||
item.e = e;
|
||||
item.params = params;
|
||||
g_dispatchQueue.push(item);
|
||||
g_dispatchQueue.push_front(item);
|
||||
}
|
||||
|
||||
void DispatchEvents() {
|
||||
@@ -43,11 +43,19 @@ void DispatchEvents() {
|
||||
|
||||
while (!g_dispatchQueue.empty()) {
|
||||
DispatchQueueItem item = g_dispatchQueue.back();
|
||||
g_dispatchQueue.pop();
|
||||
item.e->Dispatch(item.params);
|
||||
g_dispatchQueue.pop_back();
|
||||
if (item.e) {
|
||||
item.e->Dispatch(item.params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveQueuedEvents(View *v) {
|
||||
for (int i = 0; i < g_dispatchQueue.size(); i++) {
|
||||
if (g_dispatchQueue[i].params.v == v)
|
||||
g_dispatchQueue.erase(g_dispatchQueue.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
View *GetFocusedView() {
|
||||
return focusedView;
|
||||
@@ -107,10 +115,16 @@ EventReturn Event::Dispatch(EventParams &e) {
|
||||
for (auto iter = handlers_.begin(); iter != handlers_.end(); ++iter) {
|
||||
if ((iter->func)(e) == UI::EVENT_DONE) {
|
||||
// Event is handled, stop looping immediately. This event might even have gotten deleted.
|
||||
eventHandled = true;
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
}
|
||||
return eventHandled ? UI::EVENT_DONE : UI::EVENT_SKIPPED;
|
||||
return UI::EVENT_SKIPPED;
|
||||
}
|
||||
|
||||
View::~View() {
|
||||
if (HasFocus())
|
||||
SetFocusedView(0);
|
||||
RemoveQueuedEvents(this);
|
||||
}
|
||||
|
||||
void View::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {
|
||||
@@ -374,7 +388,7 @@ void PopupHeader::Draw(UIContext &dc) {
|
||||
EventReturn CheckBox::OnClicked(EventParams &e) {
|
||||
if (toggle_)
|
||||
*toggle_ = !(*toggle_);
|
||||
return EVENT_DONE;
|
||||
return EVENT_CONTINUE; // It's safe to keep processing events.
|
||||
}
|
||||
|
||||
void CheckBox::Draw(UIContext &dc) {
|
||||
|
||||
@@ -180,9 +180,11 @@ enum MeasureSpecType {
|
||||
AT_MOST,
|
||||
};
|
||||
|
||||
// I hope I can find a way to simplify this one day.
|
||||
enum EventReturn {
|
||||
EVENT_DONE,
|
||||
EVENT_SKIPPED,
|
||||
EVENT_DONE, // Return this when no other view may process this event, for example if you changed the view hierarchy
|
||||
EVENT_SKIPPED, // Return this if you ignored an event
|
||||
EVENT_CONTINUE, // Return this if it's safe to send this event along. This hsould normally be the default choice but often EVENT_DONE is necessary.
|
||||
};
|
||||
|
||||
enum FocusFlags {
|
||||
@@ -292,7 +294,7 @@ public:
|
||||
layoutParams_.reset(new LayoutParams());
|
||||
}
|
||||
|
||||
virtual ~View() { if (HasFocus()) SetFocusedView(0); }
|
||||
virtual ~View();
|
||||
|
||||
// Please note that Touch is called ENTIRELY asynchronously from drawing!
|
||||
// Can even be called on a different thread! This is to really minimize latency, and decouple
|
||||
|
||||
Reference in new issue
Block a user