From fff90b8e265722c1fdfa70a1ef288979a517a729 Mon Sep 17 00:00:00 2001 From: Mr-Dave Date: Fri, 1 Nov 2024 10:37:59 -0600 Subject: [PATCH] Add click to go to camera on webcontrol --- doc/samplepage.html | 282 +++++--------------------------------------- src/allcam.cpp | 11 ++ src/motionplus.hpp | 4 + src/webu_html.cpp | 38 +++++- src/webu_html.hpp | 1 + src/webu_json.cpp | 4 + 6 files changed, 86 insertions(+), 254 deletions(-) diff --git a/doc/samplepage.html b/doc/samplepage.html index 14ec804..e9f1ea5 100644 --- a/doc/samplepage.html +++ b/doc/samplepage.html @@ -848,6 +848,30 @@ } + function image_picall() { + + document.getElementById('picall').addEventListener('click',function(event){ + bounds=this.getBoundingClientRect(); + var locx,locy,locw, loch,pctx,pcty; + var indx, camcnt, caminfo; + locx = Math.floor(event.pageX - bounds.left - window.scrollX); + locy = Math.floor(event.pageY - bounds.top - window.scrollY); + locw = Math.floor(bounds.width); + loch = Math.floor(bounds.height); + pctx = ((locx*100)/locw); + pcty = ((locy*100)/loch); + camcnt = pData['cameras']['count']; + for (indx=0; indx= pData['cameras'][indx]['all_xpct_st']) && + (pctx <= pData['cameras'][indx]['all_xpct_en']) && + (pcty >= pData['cameras'][indx]['all_ypct_st']) && + (pcty <= pData['cameras'][indx]['all_ypct_en'])) { + cams_one_click(indx); + } + } + }); + } + function image_pantilt() { if (gIndxCam == -1 ) { @@ -939,7 +963,7 @@ } } } else { - html_preview += " - diff --git a/src/allcam.cpp b/src/allcam.cpp index 857896b..f829d68 100644 --- a/src/allcam.cpp +++ b/src/allcam.cpp @@ -477,6 +477,17 @@ void cls_allcam::getsizes() all_sizes.width * 3)/2); all_sizes.reset = false; + for (indx=0; indxall_loc.xpct_st = ((p_cam->all_loc.offset_col * 100) /all_sizes.width); + p_cam->all_loc.xpct_en = + (((p_cam->all_loc.offset_col+img_w) * 100) /all_sizes.width); + p_cam->all_loc.ypct_st = ((p_cam->all_loc.offset_row * 100) /all_sizes.height); + p_cam->all_loc.ypct_en = + (((p_cam->all_loc.offset_row+img_h) * 100) /all_sizes.height); + } + stream_free(); stream_alloc(); diff --git a/src/motionplus.hpp b/src/motionplus.hpp index df5d681..4b7772e 100644 --- a/src/motionplus.hpp +++ b/src/motionplus.hpp @@ -137,6 +137,10 @@ struct ctx_all_loc { int offset_user_row; int offset_user_col; int scale; + int xpct_st; /*Starting x location of image on percentage basis*/ + int xpct_en; /*Ending x location of image on percentage basis*/ + int ypct_st; /*Starting y location of image on percentage basis*/ + int ypct_en; /*Ending y location of image on percentage basis*/ }; struct ctx_all_sizes { diff --git a/src/webu_html.cpp b/src/webu_html.cpp index 35566ff..9c66a93 100644 --- a/src/webu_html.cpp +++ b/src/webu_html.cpp @@ -1058,6 +1058,33 @@ void cls_webu_html::script_camera_buttons_ptz() " }\n\n"; } +void cls_webu_html::script_image_picall() +{ + webua->resp_page += + " function image_picall() {\n\n" + " document.getElementById('picall').addEventListener('click',function(event){\n" + " bounds=this.getBoundingClientRect();\n" + " var locx,locy,locw, loch,pctx,pcty;\n" + " var indx, camcnt, caminfo;\n" + " locx = Math.floor(event.pageX - bounds.left - window.scrollX);\n" + " locy = Math.floor(event.pageY - bounds.top - window.scrollY);\n" + " locw = Math.floor(bounds.width);\n" + " loch = Math.floor(bounds.height);\n" + " pctx = ((locx*100)/locw);\n" + " pcty = ((locy*100)/loch);\n" + " camcnt = pData['cameras']['count'];\n" + " for (indx=0; indx= pData['cameras'][indx]['all_xpct_st']) &&\n" + " (pctx <= pData['cameras'][indx]['all_xpct_en']) &&\n" + " (pcty >= pData['cameras'][indx]['all_ypct_st']) &&\n" + " (pcty <= pData['cameras'][indx]['all_ypct_en'])) {\n" + " cams_one_click(indx);\n" + " }\n" + " }\n" + " });\n" + " }\n\n"; +} + /* Create the image_pantilt javascript function */ void cls_webu_html::script_image_pantilt() { @@ -1202,7 +1229,7 @@ void cls_webu_html::script_cams_all_click() " } \n" " }\n" " } else { \n" - " html_preview += \"resp_page += "{\"name\": \"" + escstr(cam->cfg->device_name) + "\""; } webua->resp_page += ",\"id\": " + strid; + webua->resp_page += ",\"all_xpct_st\": " + std::to_string(cam->all_loc.xpct_st); + webua->resp_page += ",\"all_xpct_en\": " + std::to_string(cam->all_loc.xpct_en); + webua->resp_page += ",\"all_ypct_st\": " + std::to_string(cam->all_loc.ypct_st); + webua->resp_page += ",\"all_ypct_en\": " + std::to_string(cam->all_loc.ypct_en); webua->resp_page += ",\"url\": \"" + webua->hostfull + "/" + strid + "/\"} "; } webua->resp_page += "}";