Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
vesteraas committed Dec 25, 2014
1 parent 7c6871f commit 702cad9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/berries.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");
var fb = pitft("/dev/fb1");
fb.clear();

var xMax = fb.size().width;
Expand Down
2 changes: 1 addition & 1 deletion examples/circles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");
var fb = pitft("/dev/fb1");
fb.clear();

var xMax = fb.size().width;
Expand Down
2 changes: 1 addition & 1 deletion examples/clock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1", true);
var fb = pitft("/dev/fb1", true);
fb.clear();

var xMax = fb.size().width;
Expand Down
3 changes: 2 additions & 1 deletion examples/lines.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");
var fb = pitft("/dev/fb1");

fb.clear();

var xMax = fb.size().width;
Expand Down
2 changes: 1 addition & 1 deletion examples/rectangles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");
var fb = pitft("/dev/fb1");
fb.clear();

var xMax = fb.size().width;
Expand Down
3 changes: 1 addition & 2 deletions examples/text.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");

var fb = pitft("/dev/fb1");
fb.clear();

var xMax = fb.size().width;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pitft",
"description": "A C++ extension for node.js that gives javascript access to the PiTFT framebuffer",
"version": "0.0.7",
"description": "A NodeJS module that gives you access to the PiTFT framebuffer",
"version": "0.0.8",
"main": "pitft.js",
"author": "Werner Vesteraas <[email protected]>",
"license": {
Expand Down
25 changes: 18 additions & 7 deletions src/framebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

using namespace v8;

Persistent<FunctionTemplate> FrameBuffer::constructor;
Persistent<Function> FrameBuffer::constructor;

void FrameBuffer::Init(Handle<Object> exports) {
void FrameBuffer::Init() {
NanScope();

Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(FrameBuffer::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanNew("FrameBuffer"));

Expand All @@ -25,7 +24,17 @@ void FrameBuffer::Init(Handle<Object> exports) {
NODE_SET_PROTOTYPE_METHOD(ctor, "text", Text);
NODE_SET_PROTOTYPE_METHOD(ctor, "image", Image);

exports->Set(NanNew("FrameBuffer"), ctor->GetFunction());
constructor = Persistent<Function>::New(ctor->GetFunction());
}

NAN_METHOD(FrameBuffer::NewInstance) {
HandleScope scope;

const unsigned argc = 2;
Handle<Value> argv[2] = { args[0], args[1] };
Local<Object> instance = constructor->NewInstance(argc, argv);

NanReturnValue(instance);
}

NAN_METHOD(FrameBuffer::New) {
Expand Down Expand Up @@ -84,9 +93,11 @@ NAN_METHOD(FrameBuffer::Blit) {

FrameBuffer *obj = ObjectWrap::Unwrap<FrameBuffer>(args.Holder());

cairo_t *cr = cairo_create (obj->screenSurface);
cairo_set_source_surface (cr, obj->bufferSurface, 0, 0);
cairo_paint (cr);
if (obj->drawToBuffer) {
cairo_t *cr = cairo_create (obj->screenSurface);
cairo_set_source_surface (cr, obj->bufferSurface, 0, 0);
cairo_paint (cr);
}

NanReturnUndefined();
}
Expand Down
5 changes: 3 additions & 2 deletions src/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ using namespace node;

class FrameBuffer : public node::ObjectWrap {
public:
static Persistent<FunctionTemplate> constructor;
static void Init(Handle<Object> exports);
static Persistent<Function> constructor;
static void Init();
static NAN_METHOD(NewInstance);
static NAN_METHOD(New);
static NAN_METHOD(Size);
static NAN_METHOD(Data);
Expand Down
13 changes: 11 additions & 2 deletions src/pitft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@

using namespace v8;

void InitAll(Handle<Object> exports) {
FrameBuffer::Init(exports);
NAN_METHOD(CreateObject) {
NanScope();

NanReturnValue(FrameBuffer::NewInstance(args));
}

void InitAll(Handle<Object> exports, Handle<Object> module) {
FrameBuffer::Init();

module->Set(String::NewSymbol("exports"),
FunctionTemplate::New(CreateObject)->GetFunction());
}

NODE_MODULE(pitft, InitAll)

0 comments on commit 702cad9

Please sign in to comment.