fixed camera rotation
This commit is contained in:
31
src/modules/stream/editor_event.cpp
Normal file
31
src/modules/stream/editor_event.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#undef NDEBUG
|
||||
#include <cassert>
|
||||
|
||||
#include "editor_event.h"
|
||||
|
||||
EditorEvent *EditorEvent::singleton = nullptr;
|
||||
|
||||
EditorEvent::EditorEvent()
|
||||
{
|
||||
}
|
||||
|
||||
EditorEvent::~EditorEvent()
|
||||
{
|
||||
}
|
||||
|
||||
EditorEvent *EditorEvent::get_singleton()
|
||||
{
|
||||
if (!singleton)
|
||||
singleton = memnew(EditorEvent);
|
||||
return singleton;
|
||||
}
|
||||
|
||||
void EditorEvent::EventHelper::emit(const String &event, const Array &args)
|
||||
{
|
||||
auto evl = listeners.begin();
|
||||
while (evl != listeners.end()) {
|
||||
const event_listener_ptrs &xev = *evl;
|
||||
xev.execute(event, args);
|
||||
evl++;
|
||||
}
|
||||
}
|
||||
76
src/modules/stream/editor_event.h
Normal file
76
src/modules/stream/editor_event.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef EDITOR_EVENT_H
|
||||
#define EDITOR_EVENT_H
|
||||
#include <core/ustring.h>
|
||||
#include <list>
|
||||
class EditorEvent {
|
||||
public:
|
||||
class EventHelper {
|
||||
class event_listener_ptrs {
|
||||
public:
|
||||
class H {};
|
||||
H *obj;
|
||||
void (H::*method)(const String &event,
|
||||
const Array &args);
|
||||
void execute(const String &event,
|
||||
const Array &args) const
|
||||
{
|
||||
(obj->*method)(event, args);
|
||||
}
|
||||
};
|
||||
std::list<event_listener_ptrs> listeners;
|
||||
typedef event_listener_ptrs::H *obj_t;
|
||||
typedef void (event_listener_ptrs::H::*method_t)(
|
||||
const String &event, const Array &args);
|
||||
|
||||
public:
|
||||
template <class T>
|
||||
void add_listener(T *obj, void (T::*method)(const String &event,
|
||||
const Array &args));
|
||||
template <class T>
|
||||
void remove_listener(T *obj,
|
||||
void (T::*method)(const String &event,
|
||||
const Array &args));
|
||||
void emit(const String &event, const Array &args);
|
||||
};
|
||||
EventHelper event;
|
||||
|
||||
private:
|
||||
static EditorEvent *singleton;
|
||||
EditorEvent();
|
||||
virtual ~EditorEvent();
|
||||
|
||||
public:
|
||||
static EditorEvent *get_singleton();
|
||||
};
|
||||
template <class T>
|
||||
void EditorEvent::EventHelper::remove_listener(
|
||||
T *obj, void (T::*method)(const String &event, const Array &args))
|
||||
{
|
||||
listeners.remove_if([obj, method](const event_listener_ptrs &e) {
|
||||
return e.obj == reinterpret_cast<obj_t>(obj) &&
|
||||
e.method == reinterpret_cast<method_t>(method);
|
||||
});
|
||||
}
|
||||
template <class T>
|
||||
void EditorEvent::EventHelper::add_listener(
|
||||
T *obj, void (T::*method)(const String &event, const Array &args))
|
||||
{
|
||||
auto evl = listeners.begin();
|
||||
bool bad = false;
|
||||
while (evl != listeners.end()) {
|
||||
const event_listener_ptrs &xev = *evl;
|
||||
if (xev.obj == reinterpret_cast<obj_t>(obj) &&
|
||||
xev.method == reinterpret_cast<method_t>(method)) {
|
||||
bad = true;
|
||||
break;
|
||||
}
|
||||
evl++;
|
||||
}
|
||||
if (bad)
|
||||
return;
|
||||
event_listener_ptrs ev;
|
||||
ev.obj = reinterpret_cast<obj_t>(obj);
|
||||
ev.method = reinterpret_cast<method_t>(method);
|
||||
listeners.push_back(ev);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user