framework for a left-click menu per face that calls up a DBox with basics -- needs much more love

This commit is contained in:
2022-02-04 22:33:11 +11:00
parent 694aef038b
commit 10cbee450f

View File

@@ -182,31 +182,38 @@ function ViewImageOrVideo()
}
}
var offsetX,offsetY;
$(document).ready( function()
function reOffset()
{
var cw=$('#canvas').width;
var ch=$('#canvas').height;
function reOffset(){
var BB=$('#canvas').get(0).getBoundingClientRect();
offsetX=BB.left;
offsetY=BB.top;
}
var offsetX,offsetY;
window.onscroll=function(e){ reOffset(); }
window.onresize=function(e){ reOffset(); }
$(document).ready( function()
{
var cw=$('#canvas').width;
var ch=$('#canvas').height;
reOffset();
window.onscroll=function(e){ reOffset(); }
window.onresize=function(e){ reOffset(); }
$.contextMenu({
selector: '#canvas',
trigger: 'left',
hideOnSecondTrigger: true,
build: function($triggerElement, e) {
reOffset();
// get mouse position relative to the canvas (left-click uses page*)
var x=parseInt(e.pageX-offsetX);
var y=parseInt(e.pageY-offsetY);
// get mouse position relative to the canvas
var x=parseInt(e.clientX-offsetX);
var y=parseInt(e.clientY-offsetY);
item_list = { not_a_face: { name: "Not a face" } }
item_list = { not_a_face: { name: "Not a face", which_face: '-1' } }
for( i=0; i<objs[current].faces.length; i++ )
{
@@ -214,7 +221,6 @@ $.contextMenu({
fy = objs[current].faces[i].y / ( im.height/canvas.height )
fw = objs[current].faces[i].w / ( im.width/canvas.width )
fh = objs[current].faces[i].h / ( im.height/canvas.height )
console.log( 'i=' + i + ', w=' + objs[current].faces[i].w + ', h=' + objs[current].faces[i].h )
if( x >= fx && x <= fx+fw && y >= fy && y <= fy+fh )
{
@@ -228,6 +234,7 @@ $.contextMenu({
item_list['no_match_no_face']={ 'name': 'Mark as not a face', 'which_face': i }
item_list['no_match_too_young']={ 'name': 'Mark as face too young', 'which_face': i }
item_list['no_match_ignore']={ 'name': 'Ignore this face', 'which_face': i }
item_list['remove_override']={ 'name': 'Remove override for this face', 'which_face': i }
}
delete item_list['not_a_face']
$('#canvas').prop('menu_item', item_list )
@@ -236,32 +243,35 @@ $.contextMenu({
}
return {
callback: function( key, options) {
if( key == "no_match" ) { item=$('#canvas').prop( 'menu_item' ); console.log(item['no_match']['which_face']) }
if( key == "match" ) { item=$('#canvas').prop( 'menu_item' ); console.log(item['match']['which_face']) }
if( key == 'not_a_face' ) { return true }
item=$('#canvas').prop( 'menu_item' );
FaceDBox( key, item )
},
items: item_list
};
}
} )
function showContextMenu(i,x,y)
{
console.log( 'ShowContextMenu called. i='+i+', x='+x+', y='+y )
if( objs[current].faces[i].who )
console.log( 'face is: ' + objs[current].faces[i].who )
else
console.log( 'face is not known!' )
/*
$menu.show();
var m=r.contextMenu;
$menu.empty();
$menu.css({left:x,top:y});
for(var i=0;i<m.length;i++){
$('<li>', { text:m[i], 'data-fn':i, }).appendTo($menu[0]);
}
*/
}
} );
function FaceDBox(key, item)
{
div ='<p>'
div+='Face #' + item[key]['which_face']
div+='</p>'
if ( key == 'no_match_new_person' )
{
div+='<br>create new person'
}
if ( key == 'no_match_new_refimg' || key == 'no_match_override_match' )
{
div+='<br>search for existing person'
}
if ( key == 'no_match_no_face' || key == 'no_match_too_young' || key == 'no_match_ignore' )
{
div+='<br>just track this against face#' + item[key]['which_face']
}
$('#dbox-title').html(item[key]['name'])
$('#dbox-content').html(div)
$('#dbox').modal('show')
}