Permalink
Browse files

More functions wrapped, more refactoring, etc.

  • Loading branch information...
1 parent 5ca83ae commit 9e1819fd3a1623ea3870195e1c8d568c9e2a50f3 Vincent Kuyatt committed Jan 18, 2014
Showing with 675 additions and 79 deletions.
  1. +3 −1 binding.gyp
  2. +1 −1 package.json
  3. +1 −0 sdl.js
  4. +70 −0 src/event.cc
  5. +13 −0 src/event.h
  6. +0 −1 src/helpers.h
  7. +200 −70 src/node_sdl.cc
  8. +16 −6 src/node_sdl.h
  9. +308 −0 src/sdl_gl.cc
  10. +48 −0 src/sdl_gl.h
  11. +12 −0 src/window.cc
  12. +3 −0 src/window.h
View
@@ -11,7 +11,9 @@
'src/texture.cc',
'src/window.cc',
'src/surface.cc',
- 'src/container.cc'
+ 'src/container.cc',
+ 'src/sdl_gl.cc',
+ 'src/event.cc'
],
'libraries': [
'/Library/Frameworks/SDL2.framework/SDL2',
View
@@ -9,7 +9,7 @@
},
"main": "sdl.js",
"engines": {
- "node": ">=0.4.4"
+ "node": ">=0.10.0"
},
"dependencies": {},
"devDependencies": {}
View
1 sdl.js
@@ -23,6 +23,7 @@ SDL.Color.Blue = new SDL.Color(0, 0, 255);
console.log("About to init SDL. (no args, default to EVERYTHING)");
SDL.init("FOO");
+console.log(SDL.Renderer.SOFTWARE);
console.log("COLOR: " + new SDL.Color(100, 100, 100, 255).toString());
console.log(SDL.Color.White.toString());
View
@@ -0,0 +1,70 @@
+#include "event.h"
+
+using namespace v8;
+using namespace node;
+
+
+Local<Object> SDLEventToJavascriptObject(const SDL_Event& event) {
+ Local<Object> evt = Object::New();
+
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ case SDL_KEYUP:
+ evt->Set(String::New("type"), String::New(event.type == SDL_KEYDOWN ? "KEYDOWN" : "KEYUP"));
+ evt->Set(String::New("scancode"), Number::New(event.key.keysym.scancode));
+ evt->Set(String::New("sym"), Number::New(event.key.keysym.sym));
+ evt->Set(String::New("mod"), Number::New(event.key.keysym.mod));
+ break;
+ case SDL_MOUSEMOTION:
+ evt->Set(String::New("type"), String::New("MOUSEMOTION"));
+ evt->Set(String::New("state"), Number::New(event.motion.state));
+ evt->Set(String::New("which"), Number::New(event.motion.which));
+ evt->Set(String::New("x"), Number::New(event.motion.x));
+ evt->Set(String::New("y"), Number::New(event.motion.y));
+ evt->Set(String::New("xrel"), Number::New(event.motion.xrel));
+ evt->Set(String::New("yrel"), Number::New(event.motion.yrel));
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ evt->Set(String::New("type"), String::New(event.type == SDL_MOUSEBUTTONDOWN ? "MOUSEBUTTONDOWN" : "MOUSEBUTTONUP"));
+ evt->Set(String::New("button"), Number::New(event.button.button));
+ evt->Set(String::New("which"), Number::New(event.button.which));
+ evt->Set(String::New("x"), Number::New(event.button.x));
+ evt->Set(String::New("y"), Number::New(event.button.y));
+ break;
+ case SDL_JOYAXISMOTION:
+ evt->Set(String::New("type"), String::New("JOYAXISMOTION"));
+ evt->Set(String::New("which"), Number::New(event.jaxis.which));
+ evt->Set(String::New("axis"), Number::New(event.jaxis.axis));
+ evt->Set(String::New("value"), Number::New(event.jaxis.value));
+ break;
+ case SDL_JOYBALLMOTION:
+ evt->Set(String::New("type"), String::New("JOYBALLMOTION"));
+ evt->Set(String::New("which"), Number::New(event.jball.which));
+ evt->Set(String::New("ball"), Number::New(event.jball.ball));
+ evt->Set(String::New("xrel"), Number::New(event.jball.xrel));
+ evt->Set(String::New("yrel"), Number::New(event.jball.yrel));
+ break;
+ case SDL_JOYHATMOTION:
+ evt->Set(String::New("type"), String::New("JOYHATMOTION"));
+ evt->Set(String::New("which"), Number::New(event.jhat.which));
+ evt->Set(String::New("hat"), Number::New(event.jhat.hat));
+ evt->Set(String::New("value"), Number::New(event.jhat.value));
+ break;
+ case SDL_JOYBUTTONDOWN:
+ case SDL_JOYBUTTONUP:
+ evt->Set(String::New("type"), String::New(event.type == SDL_JOYBUTTONDOWN ? "JOYBUTTONDOWN" : "JOYBUTTONUP"));
+ evt->Set(String::New("which"), Number::New(event.jbutton.which));
+ evt->Set(String::New("button"), Number::New(event.jbutton.button));
+ break;
+ case SDL_QUIT:
+ evt->Set(String::New("type"), String::New("QUIT"));
+ break;
+ default:
+ evt->Set(String::New("type"), String::New("UNKNOWN"));
+ evt->Set(String::New("typeCode"), Number::New(event.type));
+ break;
+ }
+
+ return evt;
+}
View
@@ -0,0 +1,13 @@
+#ifndef NODEJS_EVENT_H
+#define NODEJS_EVENT_H
+
+#include <v8.h>
+#include <node.h>
+#include "SDL.h"
+
+
+namespace sdl {
+ v8::Local<v8::Object> SDLEventToJavascriptObject(const SDL_Event& event);
+}
+
+#endif
View
@@ -17,7 +17,6 @@ namespace sdl {
char* BufferData(v8::Local<v8::Object> buf_obj);
size_t BufferLength(v8::Local<v8::Object> buf_obj);
- v8::Local<v8::Object> SDLEventToJavascriptObject(const SDL_Event& event);
v8::Local<v8::Object> SDLDisplayModeToJavascriptObject(const SDL_DisplayMode& mode);
} // sdl
Oops, something went wrong.

0 comments on commit 9e1819f

Please sign in to comment.