Skip to content

Commit

Permalink
Allow x, y, width, and height to be passed.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Jan 5, 2016
1 parent 0cd6db2 commit bb2ab38
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,36 @@ NAN_METHOD(getScreenSize)
}

NAN_METHOD(captureScreen)
{
MMSize displaySize = getMainDisplaySize();
{
size_t x;
size_t y;
size_t w;
size_t h;

//If user has provided screen coords, use them!
if (info.Length() == 4)
{
//TODO: Make sure requested coords are within the screen bounds, or we get a seg fault.
// An error message is much nicer!

x = info[0]->Int32Value();
y = info[1]->Int32Value();
w = info[2]->Int32Value();
h = info[3]->Int32Value();
}
else
{
//We're getting the full screen.
x = 0;
y = 0;

//Get screen size.
MMSize displaySize = getMainDisplaySize();
w = displaySize.width;
h = displaySize.height;
}

MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(0, 0, displaySize.width, displaySize.height));
MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h));

uint32_t bufferSize = bitmap->bytesPerPixel * bitmap->width * bitmap->height;
Local<Object> buffer = Nan::NewBuffer((char*)bitmap->imageBuffer, bufferSize, destroyMMBitmapBuffer, NULL).ToLocalChecked();
Expand Down

0 comments on commit bb2ab38

Please sign in to comment.