4import QGroundControl.Controls
12 property var screenXrateInitCoocked
13 property var screenYrateInitCoocked
15 property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
16 property var gimbalController: activeVehicle ? activeVehicle.gimbalController : undefined
17 property var activeGimbal: gimbalController ? gimbalController.activeGimbal : undefined
18 property bool gimbalAvailable: activeGimbal != undefined
19 property var gimbalControllerSettings: QGroundControl.settingsManager.gimbalControllerSettings
20 property bool cameraTrackingEnabled: false // Used to ignore clicks when camera tracking operation is active, otherwise it would collide with these gimbal controls
21 property bool shouldProcessClicks: gimbalControllerSettings.EnableOnScreenControl.value && activeGimbal && !cameraTrackingEnabled ? true : false
23 function clickControl() {
24 if (!shouldProcessClicks) {
27 // If click and slide control, return, it uses press and release
28 if (!gimbalControllerSettings.ControlType.rawValue == 0) {
34 // Sends a +-(0-1) xy value to vehicle.gimbalController.gimbalOnScreenControl
35 function clickAndPoint() {
36 if (rootItem.gimbalAvailable) {
37 var xCoocked = ( (screenX / parent.width) * 2) - 1
38 var yCoocked = -( (screenY / parent.height) * 2) + 1
39 // console.log("X global: " + x + " Y global: " + y)
40 // console.log("X coocked: " + xCoocked + " Y coocked: " + yCoocked)
41 gimbalController.gimbalOnScreenControl(xCoocked, yCoocked, true, false, false)
43 // We should never be here
44 console.log("gimbal not available")
48 function pressControl() {
49 if (!shouldProcessClicks) {
52 // If click and point control return, that is handled exclusively on clickAndPoint()
53 if (!gimbalControllerSettings.ControlType.rawValue == 1) {
57 screenXrateInitCoocked = ( ( screenX / parent.width) * 2) - 1
58 screenYrateInitCoocked = -( ( screenY / parent.height) * 2) + 1
61 function releaseControl() {
62 if (!shouldProcessClicks) {
65 // If click and point control return, that is handled exclusively on clickAndPoint()
66 if (!gimbalControllerSettings.ControlType.rawValue == 1) {
70 screenXrateInitCoocked = null
71 screenYrateInitCoocked = null
79 if (rootItem.gimbalAvailable) {
80 var xCoocked = ( ( screenX / parent.width) * 2) - 1
81 var yCoocked = -( ( screenY / parent.height) * 2) + 1
82 xCoocked -= screenXrateInitCoocked
83 yCoocked -= screenYrateInitCoocked
84 gimbalController.gimbalOnScreenControl(xCoocked, yCoocked, false, true, true)
86 console.log("gimbal not available")