Skip to content

Commit 6ca6764

Browse files
committed
(#8) Removed no longer provided functions
1 parent b75ee71 commit 6ca6764

File tree

1 file changed

+4
-159
lines changed

1 file changed

+4
-159
lines changed

src/libnut.cc

Lines changed: 4 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
#include <napi.h>
2-
#include <vector>
3-
#include <sstream>
4-
#include <iostream>
5-
#include <cstdint>
62
#include "mouse.h"
73
#include "buffer_finalizer.h"
84
#include "deadbeef_rand.h"
95
#include "keypress.h"
106
#include "screen.h"
117
#include "screengrab.h"
128
#include "MMBitmap.h"
13-
#include "snprintf.h"
149
#include "microsleep.h"
1510
#if defined(USE_X11)
1611
#include "xdisplay.h"
@@ -109,26 +104,6 @@ Napi::Number _moveMouse(const Napi::CallbackInfo &info)
109104
return Napi::Number::New(env, 1);
110105
}
111106

112-
Napi::Number _moveMouseSmooth(const Napi::CallbackInfo &info)
113-
{
114-
Napi::Env env = info.Env();
115-
116-
if (info.Length() != 2)
117-
{
118-
throw Napi::Error::New(env, "Invalid number of arguments.");
119-
}
120-
121-
size_t x = info[0].As<Napi::Number>().Int32Value();
122-
size_t y = info[1].As<Napi::Number>().Int32Value();
123-
124-
MMPoint point;
125-
point = MMPointMake(x, y);
126-
smoothlyMoveMouse(point);
127-
microsleep(mouseDelay);
128-
129-
return Napi::Number::New(env, 1);
130-
}
131-
132107
Napi::Object _getMousePos(const Napi::CallbackInfo &info)
133108
{
134109
Napi::Env env = info.Env();
@@ -626,51 +601,6 @@ Napi::Number _setKeyboardDelay(const Napi::CallbackInfo &info)
626601
627602
*/
628603

629-
/**
630-
* Pad hex color code with leading zeros.
631-
* @param color Hex value to pad.
632-
* @param hex Hex value to output.
633-
*/
634-
void padHex(MMRGBHex color, char *hex)
635-
{
636-
//Length needs to be 7 because snprintf includes a terminating null.
637-
//Use %06x to pad hex value with leading 0s.
638-
snprintf(hex, 7, "%06x", color);
639-
}
640-
641-
Napi::String _getPixelColor(const Napi::CallbackInfo &info)
642-
{
643-
Napi::Env env = info.Env();
644-
645-
if (info.Length() != 2)
646-
{
647-
throw Napi::Error::New(env, "Invalid number of arguments.");
648-
}
649-
650-
MMBitmapRef bitmap;
651-
MMRGBHex color;
652-
653-
size_t x = info[0].As<Napi::Number>().Int32Value();
654-
size_t y = info[1].As<Napi::Number>().Int32Value();
655-
656-
if (!pointVisibleOnMainDisplay(MMPointMake(x, y)))
657-
{
658-
throw Napi::Error::New(env, "Requested coordinates are outside the main screen's dimensions.");
659-
}
660-
661-
bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1));
662-
663-
color = MMRGBHexAtPoint(bitmap, 0, 0);
664-
665-
char hex[7];
666-
667-
padHex(color, hex);
668-
669-
destroyMMBitmap(bitmap);
670-
671-
return Napi::String::New(env, hex);
672-
}
673-
674604
Napi::Object _getScreenSize(const Napi::CallbackInfo &info)
675605
{
676606
Napi::Env env = info.Env();
@@ -756,27 +686,19 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
756686

757687
if (!(x >= 0 && x < displaySize.width))
758688
{
759-
std::stringstream s;
760-
s << "x coordinate is out of bounds. Should be within 0 and " << displaySize.width << " but is: " << x;
761-
throw Napi::Error::New(env, s.str());
689+
throw Napi::Error::New(env, "Error: x coordinate outside of display");
762690
}
763691
if (!(y >= 0 && y < displaySize.height))
764692
{
765-
std::stringstream s;
766-
s << "y coordinate is out of bounds. Should be within 0 and " << displaySize.height << " but is: " << y;
767-
throw Napi::Error::New(env, s.str());
693+
throw Napi::Error::New(env, "Error: y coordinate outside of display");
768694
}
769695
if (!((x + w) >= 0 && (x + w) < displaySize.width))
770696
{
771-
std::stringstream s;
772-
s << "Rect is out of bounds. Should be within 0 and " << displaySize.width << " but is: (" << x << "," << x + w << ")";
773-
throw Napi::Error::New(env, s.str());
697+
throw Napi::Error::New(env, "Error: Given width exceeds display dimensions");
774698
}
775699
if (!((y + h) >= 0 && (y + h) < displaySize.height))
776700
{
777-
std::stringstream s;
778-
s << "Rect is out of bounds. Should be within 0 and " << displaySize.height << " but is: (" << y << "," << y + h << ")";
779-
throw Napi::Error::New(env, s.str());
701+
throw Napi::Error::New(env, "Error: Given height exceeds display dimensions");
780702
}
781703
}
782704
else
@@ -806,85 +728,10 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
806728
return obj;
807729
}
808730

809-
/*
810-
____ _ _
811-
| __ )(_) |_ _ __ ___ __ _ _ __
812-
| _ \| | __| '_ ` _ \ / _` | '_ \
813-
| |_) | | |_| | | | | | (_| | |_) |
814-
|____/|_|\__|_| |_| |_|\__,_| .__/
815-
|_|
816-
*/
817-
818-
class BMP
819-
{
820-
public:
821-
size_t width;
822-
size_t height;
823-
size_t byteWidth;
824-
uint8_t bitsPerPixel;
825-
uint8_t bytesPerPixel;
826-
uint8_t *image;
827-
};
828-
829-
//Convert object from Javascript to a C++ class (BMP).
830-
BMP buildBMP(const Napi::Object &info)
831-
{
832-
BMP img;
833-
834-
img.width = info.Get("width").As<Napi::Number>().Uint32Value();
835-
img.height = info.Get("height").As<Napi::Number>().Uint32Value();
836-
img.byteWidth = info.Get("byteWidth").As<Napi::Number>().Uint32Value();
837-
img.bitsPerPixel = info.Get("bitsPerPixel").As<Napi::Number>().Uint32Value();
838-
img.bytesPerPixel = info.Get("bytesPerPixel").As<Napi::Number>().Uint32Value();
839-
840-
Napi::Buffer<char> imageBuffer = info.Get("image").As<Napi::Buffer<char>>();
841-
char *buf = imageBuffer.Data();
842-
843-
//Convert the buffer to a uint8_t which createMMBitmap requires.
844-
img.image = (uint8_t *)malloc(img.byteWidth * img.height);
845-
memcpy(img.image, buf, img.byteWidth * img.height);
846-
847-
return img;
848-
}
849-
850-
Napi::String _getColor(const Napi::CallbackInfo &info)
851-
{
852-
Napi::Env env = info.Env();
853-
854-
MMBitmapRef bitmap;
855-
MMRGBHex color;
856-
857-
size_t x = info[1].As<Napi::Number>().Int32Value();
858-
size_t y = info[2].As<Napi::Number>().Int32Value();
859-
860-
//Get our image object from JavaScript.
861-
BMP img = buildBMP(info[0].As<Napi::Object>());
862-
863-
//Create the bitmap.
864-
bitmap = createMMBitmap(img.image, img.width, img.height, img.byteWidth, img.bitsPerPixel, img.bytesPerPixel);
865-
866-
// Make sure the requested pixel is inside the bitmap.
867-
if (!MMBitmapPointInBounds(bitmap, MMPointMake(x, y)))
868-
{
869-
throw Napi::Error::New(env, "Requested coordinates are outside the bitmap's dimensions.");
870-
}
871-
872-
color = MMRGBHexAtPoint(bitmap, x, y);
873-
874-
char hex[7];
875-
876-
padHex(color, hex);
877-
878-
destroyMMBitmap(bitmap);
879-
880-
return Napi::String::New(env, hex);
881-
}
882-
883731
Napi::Object Init(Napi::Env env, Napi::Object exports)
884732
{
885733
exports.Set(Napi::String::New(env, "dragMouse"), Napi::Function::New(env, _dragMouse));
886734
exports.Set(Napi::String::New(env, "moveMouse"), Napi::Function::New(env, _moveMouse));
887-
exports.Set(Napi::String::New(env, "moveMouseSmooth"), Napi::Function::New(env, _moveMouseSmooth));
888735
exports.Set(Napi::String::New(env, "getMousePos"), Napi::Function::New(env, _getMousePos));
889736
exports.Set(Napi::String::New(env, "mouseClick"), Napi::Function::New(env, _mouseClick));
890737
exports.Set(Napi::String::New(env, "mouseToggle"), Napi::Function::New(env, _mouseToggle));
@@ -897,11 +744,9 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
897744
exports.Set(Napi::String::New(env, "typeStringDelayed"), Napi::Function::New(env, _typeStringDelayed));
898745
exports.Set(Napi::String::New(env, "setKeyboardDelay"), Napi::Function::New(env, _setKeyboardDelay));
899746

900-
exports.Set(Napi::String::New(env, "getPixelColor"), Napi::Function::New(env, _getPixelColor));
901747
exports.Set(Napi::String::New(env, "getScreenSize"), Napi::Function::New(env, _getScreenSize));
902748
exports.Set(Napi::String::New(env, "highlight"), Napi::Function::New(env, _highlight));
903749
exports.Set(Napi::String::New(env, "captureScreen"), Napi::Function::New(env, _captureScreen));
904-
exports.Set(Napi::String::New(env, "getColor"), Napi::Function::New(env, _getColor));
905750
exports.Set(Napi::String::New(env, "getXDisplayName"), Napi::Function::New(env, _getXDisplayName));
906751
exports.Set(Napi::String::New(env, "setXDisplayName"), Napi::Function::New(env, _setXDisplayName));
907752

0 commit comments

Comments
 (0)