@@ -7,26 +7,26 @@ import QGroundControl.ScreenTools 1.0
77Item {
88 id: _joyRoot
99
10- property alias lightColors: mapPal .lightColors // /< true: use light colors from QGCMapPalette for drawing
11- property real xAxis: 0 // /< Value range [-1,1], negative values left stick, positive values right stick
12- property real yAxis: 0 // /< Value range [-1,1], negative values up stick, positive values down stick
13- property bool yAxisThrottle: false // /< true: yAxis used for throttle, range [1,0], positive value are stick up
14- property bool yAxisThrottleCentered: false // /< false: center yAxis in throttle for reverser and forward
15- property real xPositionDelta: 0 // /< Amount to move the control on x axis
16- property real yPositionDelta: 0 // /< Amount to move the control on y axis
17- property bool springYToCenter: true // /< true: Spring Y to center on release
10+ property alias lightColors: mapPal .lightColors // /< true: use light colors from QGCMapPalette for drawing
11+ property real xAxis: 0 // /< Value range [-1,1], negative values left stick, positive values right stick
12+ property real yAxis: 0 // /< Value range [-1,1], negative values down stick, positive values up stick
13+ property bool yAxisPositiveRangeOnly: false // /< true: value range [0,1], false: value range [-1,1]
14+ property bool yAxisReCenter: true // /< true: snaps back to center on release, false: stays at current position on release
15+ property real xPositionDelta: 0 // /< Amount to move the control on x axis
16+ property real yPositionDelta: 0 // /< Amount to move the control on y axis
1817
1918 property real _centerXY: width / 2
2019 property bool _processTouchPoints: false
2120 property real stickPositionX: _centerXY
22- property real stickPositionY: yAxisThrottleCentered ? _centerXY : height
21+ property real stickPositionY: yAxisReCenter ? _centerXY : height
2322
2423 QGCMapPalette { id: mapPal }
2524
26- onWidthChanged: calculateXAxis ()
27- onStickPositionXChanged: calculateXAxis ()
28- onHeightChanged: calculateYAxis ()
29- onStickPositionYChanged: calculateYAxis ()
25+ onWidthChanged: calculateXAxis ()
26+ onStickPositionXChanged: calculateXAxis ()
27+ onHeightChanged: calculateYAxis ()
28+ onStickPositionYChanged: calculateYAxis ()
29+ onYAxisPositiveRangeOnlyChanged: calculateYAxis ()
3030
3131 function calculateXAxis () {
3232 if (! _joyRoot .visible ) {
@@ -42,13 +42,13 @@ Item {
4242 if (! _joyRoot .visible ) {
4343 return ;
4444 }
45- var yAxisTemp = stickPositionY / height
46- yAxisTemp *= 2.0
47- yAxisTemp -= 1.0
48- if (yAxisThrottle ) {
49- yAxisTemp = ((yAxisTemp * - 1.0 ) / 2.0 ) + 0.5
45+ var fullRange = yAxisPositiveRangeOnly ? 1 : 2
46+ var pctUp = 1.0 - (stickPositionY / height)
47+ var rangeUp = pctUp * fullRange
48+ if (! yAxisPositiveRangeOnly ) {
49+ rangeUp -= 1
5050 }
51- yAxis = yAxisTemp
51+ yAxis = rangeUp
5252 }
5353
5454 function reCenter () {
@@ -58,17 +58,17 @@ Item {
5858 xPositionDelta = 0
5959 yPositionDelta = 0
6060
61- // Center sticks
61+ // Re- Center sticks as needed
6262 stickPositionX = _centerXY
63- if (yAxisThrottleCentered ) {
63+ if (yAxisReCenter ) {
6464 stickPositionY = _centerXY
6565 }
6666 }
6767
6868 function thumbDown (touchPoints ) {
6969 // Position the control around the initial thumb position
7070 xPositionDelta = touchPoints[0 ].x - _centerXY
71- if (yAxisThrottle ) {
71+ if (yAxisPositiveRangeOnly ) {
7272 yPositionDelta = touchPoints[0 ].y - stickPositionY
7373 } else {
7474 yPositionDelta = touchPoints[0 ].y - _centerXY
9494
9595 QGCColoredImage {
9696 color: lightColors ? " white" : " black"
97- visible: yAxisThrottle
97+ visible: yAxisPositiveRangeOnly
9898 height: ScreenTools .defaultFontPixelHeight
9999 width: height
100100 sourceSize .height : height
@@ -108,7 +108,7 @@ Item {
108108
109109 QGCColoredImage {
110110 color: lightColors ? " white" : " black"
111- visible: yAxisThrottle
111+ visible: yAxisPositiveRangeOnly
112112 height: ScreenTools .defaultFontPixelHeight
113113 width: height
114114 sourceSize .height : height
@@ -122,7 +122,7 @@ Item {
122122
123123 QGCColoredImage {
124124 color: lightColors ? " white" : " black"
125- visible: yAxisThrottle
125+ visible: yAxisPositiveRangeOnly
126126 height: ScreenTools .defaultFontPixelHeight
127127 width: height
128128 sourceSize .height : height
@@ -136,7 +136,7 @@ Item {
136136
137137 QGCColoredImage {
138138 color: lightColors ? " white" : " black"
139- visible: yAxisThrottle
139+ visible: yAxisPositiveRangeOnly
140140 height: ScreenTools .defaultFontPixelHeight
141141 width: height
142142 sourceSize .height : height
@@ -200,9 +200,6 @@ Item {
200200 maximumTouchPoints: 1
201201 touchPoints: [ TouchPoint { id: touchPoint } ]
202202 onPressed: _joyRoot .thumbDown (touchPoints)
203- onReleased: {
204- if (springYToCenter)
205- _joyRoot .reCenter ()
206- }
203+ onReleased: _joyRoot .reCenter ()
207204 }
208205}
0 commit comments