// outerShape = new MTRectangle(x,y, width, height, applet);
outerShape = new MTRoundRectangle(x,y,0, width, height, knobWidth/2f + innerPadding, knobHeight/2f + innerPadding, applet);
outerShape.unregisterAllInputProcessors();
//When we click on the outershape move the knob in that direction a certain step
outerShape.registerInputProcessor(new TapProcessor(applet, 35));
outerShape.addGestureListener(TapProcessor.class, new IGestureEventListener() {
public boolean processGestureEvent(MTGestureEvent ge) {
TapEvent te = (TapEvent)ge;
switch (te.getTapID()) {
case TapEvent.BUTTON_CLICKED:
Vector3D screenPos = te.getLocationOnScreen();
Vector3D intersection = outerShape.getIntersectionGlobal(Tools3D.getCameraPickRay(app, outerShape, screenPos.x, screenPos.y));
if (intersection != null){
//Get the intersection point into knob local relative space
Vector3D localClickPos = knob.globalToLocal(intersection);
Vector3D knobCenterLocal = knob.getCenterPointLocal();
float range = getValueRange();
float step = range/5f; //Arbitrary step value
float oldValue = getValue();
if (localClickPos.x < knobCenterLocal.x){
setValue(oldValue - step); //Move knob Left
}else if (localClickPos.x > knobCenterLocal.x){
setValue(oldValue + step); //Move knob Right
}
}
break;
}
return false;
}
});
// knob = new MTRectangle(x+innerOffset, y+innerOffset, knobWidth, knobHeight, applet);
knob = new MTEllipse(applet, new Vector3D(0,0,0), knobWidth*0.5f, knobHeight*0.5f);
knob.setFillColor(new MTColor(140, 140, 140, 255));
AbstractComponentProcessor[] inputPs = knob.getInputProcessors();
for (int i = 0; i < inputPs.length; i++) {
AbstractComponentProcessor p = inputPs[i];
if (!(p instanceof DragProcessor)){
knob.unregisterInputProcessor(p);
}
}
knob.removeAllGestureEventListeners(DragProcessor.class);
outerShape.addChild(knob);
this.addChild(outerShape);
//TODO these have to be updated if knob or outershape are changed
// final float knobWidthRelParent = knob.getWidthXY(TransformSpace.RELATIVE_TO_PARENT);
// final float knobHeightRelParent = knob.getHeightXY(TransformSpace.RELATIVE_TO_PARENT);
// final float outerWidthLocal = outerShape.getWidthXY(TransformSpace.LOCAL);
knob.addGestureListener(DragProcessor.class, new IGestureEventListener() {
//@Override
public boolean processGestureEvent(MTGestureEvent ge) {
DragEvent de = (DragEvent)ge;
Vector3D dir = new Vector3D(de.getTranslationVect());
//Transform the global direction vector into knob local coordiante space