2015-01-11 16:42:31 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: esteldunedain
|
2015-01-11 16:42:31 +00:00
|
|
|
* Handle key down on map.
|
|
|
|
*
|
2015-04-07 20:01:44 +00:00
|
|
|
* Arguments:
|
2015-01-11 16:42:31 +00:00
|
|
|
* 0: Display (display)
|
|
|
|
* 1: Key code (number)
|
|
|
|
* 2: Shift Key (boolean)
|
|
|
|
* 3: Ctrl Key (boolean)
|
|
|
|
* 4: Alt Key (boolean)
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* Boolean, true if event was handled
|
|
|
|
*/
|
|
|
|
|
2015-01-15 21:50:48 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-04-17 23:13:09 +00:00
|
|
|
PARAMS_5(_display,_code,_shiftKey,_ctrlKey,_altKey);
|
|
|
|
|
|
|
|
private ["_handled", "_relPos", "_diffVector", "_magDiffVector", "_lambdaLong", "_lambdaTrasAbs"];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
_handled = false;
|
|
|
|
|
|
|
|
#define DIK_ESCAPE 0x01
|
|
|
|
#define DIK_DELETE 0xD3
|
|
|
|
|
|
|
|
// If pressed Esc while drawing
|
|
|
|
if (_code == DIK_ESCAPE) exitWith {
|
2015-04-07 20:01:44 +00:00
|
|
|
if (GVAR(drawing_isDrawing)) then {
|
|
|
|
call FUNC(cancelDrawing);
|
|
|
|
_handled = true;
|
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_code == DIK_DELETE) exitWith {
|
2015-04-07 20:01:44 +00:00
|
|
|
if (GVAR(drawing_isDrawing)) then {
|
|
|
|
call FUNC(cancelDrawing);
|
|
|
|
_handled = true;
|
|
|
|
} else {
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-04-07 20:01:44 +00:00
|
|
|
// Check if a line marker needs to be deleted
|
|
|
|
{
|
|
|
|
_relPos = GVAR(mousePosition) vectorDiff (_x select 1);
|
|
|
|
_diffVector = (_x select 2) vectorDiff (_x select 1);
|
|
|
|
_magDiffVector = vectorMagnitude _diffVector;
|
|
|
|
if (_magDiffVector == 0) then {
|
|
|
|
_diffVector = [10,0,0];
|
|
|
|
_magDiffVector = vectorMagnitude _diffVector;
|
|
|
|
};
|
|
|
|
_diffVector = _diffVector vectorMultiply (1/_magDiffVector);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-04-07 20:01:44 +00:00
|
|
|
// Projection of the relative position over the longitudinal axis
|
|
|
|
_lambdaLong = _diffVector vectorDotProduct _relPos;
|
|
|
|
// Projection of the relative position over the trasversal axis
|
|
|
|
_lambdaTrasAbs = vectorMagnitude (_relPos vectorDiff (_diffVector vectorMultiply _lambdaLong));
|
|
|
|
if (_lambdaLong >= 0 && _lambdaLong <= _magDiffVector && _lambdaTrasAbs <= 5) exitWith {
|
|
|
|
// Delete the line marker
|
|
|
|
if (GVAR(drawing_syncMarkers)) then {
|
|
|
|
["drawing_removeLineMarker", [_x select 0]] call EFUNC(common,globalEvent);
|
|
|
|
} else {
|
|
|
|
deleteMarkerLocal (_x select 0);
|
|
|
|
GVAR(drawing_lineMarkers) = GVAR(drawing_lineMarkers) - [_x];
|
|
|
|
};
|
|
|
|
_handled = true;
|
|
|
|
};
|
|
|
|
} forEach GVAR(drawing_lineMarkers);
|
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_handled
|