import QtQuick 1.0 import TouchArea 1.0 Item { id:joystick property int xv:(knob.x-(width-knob.width)/2)*(200/(width-knob.width)) property int yv:(knob.y-(height-knob.height)/2)*(200/(height-knob.height)) property bool pressed:false property int touchPointId:-1 property bool touchmode:false property url joyBackground:"joybox.png" width: 200 height: 200 Image { id:knob x:parent.width/2-width/2 y:parent.width/2-height/2 source: "joyknob.png" } TouchArea { id: joyarea anchors.fill:parent minimumTouches: 1 maximumTouches: 1 onTouchStart: { // console.log("TouchArea:ontouchStart " + joyarea.touches.length); var touch = joyarea.touches[0]; // console.log("touchStart",touch.id," at ",touch.y,touch.x,stick.x); knob.x=touch.x; knob.y=touch.y; pressed=true; touchmode=true } onTouchMove: { // console.log("TouchArea:ontouchMove " + joyarea.changedTouches.length); var touch = joyarea.changedTouches[0]; // console.log("touchMove",touch.id," at ",touch.y,touch.x); if((touch.x0)) knob.x=touch.x; if((touch.y0))knob.y=touch.y; } onTouchEnd: { // console.log("TouchArea:ontouchEnd " + joyarea.releasedTouches.length); var touch = joyarea.releasedTouches[0]; // console.log("JoyStick:touchEnd",touch.x,touch.y) knob.x=width/2-knob.width/2 knob.y=width/2-knob.height/2 pressed=false; } } MouseArea { id:mouse_area visible:!touchmode anchors.fill:parent drag.minimumX:0 drag.minimumY:0 drag.maximumX:parent.width-knob.width drag.maximumY:parent.height-knob.height drag.target:knob; onReleased:{ knob.x=parent.width/2-knob.width/2; knob.y=parent.height/2-knob.height/2; } } Image { source:joyBackground anchors.fill:parent } }