Added missing file
This commit is contained in:
94
src/modules/stream/signal_handler.h
Normal file
94
src/modules/stream/signal_handler.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/* ~/godot-projects/streaming_world/src/modules/stream/signal_handler.h */
|
||||
#ifndef SIGNAL_HANDLER_H_
|
||||
#define SIGNAL_HANDLER_H_
|
||||
#include <core/object.h>
|
||||
#include "editor_event.h"
|
||||
|
||||
#define _GODOT_HANDLER_METHOD(class_name, obj_name, sig_name, event_name, \
|
||||
hdecl, hargs, hbind) \
|
||||
class class_name : public Object { \
|
||||
GDCLASS(class_name, Object) \
|
||||
obj_name *ob; \
|
||||
\
|
||||
public: \
|
||||
class_name(obj_name *ob) \
|
||||
: Object() \
|
||||
, ob(ob) \
|
||||
{ \
|
||||
ob->connect(#sig_name, this, "handler"); \
|
||||
} \
|
||||
~class_name() \
|
||||
{ \
|
||||
ob->disconnect(#sig_name, this, "handler"); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
void handler hdecl \
|
||||
{ \
|
||||
Vector<Variant> args = varray hargs; \
|
||||
args.insert(0, ob); \
|
||||
EditorEvent::get_singleton()->event.emit(#event_name, \
|
||||
args); \
|
||||
} \
|
||||
static void _bind_methods() \
|
||||
{ \
|
||||
ClassDB::bind_method(hbind, &class_name::handler); \
|
||||
} \
|
||||
};
|
||||
#define GODOT_HANDLER_METHOD(class_name, obj_name, sig_name, event_name, \
|
||||
hdecl, hargs, hbind) \
|
||||
_GODOT_HANDLER_METHOD(class_name##__LINE__, obj_name, sig_name, \
|
||||
event_name, hdecl, hargs, hbind)
|
||||
|
||||
#define _GODOT_HANDLER_EVENT_METHOD(class_name, obj_name, sig_name, hdecl, \
|
||||
hargs, hbind) \
|
||||
class class_name : public Object { \
|
||||
GDCLASS(class_name, Object) \
|
||||
obj_name *ob; \
|
||||
String event_name; \
|
||||
\
|
||||
public: \
|
||||
class_name(obj_name *ob, const String &event_name) \
|
||||
: Object() \
|
||||
, ob(ob) \
|
||||
, event_name(event_name) \
|
||||
{ \
|
||||
Error err; \
|
||||
assert(ob); \
|
||||
err = ob->connect(#sig_name, this, "handler"); \
|
||||
assert(err == OK); \
|
||||
} \
|
||||
~class_name() \
|
||||
{ \
|
||||
if (ob) \
|
||||
ob->disconnect(#sig_name, this, "handler"); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
void handler hdecl \
|
||||
{ \
|
||||
Vector<Variant> args = varray hargs; \
|
||||
args.insert(0, ob); \
|
||||
EditorEvent::get_singleton()->event.emit(event_name, \
|
||||
args); \
|
||||
} \
|
||||
static void _bind_methods() \
|
||||
{ \
|
||||
ClassDB::bind_method(hbind, &class_name::handler); \
|
||||
} \
|
||||
};
|
||||
#define _GODOT_HANDLER_CONCAT(a, b) a##b
|
||||
#define _GODOT_HANDLER_CONCAT2(a, b) _GODOT_HANDLER_CONCAT(a, b)
|
||||
#define GODOT_HANDLER_EVENT_METHOD(class_name, obj_name, sig_name, hdecl, \
|
||||
hargs, hbind) \
|
||||
_GODOT_HANDLER_EVENT_METHOD(_GODOT_HANDLER_CONCAT2(class_name, \
|
||||
__LINE__), \
|
||||
obj_name, sig_name, hdecl, hargs, hbind) \
|
||||
typedef _GODOT_HANDLER_CONCAT2(class_name, __LINE__) class_name;
|
||||
|
||||
GODOT_HANDLER_METHOD(BrushSelectHandler, OptionButton, item_selected,
|
||||
brush_select, (int id), (id), D_METHOD("handler", "id"))
|
||||
GODOT_HANDLER_EVENT_METHOD(OptionButtonHandler, OptionButton, item_selected,
|
||||
(int id), (id), D_METHOD("handler", "id"))
|
||||
|
||||
#endif // SIGNAL_HANDLER_H_
|
||||
Reference in New Issue
Block a user