Skip to content

Commit

Permalink
The advanced PTZ function "3D Positioning" is now usable on supported…
Browse files Browse the repository at this point in the history
… cameras in a group camera stream, but requires the middle mouse button to use it from here.
  • Loading branch information
bp2008 committed Jul 24, 2023
1 parent e88f371 commit 108a729
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions ui3/ui3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6154,19 +6154,19 @@ function PtzButtons()
}
self.PTZ_async_noguarantee(videoPlayer.Loading().image.id, 100 + parseInt(presetNumber));
}
this.PTZ_relative = function (x, y, z, onSuccess, onFail)
this.PTZ_relative = function (x, y, z, onSuccess, onFail, camData)
{
if (!ptzControlsEnabled)
return;
if (!videoPlayer.Loading().image.ptz)
if (!camData)
camData = videoPlayer.Loading().cam;
if (!camData.ptz)
{
toaster.Error("Current camera is not PTZ");
return;
}
x = Clamp(x, 0, 1);
y = Clamp(y, 0, 1);
z = Clamp(z, -1, 1);
self.PTZ_async_noguarantee(videoPlayer.Loading().image.id, 4, undefined, { xperc: x, yperc: y, zperc: z }, onSuccess, onFail);
self.PTZ_async_noguarantee(camData.optionValue, 4, undefined, { xperc: x, yperc: y, zperc: z }, onSuccess, onFail);
}
var PTZ_set_preset = function (presetNumber, description)
{
Expand Down Expand Up @@ -6472,6 +6472,7 @@ function RelativePTZ()
var pos3dDragging = false;
var box = $("#relativeptzbox");
var $camimg_wrapper = $("#camimg_wrapper");
var currentCam = undefined;

function Initialize()
{
Expand Down Expand Up @@ -6517,27 +6518,65 @@ function RelativePTZ()
var zoomFactor = imageRenderer.zoomHandler.GetZoomFactor();
var imgFrameW = $camimg_wrapper.width() * zoomFactor;
var imgFrameH = $camimg_wrapper.height() * zoomFactor;
var loaded = videoPlayer.Loaded();
if (loaded.cam.optionValue !== currentCam.optionValue)
{
// [loaded.cam] is a group view where the user has middle-clicked on ptz camera [currentCam].
// Adjust the calculations to be relative to the camera's frame.
var cams = cameraListLoader.GetGroupCams(loaded.cam.optionValue);
var rects = cameraListLoader.GetGroupRects(loaded.cam.optionValue);
for (var i = 0; i < cams.length; i++)
{
if (cams[i] === currentCam.optionValue)
{
// This code is mostly copied from CameraNameLabels
var rect = rects[i];
var nativeRes = cameraListLoader.isDynamicLayoutEnabled(loaded.image.id)
? loaded.image.getActualRect()
: loaded.image.getFullRect();
var scaleX = imageRenderer.GetPreviousImageDrawInfo().w / nativeRes.w;
var scaleY = imageRenderer.GetPreviousImageDrawInfo().h / nativeRes.h;
var adjX = rect[0] * scaleX;
var adjY = rect[1] * scaleY;
var adjW = (rect[2] - rect[0]) * scaleX;
var adjH = (rect[3] - rect[1]) * scaleY;

imgFrameOffset.top += adjY;
imgFrameOffset.left += adjX;
imgFrameW = adjW;
imgFrameH = adjH;
break;
}
}
}
var z = Math.max(Math.abs(w / imgFrameW), Math.abs(h / imgFrameH));
if (w < 0)
z *= -1;
var xperc = ((pos3dX - imgFrameOffset.left) + (w / 2)) / imgFrameW;
var yperc = ((pos3dY - imgFrameOffset.top) + (h / 2)) / imgFrameH;

ptzButtons.PTZ_relative(xperc, yperc, z, function () { self.flashRelPtzBox(boxSpec.x, boxSpec.y, boxSpec.w, boxSpec.h); });
ptzButtons.PTZ_relative(xperc, yperc, z, function () { self.flashRelPtzBox(boxSpec.x, boxSpec.y, boxSpec.w, boxSpec.h); }, undefined, currentCam);
}
}
function Precon_3dPos(e)
{
if (!videoPlayer.Loading().image.isLive)
return;
var currentCam = cameraListLoader.GetCameraWithId(videoPlayer.Loading().image.id);

currentCam = cameraListLoader.GetCameraWithId(videoPlayer.Loading().image.id);
videoPlayer.DoThingIfImgClickEligible(e, function (camData)
{
currentCam = camData;
});

if (!currentCam || !currentCam.ptz || !currentCam.ptzdirect)
return;
return (e.which === 2 || enabled3dPositioning ||
(e.getModifierState && e.getModifierState("Control")));
}
function ImageArea_MouseDown(e)
{
mouseCoordFixer.fix(e);
if (pos3dDragging)
{
pos3dDragging = false;
Expand All @@ -6547,7 +6586,6 @@ function RelativePTZ()
if (Precon_3dPos(e))
{
videoPlayer.suppressMouseHelper(true);
mouseCoordFixer.fix(e);
pos3dX = e.mouseX;
pos3dY = e.mouseY;
pos3dDragging = true;
Expand Down Expand Up @@ -14870,7 +14908,7 @@ function VideoPlayerController()
if (confirmed)
ImgClick(e);
else
DoThingIfImgClickEligible(e, videoOverlayHelper.ShowFalseLoadingOverlay);
self.DoThingIfImgClickEligible(e, videoOverlayHelper.ShowFalseLoadingOverlay);
}
else if (!confirmed)
ImgClick(e);
Expand Down Expand Up @@ -15121,9 +15159,13 @@ function VideoPlayerController()
}
return null;
}
var DoThingIfImgClickEligible = function (event, thing)
/**
* Does all the validation and clicked-camera identification from the ImgClick function, then calls a callback method where the clicked camera is passed in.
* @param {any} event Mouse event object
* @param {Function} thing Function to call after validation
*/
this.DoThingIfImgClickEligible = function (event, thing)
{
/// <summary>A silly method that does all the validation and clicked-camera identification from the ImgClick function, then calls a callback method.</summary>
if (!currentlyLoadingImage.isLive && !currentlyLoadingImage.isTimeline())
return;
// mouseCoordFixer.fix(event); // Don't call this more than once per event!
Expand All @@ -15147,7 +15189,7 @@ function VideoPlayerController()
}
var ImgClick = function (event)
{
DoThingIfImgClickEligible(event, self.ImgClick_Camera);
self.DoThingIfImgClickEligible(event, self.ImgClick_Camera);
}
this.ImgClick_Camera = function (camData)
{
Expand Down

0 comments on commit 108a729

Please sign in to comment.