Permalink
Browse files

updated

  • Loading branch information...
mikeseven committed Sep 13, 2015
1 parent 8f6a750 commit ac759f24d45a26ddc0fa6328dfbed4f333cc31d4
Showing with 41 additions and 39 deletions.
  1. +16 −16 src/atb.cc
  2. +7 −7 src/atb.h
  3. +18 −16 src/glfw.cc
View
@@ -14,7 +14,7 @@ NAN_MODULE_INIT(AntTweakBar::Initialize)
{
Nan::HandleScope scope;
Local<FunctionTemplate> ctor = FunctionTemplate::New(AntTweakBar::New);
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(AntTweakBar::New);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(JS_STR("AntTweakBar"));
@@ -51,8 +51,8 @@ NAN_MODULE_INIT(AntTweakBar::Initialize)
//DEFINE_ATB_CONSTANT(CDSTRING);
NanAssignPersistent<Function>(constructor_template, ctor->GetFunction());
target->Set(JS_STR("AntTweakBar"), ctor->GetFunction());
constructor_template.Reset(ctor->GetFunction());
Nan::Set(target, JS_STR("AntTweakBar"), ctor->GetFunction());
}
NAN_METHOD(AntTweakBar::New) {
@@ -150,7 +150,7 @@ NAN_METHOD(AntTweakBar::NewBar) {
String::Utf8Value str(info[0]);
TwBar *bar = TwNewBar(info.Length()!=1 ? "AntTweakBar" : *str);
info.GetReturnValue().Set(atb::Bar::New(bar->handle()));
info.GetReturnValue().Set(atb::Bar::New(bar)->handle());
}
Nan::Persistent<Function> Bar::constructor_template;
@@ -159,7 +159,7 @@ NAN_MODULE_INIT(Bar::Initialize)
{
Nan::HandleScope scope;
Local<FunctionTemplate> ctor = FunctionTemplate::New(Bar::New);
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(Bar::New);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(JS_STR("Bar"));
@@ -169,8 +169,8 @@ NAN_MODULE_INIT(Bar::Initialize)
Nan::SetPrototypeMethod(ctor, "AddButton", AddButton);
Nan::SetPrototypeMethod(ctor, "AddSeparator", AddSeparator);
NanAssignPersistent<Function>(constructor_template, ctor->GetFunction());
target->Set(JS_STR("Bar"), ctor->GetFunction());
constructor_template.Reset(ctor->GetFunction());
Nan::Set(target, JS_STR("Bar"), ctor->GetFunction());
}
NAN_METHOD(Bar::New) {
@@ -217,7 +217,7 @@ void TW_CALL SetCallback(const void *value, void *clientData) {
CB *cb=static_cast<CB*>(clientData);
// cout<<" cb type: "<<cb->type<<endl;
Handle<Value> argv[1];
Local<Value> argv[1];
switch(cb->type) {
case TW_TYPE_INT8:
@@ -246,7 +246,7 @@ void TW_CALL SetCallback(const void *value, void *clientData) {
break;
case TW_TYPE_DIR3F: {
const float *val=static_cast<const float*>(value);
Local<Array> arr=Array::New(3);
Local<Array> arr=Nan::New<Array>(3);
arr->Set(0,JS_NUM(val[0]));
arr->Set(1,JS_NUM(val[1]));
arr->Set(2,JS_NUM(val[2]));
@@ -262,7 +262,7 @@ void TW_CALL SetCallback(const void *value, void *clientData) {
TryCatch try_catch;
Local<Function> constructorHandle = Nan::New(cb->setter);
constructorHandle->Call(Context::GetCurrent()->Global(), 1, argv);
constructorHandle->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), 1, argv);
if (try_catch.HasCaught())
FatalException(try_catch);
@@ -276,8 +276,8 @@ void TW_CALL GetCallback(void *value, void *clientData) {
CB *cb=static_cast<CB*>(clientData);
// build callback values
Handle<Value> argv[1];
argv[0]=Undefined();
Local<Value> argv[1];
argv[0]=Nan::Undefined();
TryCatch try_catch;
@@ -291,7 +291,7 @@ void TW_CALL GetCallback(void *value, void *clientData) {
// cout<<"getter name: "<<*str<<" callable? "<<fct->IsCallable()<<" function? "<<fct->IsFunction()<<endl;
// cout<<" global has getter()? "<<global->Has(name->ToString())<<endl;
Local<Value> val=fct->Call(Context::GetCurrent()->Global(), 1, argv);
Local<Value> val=fct->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), 1, argv);
if (try_catch.HasCaught())
FatalException(try_catch);
@@ -389,13 +389,13 @@ void TW_CALL SetButtonCallback(void *clientData) {
CB *cb=static_cast<CB*>(clientData);
//cout<<" cb type: "<<cb->type<<endl;
Handle<Value> argv[1];
argv[0]=Undefined();
Local<Value> argv[1];
argv[0]=Nan::Undefined();
TryCatch try_catch;
Local<Function> constructorHandle = Nan::New(cb->setter);
constructorHandle->Call(Context::GetCurrent()->Global(), 1, argv);
constructorHandle->Call(v8::Isolate::GetCurrent()->GetCurrentContext()->Global(), 1, argv);
if (try_catch.HasCaught())
FatalException(try_catch);
View
@@ -18,21 +18,21 @@ using namespace node;
namespace atb {
struct CB {
Persistent<Function> getter, setter;
Nan::Persistent<Function> getter, setter;
uint32_t type;
char *name;
CB() : type(0), name(NULL) {}
~CB() {
getter.Dispose();
setter.Dispose();
getter.Reset();
setter.Reset();
if(name) free(name);
}
};
class Bar : public Nan::ObjectWrap {
public:
static Bar *New(TwBar *bar);
static void Initialize (Handle<Object> target);
static NAN_MODULE_INIT(Initialize);
protected:
static NAN_METHOD(New);
@@ -46,15 +46,15 @@ class Bar : public Nan::ObjectWrap {
private:
Bar(Handle<Object> wrapper);
static Persistent<Function> constructor_template;
static Nan::Persistent<Function> constructor_template;
TwBar *bar;
std::vector<CB*> cbs;
};
class AntTweakBar : public Nan::ObjectWrap {
public:
static void Initialize (Handle<Object> target);
static NAN_MODULE_INIT(Initialize);
protected:
static NAN_METHOD(New);
@@ -71,7 +71,7 @@ class AntTweakBar : public Nan::ObjectWrap {
private:
AntTweakBar(Handle<Object> wrapper);
static Persistent<Function> constructor_template;
static Nan::Persistent<Function> constructor_template;
};
} // namespace atb
View
@@ -117,14 +117,16 @@ Nan::Persistent<Object> glfw_events;
int lastX=0,lastY=0;
bool windowCreated=false;
void NAN_INLINE(CallEmitter(int argc, Handle<Value> argv[])) {
void NAN_INLINE(CallEmitter(int argc, Local<Value> argv[])) {
Nan::HandleScope scope;
// MakeCallback(glfw_events, "emit", argc, argv);
if(Nan::New(glfw_events)->Has(JS_STR("emit"))) {
Local<Function> callback = Nan::New(glfw_events)->Get(JS_STR("emit")).As<Function>();
// Local<Function> callback = Nan::New(glfw_events)->Get(JS_STR("emit")).As<Function>();
Nan::Callback callback(Nan::New(glfw_events)->Get(JS_STR("emit")).As<Function>());
if (!callback.IsEmpty()) {
callback->Call(Context::GetCurrent()->Global(),argc,argv);
// callback->Call(Context::GetCurrent()->Global(),argc,argv);
callback.Call(argc,argv);
}
}
}
@@ -139,7 +141,7 @@ void APIENTRY windowPosCB(GLFWwindow *window, int xpos, int ypos) {
evt->Set(JS_STR("xpos"),JS_INT(xpos));
evt->Set(JS_STR("ypos"),JS_INT(ypos));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("window_pos"), // event name
evt
};
@@ -156,7 +158,7 @@ void APIENTRY windowSizeCB(GLFWwindow *window, int w, int h) {
evt->Set(JS_STR("width"),JS_INT(w));
evt->Set(JS_STR("height"),JS_INT(h));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("resize"), // event name
evt
};
@@ -173,7 +175,7 @@ void APIENTRY windowFramebufferSizeCB(GLFWwindow *window, int w, int h) {
evt->Set(JS_STR("width"),JS_INT(w));
evt->Set(JS_STR("height"),JS_INT(h));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("framebuffer_resize"), // event name
evt
};
@@ -184,7 +186,7 @@ void APIENTRY windowFramebufferSizeCB(GLFWwindow *window, int w, int h) {
void APIENTRY windowCloseCB(GLFWwindow *window) {
Nan::HandleScope scope;
Handle<Value> argv[1] = {
Local<Value> argv[1] = {
JS_STR("quit"), // event name
};
@@ -198,7 +200,7 @@ void APIENTRY windowRefreshCB(GLFWwindow *window) {
evt->Set(JS_STR("type"),JS_STR("refresh"));
evt->Set(JS_STR("window"),JS_NUM((uint64_t) window));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("refresh"), // event name
evt
};
@@ -213,7 +215,7 @@ void APIENTRY windowIconifyCB(GLFWwindow *window, int iconified) {
evt->Set(JS_STR("type"),JS_STR("iconified"));
evt->Set(JS_STR("iconified"),JS_BOOL(iconified));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("iconified"), // event name
evt
};
@@ -228,7 +230,7 @@ void APIENTRY windowFocusCB(GLFWwindow *window, int focused) {
evt->Set(JS_STR("type"),JS_STR("focused"));
evt->Set(JS_STR("focused"),JS_BOOL(focused));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("focused"), // event name
evt
};
@@ -342,7 +344,7 @@ void APIENTRY keyCB(GLFWwindow *window, int key, int scancode, int action, int m
evt->Set(JS_STR("keyCode"),JS_INT(key));
evt->Set(JS_STR("charCode"),JS_INT(charCode));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR(&actionNames[action << 3]), // event name
evt
};
@@ -370,7 +372,7 @@ void APIENTRY cursorPosCB(GLFWwindow* window, double x, double y) {
evt->Set(JS_STR("x"),JS_NUM(x));
evt->Set(JS_STR("y"),JS_NUM(y));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("mousemove"), // event name
evt
};
@@ -386,7 +388,7 @@ void APIENTRY cursorEnterCB(GLFWwindow* window, int entered) {
evt->Set(JS_STR("type"),JS_STR("mouseenter"));
evt->Set(JS_STR("entered"),JS_INT(entered));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("mouseenter"), // event name
evt
};
@@ -406,7 +408,7 @@ void APIENTRY mouseButtonCB(GLFWwindow *window, int button, int action, int mods
evt->Set(JS_STR("pageX"),JS_INT(lastX));
evt->Set(JS_STR("pageY"),JS_INT(lastY));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR(action ? "mousedown" : "mouseup"), // event name
evt
};
@@ -425,7 +427,7 @@ void APIENTRY scrollCB(GLFWwindow *window, double xoffset, double yoffset) {
evt->Set(JS_STR("wheelDeltaY"),JS_NUM(yoffset*120));
evt->Set(JS_STR("wheelDelta"),JS_NUM(yoffset*120));
Handle<Value> argv[2] = {
Local<Value> argv[2] = {
JS_STR("mousewheel"), // event name
evt
};
@@ -437,7 +439,7 @@ void APIENTRY scrollCB(GLFWwindow *window, double xoffset, double yoffset) {
int APIENTRY windowCloseCB() {
Nan::HandleScope scope;
Handle<Value> argv[1] = {
Local<Value> argv[1] = {
JS_STR("quit"), // event name
};

0 comments on commit ac759f2

Please sign in to comment.