Adding the hovering from the mouse from the debugHighlight.js

This commit is contained in:
Sam Gateau 2017-12-08 03:53:56 -08:00
parent d07cde3ecb
commit 013d2e808d
2 changed files with 107 additions and 24 deletions

View file

@ -66,24 +66,10 @@
button.editProperties({isActive: onLuciScreen});
wireEventBridge(onLuciScreen);
}
function fromQml(message) {
}
button.clicked.connect(onClicked);
tablet.screenChanged.connect(onScreenChanged);
var moveDebugCursor = false;
Controller.mousePressEvent.connect(function (e) {
if (e.isMiddleButton) {
moveDebugCursor = true;
setDebugCursor(e.x, e.y);
}
});
Controller.mouseReleaseEvent.connect(function() { moveDebugCursor = false; });
Controller.mouseMoveEvent.connect(function (e) { if (moveDebugCursor) setDebugCursor(e.x, e.y); });
Script.scriptEnding.connect(function () {
if (onLuciScreen) {
tablet.gotoHomeScreen();
@ -92,10 +78,93 @@
tablet.screenChanged.disconnect(onScreenChanged);
tablet.removeButton(button);
});
function setDebugCursor(x, y) {
// Create a Laser pointer used to pick and add objects to selections
var END_DIMENSIONS = { x: 0.05, y: 0.05, z: 0.05 };
var COLOR1 = {red: 255, green: 0, blue: 0};
var COLOR2 = {red: 0, green: 255, blue: 0};
var end1 = {
type: "sphere",
dimensions: END_DIMENSIONS,
color: COLOR1,
ignoreRayIntersection: true
}
var end2 = {
type: "sphere",
dimensions: END_DIMENSIONS,
color: COLOR2,
ignoreRayIntersection: true
}
var laser = Pointers.createPointer(PickType.Ray, {
joint: "Mouse",
filter: Picks.PICK_ENTITIES,
renderStates: [{name: "one", end: end1}],
defaultRenderStates: [{name: "one", end: end2, distance: 2.0}],
enabled: true
});
Pointers.setRenderState(laser, "one");
var HoveringList = "Hovering"
var hoveringStyle = {
isOutlineSmooth: true,
outlineWidth: 5,
outlineUnoccludedColor: {red: 255, green: 128, blue: 128},
outlineUnoccludedIntensity: 0.88,
outlineOccludedColor: {red: 255, green: 128, blue: 128},
outlineOccludedIntensity:0.5,
fillUnoccludedColor: {red: 26, green: 0, blue: 0},
fillUnoccludedIntensity: 0.0,
fillOccludedColor: {red: 26, green: 0, blue: 0},
fillOccludedIntensity: 0.0
}
Selection.enableListHighlight(HoveringList, hoveringStyle)
var currentSelectionName = ""
var isSelectionEnabled = false
Pointers.disablePointer(laser)
function fromQml(message) {
tokens = message.split(' ')
print("Received '"+message+"' from hightlight.qml")
if (tokens[0]=="highlight") {
currentSelectionName = tokens[1];
print("Switching to highlight name "+currentSelectionName)
} else if (tokens[0]=="pick") {
isSelectionEnabled = tokens[1]=='true'
print("Ray picking set to "+isSelectionEnabled.toString())
if (isSelectionEnabled) {
Pointers.enablePointer(laser)
} else {
Pointers.disablePointer(laser)
Selection.clearSelectedItemsList(HoveringList)
}
time = 0
}
}
Entities.hoverEnterEntity.connect(function (id, event) {
// print("hoverEnterEntity");
if (isSelectionEnabled) Selection.addToSelectedItemsList(HoveringList, "entity", id)
})
Entities.hoverOverEntity.connect(function (id, event) {
// print("hoverOverEntity");
})
Entities.hoverLeaveEntity.connect(function (id, event) {
if (isSelectionEnabled) Selection.removeFromSelectedItemsList(HoveringList, "entity", id)
// print("hoverLeaveEntity");
})
function cleanup() {
Pointers.removePointer(ray);
Selection.disableListHighlight(HoveringList)
Selection.removeListFromMap(HoveringList)
}
Script.scriptEnding.connect(cleanup);
}());

View file

@ -34,7 +34,9 @@ Item {
}
function resetSelectionView() {
selectionView.resetSelectionView();
if (selectionView !== undefined) {
selectionView.resetSelectionView();
}
}
Column {
@ -69,7 +71,7 @@ Item {
id: styleSelectorLoader
sourceComponent: selectorWidget
width: 300
anchors.right: parent.right
//anchors.right: parent.right
}
Component {
id: selectorWidget
@ -112,6 +114,18 @@ Item {
Separator {}
HifiControls.CheckBox {
text: "Highlight Hovered"
checked: false
onCheckedChanged: {
if (checked) {
root.sendToScript("pick true")
} else {
root.sendToScript("pick false")
}
}
}
Separator {}
Rectangle {
id: selectionView
anchors.left: parent.left
@ -120,15 +134,15 @@ Item {
color: hifi.colors.lightGray
function resetSelectionView() {
// myModel.resetSelectionView();
var entities = Selection.getSelectedItemsList(root.listName)["entities"]
//print("resetSelectionView" + JSON.stringify(entities))
myModel.clear()
var entities = Selection.getSelectedItemsList(root.listName)["entities"]
if (entities === undefined) {
return;
}
var fLen = entities.length;
for (var i = 0; i < fLen; i++) {
myModel.append({ "objectID": JSON.stringify(entities[i]) })
// print("resetSelectionView" + JSON.stringify( entities[i]))
}
}
}
ListModel {