Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #10 from joshmarinacci/master

set clip rect
  • Loading branch information...
commit 38d58b262fe35c3209335be9e76d3103a8a37ee2 2 parents acc53bc + e93b6d5
@creationix authored
Showing with 29 additions and 0 deletions.
  1. +28 −0 src/sdl.cc
  2. +1 −0  src/sdl.h
View
28 src/sdl.cc
@@ -55,6 +55,7 @@ init(Handle<Object> target)
NODE_SET_METHOD(target, "mapRGBA", sdl::MapRGBA);
NODE_SET_METHOD(target, "getRGB", sdl::GetRGB);
NODE_SET_METHOD(target, "getRGBA", sdl::GetRGBA);
+ NODE_SET_METHOD(target, "setClipRect",sdl::SetClipRect);
Local<Object> INIT = Object::New();
target->Set(String::New("INIT"), INIT);
@@ -842,6 +843,33 @@ static Handle<Value> sdl::GetRGBA(const Arguments& args) {
}
+static Handle<Value> sdl::SetClipRect(const Arguments& args) {
+ HandleScope scope;
+
+ if (!(args.Length() == 2 && args[0]->IsObject())) {
+ return ThrowException(Exception::TypeError(String::New("Invalid arguments: Expected SetClipRect(SDL_Surface, SDL_Rect)")));
+ }
+
+ SDL_Surface* surface = UnwrapSurface(args[0]->ToObject());
+ SDL_Rect* rect;
+ if (args[1]->IsNull()) {
+ rect = NULL;
+ } else if (args[1]->IsArray()) {
+ SDL_Rect r;
+ Handle<Object> arr = args[1]->ToObject();
+ r.x = arr->Get(String::New("0"))->Int32Value();
+ r.y = arr->Get(String::New("1"))->Int32Value();
+ r.w = arr->Get(String::New("2"))->Int32Value();
+ r.h = arr->Get(String::New("3"))->Int32Value();
+ rect = &r;
+ } else {
+ rect = UnwrapRect(args[1]->ToObject());
+ }
+ if (SDL_SetClipRect (surface, rect ) < 0) return ThrowSDLException(__func__);
+
+ return Undefined();
+}
+
static Handle<Value> sdl::TTF::Init(const Arguments& args) {
HandleScope scope;
View
1  src/sdl.h
@@ -51,6 +51,7 @@ namespace sdl {
static Handle<Value> MapRGBA(const Arguments& args);
static Handle<Value> GetRGB(const Arguments& args);
static Handle<Value> GetRGBA(const Arguments& args);
+ static Handle<Value> SetClipRect(const Arguments& args);
namespace TTF {
static Handle<Value> Init(const Arguments& args);
Please sign in to comment.
Something went wrong with that request. Please try again.