Added height slider and textfields to chaperone page.

This commit is contained in:
2016-12-14 21:55:35 +01:00
parent 7949ad4f43
commit 10b1518bdb
3 changed files with 191 additions and 14 deletions
+112 -10
View File
@@ -256,7 +256,7 @@ MyStackViewPage {
chaperoneVisibilityText.text = Math.round(val) + "%" chaperoneVisibilityText.text = Math.round(val) + "%"
} }
onValueChanged: { onValueChanged: {
ChaperoneTabController.setBoundsVisibility(this.value.toFixed(2), false) ChaperoneTabController.setBoundsVisibility(Math.round(value), false)
} }
} }
@@ -268,11 +268,29 @@ MyStackViewPage {
} }
} }
MyText {
MyTextField {
id: chaperoneVisibilityText id: chaperoneVisibilityText
text: "100%" text: "0.00"
horizontalAlignment: Text.AlignRight keyBoardUID: 301
Layout.minimumWidth: 85 Layout.preferredWidth: 100
Layout.leftMargin: 10
Layout.rightMargin: 10
horizontalAlignment: Text.AlignHCenter
function onInputEvent(input) {
var val = parseFloat(input)
if (!isNaN(val)) {
if (val < 0.0) {
val = 0.0
} else if (val > 100.0) {
val = 100.0
}
var v = (val/100).toFixed(2)
chaperoneVisibilitySlider.value = v
ChaperoneTabController.setBoundsVisibility(v, false)
}
text = Math.round(ChaperoneTabController.boundsVisibility * 100) + "%"
}
} }
MyText { MyText {
@@ -300,7 +318,7 @@ MyStackViewPage {
chaperoneFadeDistanceText.text = val.toFixed(1) chaperoneFadeDistanceText.text = val.toFixed(1)
} }
onValueChanged: { onValueChanged: {
ChaperoneTabController.setFadeDistance(this.value.toFixed(1), false); ChaperoneTabController.setFadeDistance(this.value.toFixed(1), false)
} }
} }
@@ -312,11 +330,86 @@ MyStackViewPage {
} }
} }
MyText { MyTextField {
id: chaperoneFadeDistanceText id: chaperoneFadeDistanceText
text: "9.9" text: "0.00"
horizontalAlignment: Text.AlignRight keyBoardUID: 302
Layout.minimumWidth: 85 Layout.preferredWidth: 100
Layout.leftMargin: 10
Layout.rightMargin: 10
horizontalAlignment: Text.AlignHCenter
function onInputEvent(input) {
var val = parseFloat(input)
if (!isNaN(val)) {
if (val < 0.0) {
val = 0.0
}
var v = val.toFixed(1)
chaperoneFadeDistanceSlider.value = v
ChaperoneTabController.setFadeDistance(v, false)
}
text = ChaperoneTabController.fadeDistance.toFixed(1)
}
}
MyText {
text: "Height:"
Layout.rightMargin: 12
}
MyPushButton2 {
text: "-"
Layout.preferredWidth: 40
onClicked: {
chaperoneHeightSlider.decrease()
}
}
MySlider {
id: chaperoneHeightSlider
from: 0.01
to: 5.0
stepSize: 0.01
value: 2.0
Layout.fillWidth: true
onPositionChanged: {
var val = (this.from + ( this.position * (this.to - this.from))).toFixed(2)
ChaperoneTabController.setHeight(val, false);
chaperoneHeightText.text = val
}
onValueChanged: {
ChaperoneTabController.setHeight(value.toFixed(2), false)
}
}
MyPushButton2 {
text: "+"
Layout.preferredWidth: 40
onClicked: {
chaperoneHeightSlider.increase()
}
}
MyTextField {
id: chaperoneHeightText
text: "0.00"
keyBoardUID: 303
Layout.preferredWidth: 100
Layout.leftMargin: 10
Layout.rightMargin: 10
horizontalAlignment: Text.AlignHCenter
function onInputEvent(input) {
var val = parseFloat(input)
if (!isNaN(val)) {
if (val < 0.01) {
val = 0.01
}
var v = val.toFixed(2)
chaperoneHeightSlider.value = v
ChaperoneTabController.setHeight(v, false)
}
text = ChaperoneTabController.height.toFixed(2)
}
} }
} }
@@ -392,6 +485,9 @@ MyStackViewPage {
Component.onCompleted: { Component.onCompleted: {
chaperoneVisibilitySlider.value = ChaperoneTabController.boundsVisibility chaperoneVisibilitySlider.value = ChaperoneTabController.boundsVisibility
chaperoneFadeDistanceSlider.value = ChaperoneTabController.fadeDistance chaperoneFadeDistanceSlider.value = ChaperoneTabController.fadeDistance
var h = ChaperoneTabController.height.toFixed(2)
chaperoneHeightSlider.value = h
chaperoneHeightText.text = h
chaperoneCenterMarkerToggle.checked = ChaperoneTabController.centerMarker chaperoneCenterMarkerToggle.checked = ChaperoneTabController.centerMarker
chaperonePlaySpaceToggle.checked = ChaperoneTabController.playSpaceMarker chaperonePlaySpaceToggle.checked = ChaperoneTabController.playSpaceMarker
chaperoneForceBoundsToggle.checked = ChaperoneTabController.forceBounds chaperoneForceBoundsToggle.checked = ChaperoneTabController.forceBounds
@@ -410,6 +506,12 @@ MyStackViewPage {
chaperoneFadeDistanceSlider.value = ChaperoneTabController.fadeDistance chaperoneFadeDistanceSlider.value = ChaperoneTabController.fadeDistance
} }
} }
onHeightChanged: {
var h = ChaperoneTabController.height.toFixed(2)
chaperoneHeightSlider.value = h
chaperoneHeightText.text = h
}
onCenterMarkerChanged: { onCenterMarkerChanged: {
chaperoneCenterMarkerToggle.checked = ChaperoneTabController.centerMarker chaperoneCenterMarkerToggle.checked = ChaperoneTabController.centerMarker
} }
@@ -7,6 +7,7 @@ namespace advsettings {
void ChaperoneTabController::initStage1() { void ChaperoneTabController::initStage1() {
m_height = getBoundsMaxY();
reloadChaperoneProfiles(); reloadChaperoneProfiles();
eventLoopTick(); eventLoopTick();
} }
@@ -241,6 +242,48 @@ void ChaperoneTabController::setFadeDistance(float value, bool notify) {
} }
} }
float ChaperoneTabController::height() const {
return m_height;
}
void ChaperoneTabController::setHeight(float value, bool notify) {
if (m_height != value) {
m_height = value;
vr::VRChaperoneSetup()->RevertWorkingCopy();
unsigned collisionBoundsCount = 0;
vr::VRChaperoneSetup()->GetWorkingCollisionBoundsInfo(nullptr, &collisionBoundsCount);
if (collisionBoundsCount > 0) {
vr::HmdQuad_t* collisionBounds = new vr::HmdQuad_t[collisionBoundsCount];
vr::VRChaperoneSetup()->GetWorkingCollisionBoundsInfo(collisionBounds, &collisionBoundsCount);
for (unsigned b = 0; b < collisionBoundsCount; b++) {
collisionBounds[b].vCorners[0].v[1] = 0.0;
collisionBounds[b].vCorners[1].v[1] = value;
collisionBounds[b].vCorners[2].v[1] = value;
collisionBounds[b].vCorners[3].v[1] = 0.0;
}
vr::VRChaperoneSetup()->SetWorkingCollisionBoundsInfo(collisionBounds, collisionBoundsCount);
vr::VRChaperoneSetup()->CommitWorkingCopy(vr::EChaperoneConfigFile_Live);
delete collisionBounds;
}
if (notify) {
emit heightChanged(m_fadeDistance);
}
}
}
void ChaperoneTabController::updateHeight(float value, bool notify) {
if (m_height != value) {
m_height = value;
if (notify) {
emit heightChanged(m_fadeDistance);
}
}
}
bool ChaperoneTabController::centerMarker() const { bool ChaperoneTabController::centerMarker() const {
return m_centerMarker; return m_centerMarker;
} }
@@ -415,6 +458,7 @@ void ChaperoneTabController::applyChaperoneProfile(unsigned index) {
setForceBounds(profile.forceBounds); setForceBounds(profile.forceBounds);
} }
vr::VRSettings()->Sync(); vr::VRSettings()->Sync();
updateHeight(getBoundsMaxY());
} }
} }
@@ -428,4 +472,27 @@ void ChaperoneTabController::deleteChaperoneProfile(unsigned index) {
} }
} }
float ChaperoneTabController::getBoundsMaxY() {
unsigned collisionBoundsCount = 0;
float result = FP_NAN;
vr::VRChaperoneSetup()->GetLiveCollisionBoundsInfo(nullptr, &collisionBoundsCount);
if (collisionBoundsCount > 0) {
vr::HmdQuad_t* collisionBounds = new vr::HmdQuad_t[collisionBoundsCount];
vr::VRChaperoneSetup()->GetLiveCollisionBoundsInfo(collisionBounds, &collisionBoundsCount);
for (unsigned b = 0; b < collisionBoundsCount; b++) {
int ci;
if (collisionBounds[b].vCorners[1].v[1] >= collisionBounds[b].vCorners[2].v[1]) {
ci = 1;
} else {
ci = 2;
}
if (isnan(result) || result < collisionBounds[b].vCorners[ci].v[1]) {
result = collisionBounds[b].vCorners[ci].v[1];
}
}
delete collisionBounds;
}
return result;
}
} // namespace advconfig } // namespace advconfig
+12 -4
View File
@@ -53,9 +53,10 @@ class ChaperoneTabController : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(float boundsVisibility READ boundsVisibility WRITE setBoundsVisibility NOTIFY boundsVisibilityChanged) Q_PROPERTY(float boundsVisibility READ boundsVisibility WRITE setBoundsVisibility NOTIFY boundsVisibilityChanged)
Q_PROPERTY(float fadeDistance READ fadeDistance WRITE setFadeDistance NOTIFY fadeDistanceChanged) Q_PROPERTY(float fadeDistance READ fadeDistance WRITE setFadeDistance NOTIFY fadeDistanceChanged)
Q_PROPERTY(float centerMarker READ centerMarker WRITE setCenterMarker NOTIFY centerMarkerChanged) Q_PROPERTY(float height READ height WRITE setHeight NOTIFY heightChanged)
Q_PROPERTY(float playSpaceMarker READ playSpaceMarker WRITE setPlaySpaceMarker NOTIFY playSpaceMarkerChanged) Q_PROPERTY(bool centerMarker READ centerMarker WRITE setCenterMarker NOTIFY centerMarkerChanged)
Q_PROPERTY(float forceBounds READ forceBounds WRITE setForceBounds NOTIFY forceBoundsChanged) Q_PROPERTY(bool playSpaceMarker READ playSpaceMarker WRITE setPlaySpaceMarker NOTIFY playSpaceMarkerChanged)
Q_PROPERTY(bool forceBounds READ forceBounds WRITE setForceBounds NOTIFY forceBoundsChanged)
private: private:
OverlayController* parent; OverlayController* parent;
@@ -63,6 +64,7 @@ private:
float m_visibility = 0.6f; float m_visibility = 0.6f;
float m_fadeDistance = 0.7f; float m_fadeDistance = 0.7f;
float m_height = 2.0f;
bool m_centerMarker = false; bool m_centerMarker = false;
bool m_playSpaceMarker = false; bool m_playSpaceMarker = false;
bool m_forceBounds = false; bool m_forceBounds = false;
@@ -79,6 +81,7 @@ public:
float boundsVisibility() const; float boundsVisibility() const;
float fadeDistance() const; float fadeDistance() const;
float height() const;
bool centerMarker() const; bool centerMarker() const;
bool playSpaceMarker() const; bool playSpaceMarker() const;
bool forceBounds() const; bool forceBounds() const;
@@ -89,9 +92,13 @@ public:
Q_INVOKABLE unsigned getChaperoneProfileCount(); Q_INVOKABLE unsigned getChaperoneProfileCount();
Q_INVOKABLE QString getChaperoneProfileName(unsigned index); Q_INVOKABLE QString getChaperoneProfileName(unsigned index);
float getBoundsMaxY();
public slots: public slots:
void setBoundsVisibility(float value, bool notify = true); void setBoundsVisibility(float value, bool notify = true);
void setFadeDistance(float value, bool notify = true); void setFadeDistance(float value, bool notify = true);
void setHeight(float value, bool notify = true);
void updateHeight(float value, bool notify = true);
void setCenterMarker(bool value, bool notify = true); void setCenterMarker(bool value, bool notify = true);
void setPlaySpaceMarker(bool value, bool notify = true); void setPlaySpaceMarker(bool value, bool notify = true);
void setForceBounds(bool value, bool notify = true); void setForceBounds(bool value, bool notify = true);
@@ -100,13 +107,14 @@ public slots:
void reloadFromDisk(); void reloadFromDisk();
void addChaperoneProfile(QString name, bool includeGeometry, bool includeVisbility, bool includeFadeDistance, bool includeCenterMarker, void addChaperoneProfile(QString name, bool includeGeometry, bool includeVisbility, bool includeFadeDistance, bool includeCenterMarker,
bool includePlaySpaceMarker, bool includeFloorBounds, bool includeBoundsColor, bool includeChaperoneStyle, bool includeForceBounds); bool includePlaySpaceMarker, bool includeFloorBounds, bool includeBoundsColor, bool includeChaperoneStyle, bool includeForceBounds);
void applyChaperoneProfile(unsigned index); void applyChaperoneProfile(unsigned index);
void deleteChaperoneProfile(unsigned index); void deleteChaperoneProfile(unsigned index);
signals: signals:
void boundsVisibilityChanged(float value); void boundsVisibilityChanged(float value);
void fadeDistanceChanged(float value); void fadeDistanceChanged(float value);
void heightChanged(float value);
void centerMarkerChanged(bool value); void centerMarkerChanged(bool value);
void playSpaceMarkerChanged(bool value); void playSpaceMarkerChanged(bool value);
void forceBoundsChanged(bool value); void forceBoundsChanged(bool value);