diff --git a/website/o3dv/dialogs.js b/website/o3dv/dialogs.js index eecffbe..df5215f 100644 --- a/website/o3dv/dialogs.js +++ b/website/o3dv/dialogs.js @@ -22,7 +22,7 @@ OV.ShowListPopup = function (items, callbacks) if (items.length === 0) { return null; } - + let popup = new OV.ListPopup (); popup.Init (() => { return callbacks.calculatePosition (popup.GetContentDiv ()); @@ -49,3 +49,33 @@ OV.ShowListPopup = function (items, callbacks) popup.Show (); return popup; }; + +OV.CalculatePopupPositionToElementBottomRight = function (elementDiv, contentDiv) +{ + let offset = elementDiv.offset (); + return { + x : offset.left + elementDiv.outerWidth (false), + y : offset.top + elementDiv.outerHeight (false) - contentDiv.outerHeight (true) + }; +}; + +OV.CalculatePopupPositionToScreen = function (globalMouseCoordinates, contentDiv) +{ + let windowObj = $(window); + let windowWidth = windowObj.outerWidth (); + let windowHeight = windowObj.outerHeight (); + let left = globalMouseCoordinates.x; + let top = globalMouseCoordinates.y; + let right = left + contentDiv.outerWidth (true); + let bottom = top + contentDiv.outerHeight (true); + if (right > windowWidth) { + left = left - (right - windowWidth); + } + if (bottom > windowHeight) { + top = top - (bottom - windowHeight); + } + return { + x : left, + y : top + }; +}; diff --git a/website/o3dv/featureset.js b/website/o3dv/featureset.js index c0cb65c..89022b2 100644 --- a/website/o3dv/featureset.js +++ b/website/o3dv/featureset.js @@ -1,5 +1,5 @@ OV.FeatureSet = { SettingsPanel : false, - ContextMenu : false + ContextMenu : true }; diff --git a/website/o3dv/navigator.js b/website/o3dv/navigator.js index b8c3f80..4d5794e 100644 --- a/website/o3dv/navigator.js +++ b/website/o3dv/navigator.js @@ -43,11 +43,7 @@ OV.NavigatorInfoPanel = class } this.popup = OV.ShowListPopup (meshItems, { calculatePosition : (contentDiv) => { - let offset = button.offset (); - return { - x : offset.left + button.outerWidth (false), - y : offset.top + button.outerHeight (false) - contentDiv.outerHeight (true) - }; + return OV.CalculatePopupPositionToElementBottomRight (button, contentDiv); }, onHoverStart : (index) => { const meshItem = usedByMeshes[index]; @@ -84,11 +80,7 @@ OV.NavigatorInfoPanel = class this.CreateButton (this.parentDiv, materialsText, (button) => { this.popup = OV.ShowListPopup (materialItems, { calculatePosition : (contentDiv) => { - let offset = button.offset (); - return { - x : offset.left + button.outerWidth (false), - y : offset.top + button.outerHeight (false) - contentDiv.outerHeight (true) - }; + return OV.CalculatePopupPositionToElementBottomRight (button, contentDiv); }, onClick : (index) => { let usedMaterial = usedMaterials[index]; diff --git a/website/o3dv/website.js b/website/o3dv/website.js index 1a305fd..d72a9ca 100644 --- a/website/o3dv/website.js +++ b/website/o3dv/website.js @@ -147,7 +147,7 @@ OV.Website = class if (!OV.FeatureSet.ContextMenu) { return; } - + let meshUserData = this.viewer.GetMeshUserDataUnderMouse (mouseCoordinates); let items = []; if (meshUserData === null) { @@ -183,7 +183,7 @@ OV.Website = class } }, { - name : isMeshIsolated ? 'Remove mesh isolation' : 'Isolate mesh', + name : isMeshIsolated ? 'Remove isolation' : 'Isolate mesh', onClick : () => { this.navigator.IsolateMesh (meshIndex); } @@ -192,11 +192,8 @@ OV.Website = class } this.dialog = OV.ShowListPopup (items, { calculatePosition : (contentDiv) => { - return { - x : globalMouseCoordinates.x, - y : globalMouseCoordinates.y - }; - }, + return OV.CalculatePopupPositionToScreen (globalMouseCoordinates, contentDiv); + }, onClick : (index) => { let clickedItem = items[index]; clickedItem.onClick ();