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

@ -67,23 +67,9 @@
wireEventBridge(onLuciScreen); wireEventBridge(onLuciScreen);
} }
function fromQml(message) {
}
button.clicked.connect(onClicked); button.clicked.connect(onClicked);
tablet.screenChanged.connect(onScreenChanged); 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 () { Script.scriptEnding.connect(function () {
if (onLuciScreen) { if (onLuciScreen) {
tablet.gotoHomeScreen(); tablet.gotoHomeScreen();
@ -93,8 +79,91 @@
tablet.removeButton(button); 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,8 +34,10 @@ Item {
} }
function resetSelectionView() { function resetSelectionView() {
if (selectionView !== undefined) {
selectionView.resetSelectionView(); selectionView.resetSelectionView();
} }
}
Column { Column {
id: col id: col
@ -69,7 +71,7 @@ Item {
id: styleSelectorLoader id: styleSelectorLoader
sourceComponent: selectorWidget sourceComponent: selectorWidget
width: 300 width: 300
anchors.right: parent.right //anchors.right: parent.right
} }
Component { Component {
id: selectorWidget id: selectorWidget
@ -112,6 +114,18 @@ Item {
Separator {} Separator {}
HifiControls.CheckBox {
text: "Highlight Hovered"
checked: false
onCheckedChanged: {
if (checked) {
root.sendToScript("pick true")
} else {
root.sendToScript("pick false")
}
}
}
Separator {}
Rectangle { Rectangle {
id: selectionView id: selectionView
anchors.left: parent.left anchors.left: parent.left
@ -120,14 +134,14 @@ Item {
color: hifi.colors.lightGray color: hifi.colors.lightGray
function resetSelectionView() { function resetSelectionView() {
// myModel.resetSelectionView();
var entities = Selection.getSelectedItemsList(root.listName)["entities"]
//print("resetSelectionView" + JSON.stringify(entities))
myModel.clear() myModel.clear()
var entities = Selection.getSelectedItemsList(root.listName)["entities"]
if (entities === undefined) {
return;
}
var fLen = entities.length; var fLen = entities.length;
for (var i = 0; i < fLen; i++) { for (var i = 0; i < fLen; i++) {
myModel.append({ "objectID": JSON.stringify(entities[i]) }) myModel.append({ "objectID": JSON.stringify(entities[i]) })
// print("resetSelectionView" + JSON.stringify( entities[i]))
} }
} }