/*
* -----
* Screenshot Sender - select_area.js
* -----
* Select area functions for Screenshot Sender
* -----
*/
var _dragging = false;
var _left = false;
var _up = false;
var StartX, StartY, FinalX, FinalY;
var FocusRect = Interop.Allocate(16);
function OnSelectAreaEvent_MessageNotification(pPlusWnd, nMessage, wParam, lParam) {
switch (nMessage) {
case _win32._const._WM_LBUTTONDOWN:
_dragging = true;
StartX = (lParam & 0xFFFF) + 1;
StartY = ((lParam >> 16) & 0xFFFF) + 1;
break;
case _win32._const._WM_MOUSEMOVE :
if (_dragging) {
// Remove the previous rect
_win32.DrawFocusRect(objCWindows[pPlusWnd.Handle].DC, FocusRect);
var x = (lParam & 0xFFFF);
var y = ((lParam >> 16) & 0xFFFF);
if (x < StartX && !_left) _left = true;
if (x > StartX && _left) _left = false;
if (y < StartY && !_up) _up = true;
if (y > StartY && _up) _up = false;
if (_left) FillRect(FocusRect, x, -1, StartX, -1);
else FillRect(FocusRect, StartX, -1, x, -1);
if (_up) FillRect(FocusRect, -1, y, -1, StartY);
else FillRect(FocusRect, -1, StartY, -1, y);
_win32.DrawFocusRect(objCWindows[pPlusWnd.Handle].DC, FocusRect);
}
break;
case _win32._const._WM_LBUTTONUP:
_win32.ShowWindow(pPlusWnd.Handle, _win32._const._SW_HIDE);
FinalX = (lParam & 0xFFFF) + 1;
FinalY = ((lParam >> 16) & 0xFFFF) + 1;
_dragging = false;
var objCWindow = objCWindows[pPlusWnd.Handle];
var oGdip = new Gdip();
oGdip.Initialize();
if (oGdip.Initialized == true) {
oGdip.SaveImage(oGdip.CaptureWindow(_win32.GetDesktopWindow(), FocusRect, true, true), SessionImages.CreateTempImage());
if (oGdip.SaveSuccessful == true /*[Ok]*/) {
if (objCWindow.SaveImage == false) {
if (objPreferences['cPreviews'] == true) {
Preview(objCWindow.ChatWnd, oGdip.ImageLocation);
}
else {
try {
if (objCWindow.ChatWnd.Contacts.Count === 1) oChatWnd_SendFile(objCWindow.ChatWnd, oGdip.ImageLocation);
else ContactSelector(objCWindow.ChatWnd.Contacts);
} catch (e) {
var WndContactSelector = ContactSelector(Messenger.MyContacts);
objChatWnds[WndContactSelector.Handle] = {};
objChatWnds[WndContactSelector.Handle].Image = oGdip.ImageLocation;
}
}
} else {
if (objPreferences['cPreviews'] == true) {
Preview(objCWindow.ChatWnd, oGdip.ImageLocation, true);
} else {
SessionImages.MoveTempImage(oGdip.ImageLocation, SessionImages.CreateImagePath());
}
}
}
}
FocusRect.Size = 0;
RegisterWindowHooks(pPlusWnd, [
_win32._const._WM_LBUTTONDOWN,
_win32._const._WM_LBUTTONUP,
_win32._const._WM_MOUSEMOVE
], false);
CloseWindow('SelectArea');
break;
}
}
function FillRect(Rect, left, top, right, bottom) {
if (left > -1) Rect.WriteDWORD(0, left);
if (top > -1) Rect.WriteDWORD(4, top);
if (right > -1) Rect.WriteDWORD(8, right);
if (bottom > -1) Rect.WriteDWORD(12, bottom);
}